/ src / display / screen_ui / display_screen_ui_common.h
display_screen_ui_common.h
 1  #pragma once
 2  
 3  #ifdef __cplusplus
 4  extern "C" {
 5  #endif
 6  
 7  
 8  	#include "lvgl.h"
 9  
10  	//////////////////////////////////////////////////////////////////////////
11  	// MessageBox
12  	typedef struct msgbox_desc_s {
13  		lv_obj_t* parent;
14  		lv_group_t* group;
15  		const char* message_text;
16  		lv_event_cb_t event_cb;
17  		const char** button_map;
18  	} msgbox_desc_t;
19  
20  	lv_obj_t* ui_common_msgbox_show(msgbox_desc_t* desc);
21  
22  	//////////////////////////////////////////////////////////////////////////
23  	// Splash Window
24  	typedef struct splash_window_desc_s {
25  		const char* title;
26  		const char* instruction;
27  		const char* icon;
28  		const lv_img_dsc_t* image;
29  		const char* header_button_text;
30  		lv_event_cb_t header_button_cb;
31  		// variables below are filled by the api
32  		lv_obj_t* return_header_button_obj;
33  		lv_obj_t* return_window_obj;
34  		lv_obj_t* return_icon_obj;
35  		lv_obj_t* return_image_obj;
36  	} splash_window_desc_t;
37  
38  	lv_obj_t* display_screen_ui_create_splash_window_screen(splash_window_desc_t* desc);
39  
40  	//////////////////////////////////////////////////////////////////////////
41  	// Menu Option List
42  	typedef struct menu_option_desc_s menu_option_desc_t; // c is weird
43  	typedef void (*menu_option_cb_t)(menu_option_desc_t*, lv_group_t*);
44  	typedef struct menu_option_desc_s {
45  		const char* option;
46  		const void* prefix;
47  		menu_option_cb_t click_cb;
48  #if LV_USE_USER_DATA
49  		uint32_t user_flags;
50  #endif // LV_USE_USER_DATA
51  	} menu_option_desc_t;
52  
53  	//////////////////////////////////////////////////////////////////////////
54  	// Styles
55  	void ui_common_set_window_button_style(lv_obj_t* button);
56  
57  	//////////////////////////////////////////////////////////////////////////
58  	// Label Font switching
59  	void ui_common_set_label_font_icons64(lv_obj_t* label);
60  	void ui_common_set_label_font_theme_small(lv_obj_t* label);
61  
62  	//////////////////////////////////////////////////////////////////////////
63  	// Callback typedefs
64  	typedef void (*ui_common_simple_cb)(void);
65  	typedef void (*ui_common_float_cb)(float);
66  	typedef void (*ui_common_uint8t_cb)(uint8_t);
67  
68  	//////////////////////////////////////////////////////////////////////////
69  	// Callback Helpers
70  	void ui_common_cb_set_active_group(lv_group_t* group);
71  	void ui_common_up_down_focus_cb(lv_obj_t* obj, lv_event_t e);
72  
73  	//////////////////////////////////////////////////////////////////////////
74  	// Macros for building UI screens
75  #define UI_CREATE_RETURN_TYPE lv_obj_t*
76  #define UI_FUNCTION(uiName, functionName) display_screen_ui_ ## uiName ## _ ## functionName
77  #define UI_DECLARE_CREATE(uiName) UI_CREATE_RETURN_TYPE UI_FUNCTION(uiName, create) (void)
78  #define UI_DECLARE_ACTIVATE(uiName) void UI_FUNCTION(uiName, activate) (lv_group_t* group)
79  #define UI_DECLARE_FUNCTION(uiName, func) UI_FUNCTION(uiName, func)
80  #define UI_DECLARE(uiName) UI_DECLARE_CREATE(uiName); UI_DECLARE_ACTIVATE(uiName)
81  
82  #define UI_DEFINE_SIMPLE_BUTTON_PRESS_CALLBACK_HANDLER(handlerName, callbackName) \
83  	static void handlerName(lv_obj_t* button, lv_event_t e)                       \
84  	{                                                                             \
85  		if (e == LV_EVENT_PRESSED && callbackName != NULL)                        \
86  		{                                                                         \
87  			callbackName();                                                       \
88  		}                                                                         \
89  		else                                                                      \
90  		{                                                                         \
91  			ui_common_up_down_focus_cb(button, e);                                \
92  		}                                                                         \
93  	}
94  
95  	LV_FONT_CUSTOM_DECLARE;
96  
97  #ifdef __cplusplus
98  } /* extern "C" */
99  #endif