C-APP

用GUI API编写C语言代码,然后将其与GUI代码一起编译,以实现预期的显示,称为C-APP。

语法

使用特定名称定义应用程序

  • 使用 GUI_APP_DEFINE_NAME API定义应用程序句柄

#define APP_STOPWATCH
GUI_APP_DEFINE_NAME(APP_STOPWATCH)
  • 使用 GUI_APP_ENTRY API定义应用程序UI设计的入口函数

graph TD; screen --> win; win --> text; screen --> status_bar; screen --> return_widget;
GUI_APP_ENTRY(APP_STOPWATCH)
{
    gui_canvas_rect_create(GUI_APP_ROOT_SCREEN, 0, 0, 0, SCREEN_W, SCREEN_H, COLOR_SILVER);
    gui_multi_level_t *ml0 = gui_multi_level_create(GUI_APP_ROOT_SCREEN, 0, stop_watch_ml0);
    gui_multi_level_create(ml0, 0, stop_watch_ml1_0);
    gui_multi_level_create(ml0, 0, stop_watch_ml1_1);
    GUI_API(gui_multi_level_t).jump(ml0, 1, 0);
    const int win_height = 100;
    gui_win_t *win_stop_watch = gui_win_create(GUI_APP_ROOT_SCREEN, 0, 0, SCREEN_H - win_height,
                                               SCREEN_W / 2, win_height);
    gui_win_press(win_stop_watch, win_stop_watch_cb, ml0);
    {
        char *text = "Stop watch";
        int font_size = 16;
        gui_text_t *t = gui_text_create(win_stop_watch, text, 0, 52, gui_get_screen_width() / 2,
                                        font_size);
        gui_text_set(t, text, GUI_FONT_SRC_BMP, APP_COLOR_BLACK, strlen(text), font_size);
        void *addr1 = ARIALBD_SIZE16_BITS4_FONT_BIN;
        gui_text_type_set(t, addr1, FONT_SRC_MEMADDR);
        gui_text_mode_set(t, CENTER);

    }
    gui_win_t *win_timer = gui_win_create(GUI_APP_ROOT_SCREEN, 0, SCREEN_W / 2 + 1,
                                          SCREEN_H - win_height, SCREEN_W / 2, win_height);
    gui_win_press(win_timer, win_timer_cb, ml0);
    {
        char *text = "timer";
        int font_size = 16;
        gui_text_t *t = gui_text_create(win_timer, text, 0, 52, gui_get_screen_width() / 2,
                                        font_size);
        gui_text_set(t, text, GUI_FONT_SRC_BMP, APP_COLOR_BLACK, strlen(text), font_size);
        void *addr1 = ARIALBD_SIZE16_BITS4_FONT_BIN;
        gui_text_type_set(t, addr1, FONT_SRC_MEMADDR);
        gui_text_mode_set(t, CENTER);

    }
    status_bar(GUI_APP_ROOT_SCREEN, (void *)0);
    gui_return_create(GUI_APP_ROOT_SCREEN, gui_app_return_array,
                      sizeof(gui_app_return_array) / sizeof(uint32_t *), win_cb, (void *)0);
}

使用特定名称和入口函数定义应用程序

  • 使用名称 APP_MENU 和入口函数 app_menu,调用 GUI_APP_DEFINEE API定义应用程序句柄

#define APP_MENU
GUI_APP_DEFINE(APP_MENU,       app_menu)

API

Defines

GUI_APP_DEFINE(APP_NAME, UI_DESIGN)

Macro to define a GUI application.

This macro creates a new GUI application by defining a static function pointer to the UI design function, initializing the GUI application structure, and providing a way to retrieve a handle to this application.

参数:
  • APP_NAME – The name of the application.

  • UI_DESIGN – The function to design the UI of the application.

GUI_APP_HANDLE(APP_NAME)

Macro to get the handle of a GUI application by its name.

参数:
  • APP_NAME – The name of the application.

返回:

A pointer to the application instance.

GUI_APP_SHUTDOWN(APP_NAME)

Macro to shut down a GUI application.

This macro shuts down the application by calling the external function gui_app_shutdown with the application’s handle.

参数:
  • APP_NAME – The name of the application.

GUI_APP_STARTUP(APP_NAME)

Macro to start up a GUI application.

This macro starts up the application by calling the external function gui_app_startup with the application’s handle.

参数:
  • APP_NAME – The name of the application.

GUI_APP_SWAP(APP_NAME, APP_NAME_NEXT)

Macro to swap between two GUI applications.

This macro allows switching from one application to another by calling gui_switch_app and passing the handles of the current and next application.

参数:
  • APP_NAME – The name of the current application.

  • APP_NAME_NEXT – The name of the next application.

GUI_APP_ROOT_SCREEN

Macro to get a pointer to the root screen of the current application.

返回:

A pointer to the root screen of the current application.

GUI_APP_SWAP_HANDLE(HANDLE_FUNC, HANDLE_NEXT_FUNC)

Macro to swap between two GUI applications using their handle functions.

This macro swaps between two applications using their external handle functions.

参数:
  • HANDLE_FUNC – The handle function of the current application.

  • HANDLE_NEXT_FUNC – The handle function of the next application.

GUI_APP_DEFINE_NAME(APP_NAME)

Macro to define a GUI application with a specific name.

This macro works similarly to GUI_APP_DEFINE but with a naming convention for the UI design function.

参数:
  • APP_NAME – The name of the application.

GUI_APP_ENTRY(APP_NAME)

Macro to declare the entry point of a GUI application’s UI design function.

This macro declares the UI design function for the application.

参数:
  • APP_NAME – The name of the application.

Functions

gui_app_t *gui_current_app(void)

get current app pointer

gui_app_t *gui_next_app(void)

get nect app pointer if there are two apps exist.

void gui_app_install(gui_app_t *app, void *ui_design, void *gui_app_entry)
void gui_app_startup(gui_app_t *app)
void gui_app_shutdown(gui_app_t *app)
gui_app_t *gui_app_create(const char *app_name, void *ui_design, void *gui_app_entry)
void gui_switch_app(gui_app_t *from, gui_app_t *to)

switch app from A to B

参数:
  • from – A pointer

  • to – B pointer

void gui_app_layer_top(void)

set next app top layer

void gui_app_layer_buttom(void)

set next app button layer

bool gui_app_get_layer(void)

get next app layer

返回:

true top layer

返回:

false button layer

void gui_set_app_active_time(gui_app_t *app, uint32_t active_ms)

set app active ms time

参数:
  • app – app set

  • active_ms – active ms times

struct gui_app
#include <gui_app.h>

APP structure.

Public Members

gui_obj_t screen

widget tree root

const char *xml

widget tree design file

uint32_t active_ms

screen shut down delay

uint32_t start_ms

screen shut down delay

void *thread_id

thread handle(optional)

void (*thread_entry)(void *_this)

thread entry

void (*ctor)(void *_this)

constructor

void (*dtor)(void *_this)

destructor

void (*ui_design)(gui_app_t*)

ui create entry

bool lvgl
bool arm2d
bool close
bool next
bool close_sync