1 /**
2  * @file lv_menu.h
3  *
4  */
5 
6 #ifndef LV_MENU_H
7 #define LV_MENU_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../../../core/lv_obj.h"
17 
18 #if LV_USE_MENU
19 
20 /*********************
21  *      DEFINES
22  *********************/
23 
24 /**********************
25  *      TYPEDEFS
26  **********************/
27 
28 enum {
29     LV_MENU_HEADER_TOP_FIXED, /* Header is positioned at the top */
30     LV_MENU_HEADER_TOP_UNFIXED, /* Header is positioned at the top and can be scrolled out of view*/
31     LV_MENU_HEADER_BOTTOM_FIXED /* Header is positioned at the bottom */
32 };
33 typedef uint8_t lv_menu_mode_header_t;
34 
35 enum {
36     LV_MENU_ROOT_BACK_BTN_DISABLED,
37     LV_MENU_ROOT_BACK_BTN_ENABLED
38 };
39 typedef uint8_t lv_menu_mode_root_back_btn_t;
40 
41 typedef struct lv_menu_load_page_event_data_t {
42     lv_obj_t * menu;
43     lv_obj_t * page;
44 } lv_menu_load_page_event_data_t;
45 
46 typedef struct {
47     lv_obj_t * page;
48 } lv_menu_history_t;
49 
50 typedef struct {
51     lv_obj_t obj;
52     lv_obj_t * storage; /* a pointer to obj that is the parent of all pages not displayed */
53     lv_obj_t * main;
54     lv_obj_t * main_page;
55     lv_obj_t * main_header;
56     lv_obj_t *
57     main_header_back_btn; /* a pointer to obj that on click triggers back btn event handler, can be same as 'main_header' */
58     lv_obj_t * main_header_title;
59     lv_obj_t * sidebar;
60     lv_obj_t * sidebar_page;
61     lv_obj_t * sidebar_header;
62     lv_obj_t *
63     sidebar_header_back_btn; /* a pointer to obj that on click triggers back btn event handler, can be same as 'sidebar_header' */
64     lv_obj_t * sidebar_header_title;
65     lv_obj_t * selected_tab;
66     lv_ll_t history_ll;
67     uint8_t cur_depth;
68     uint8_t prev_depth;
69     uint8_t sidebar_generated : 1;
70     lv_menu_mode_header_t mode_header : 2;
71     lv_menu_mode_root_back_btn_t mode_root_back_btn : 1;
72 } lv_menu_t;
73 
74 typedef struct {
75     lv_obj_t obj;
76     char * title;
77 } lv_menu_page_t;
78 
79 extern const lv_obj_class_t lv_menu_class;
80 extern const lv_obj_class_t lv_menu_page_class;
81 extern const lv_obj_class_t lv_menu_cont_class;
82 extern const lv_obj_class_t lv_menu_section_class;
83 extern const lv_obj_class_t lv_menu_separator_class;
84 extern const lv_obj_class_t lv_menu_sidebar_cont_class;
85 extern const lv_obj_class_t lv_menu_main_cont_class;
86 extern const lv_obj_class_t lv_menu_sidebar_header_cont_class;
87 extern const lv_obj_class_t lv_menu_main_header_cont_class;
88 /**********************
89  * GLOBAL PROTOTYPES
90  **********************/
91 
92 /**
93  * Create a menu object
94  * @param parent pointer to an object, it will be the parent of the new menu
95  * @return pointer to the created menu
96  */
97 lv_obj_t * lv_menu_create(lv_obj_t * parent);
98 
99 /**
100  * Create a menu page object
101  * @param parent pointer to menu object
102  * @param title pointer to text for title in header (NULL to not display title)
103  * @return pointer to the created menu page
104  */
105 lv_obj_t * lv_menu_page_create(lv_obj_t * parent, char * title);
106 
107 /**
108  * Create a menu cont object
109  * @param parent pointer to an object, it will be the parent of the new menu cont object
110  * @return pointer to the created menu cont
111  */
112 lv_obj_t * lv_menu_cont_create(lv_obj_t * parent);
113 
114 /**
115  * Create a menu section object
116  * @param parent pointer to an object, it will be the parent of the new menu section object
117  * @return pointer to the created menu section
118  */
119 lv_obj_t * lv_menu_section_create(lv_obj_t * parent);
120 
121 /**
122  * Create a menu separator object
123  * @param parent pointer to an object, it will be the parent of the new menu separator object
124  * @return pointer to the created menu separator
125  */
126 lv_obj_t * lv_menu_separator_create(lv_obj_t * parent);
127 /*=====================
128  * Setter functions
129  *====================*/
130 /**
131  * Set menu page to display in main
132  * @param obj pointer to the menu
133  * @param page pointer to the menu page to set (NULL to clear main and clear menu history)
134  */
135 void lv_menu_set_page(lv_obj_t * obj, lv_obj_t * page);
136 
137 /**
138  * Set menu page to display in sidebar
139  * @param obj pointer to the menu
140  * @param page pointer to the menu page to set (NULL to clear sidebar)
141  */
142 void lv_menu_set_sidebar_page(lv_obj_t * obj, lv_obj_t * page);
143 
144 /**
145  * Set the how the header should behave and its position
146  * @param obj pointer to a menu
147  * @param mode_header
148  */
149 void lv_menu_set_mode_header(lv_obj_t * obj, lv_menu_mode_header_t mode_header);
150 
151 /**
152  * Set whether back button should appear at root
153  * @param obj pointer to a menu
154  * @param mode_root_back_btn
155  */
156 void lv_menu_set_mode_root_back_btn(lv_obj_t * obj, lv_menu_mode_root_back_btn_t mode_root_back_btn);
157 
158 /**
159  * Add menu to the menu item
160  * @param menu pointer to the menu
161  * @param obj pointer to the obj
162  * @param page pointer to the page to load when obj is clicked
163  */
164 void lv_menu_set_load_page_event(lv_obj_t * menu, lv_obj_t * obj, lv_obj_t * page);
165 
166 /*=====================
167  * Getter functions
168  *====================*/
169 /**
170 * Get a pointer to menu page that is currently displayed in main
171 * @param obj pointer to the menu
172 * @return pointer to current page
173 */
174 lv_obj_t * lv_menu_get_cur_main_page(lv_obj_t * obj);
175 
176 /**
177 * Get a pointer to menu page that is currently displayed in sidebar
178 * @param obj pointer to the menu
179 * @return pointer to current page
180 */
181 lv_obj_t * lv_menu_get_cur_sidebar_page(lv_obj_t * obj);
182 
183 /**
184 * Get a pointer to main header obj
185 * @param obj pointer to the menu
186 * @return pointer to main header obj
187 */
188 lv_obj_t * lv_menu_get_main_header(lv_obj_t * obj);
189 
190 /**
191 * Get a pointer to main header back btn obj
192 * @param obj pointer to the menu
193 * @return pointer to main header back btn obj
194 */
195 lv_obj_t * lv_menu_get_main_header_back_btn(lv_obj_t * obj);
196 
197 /**
198 * Get a pointer to sidebar header obj
199 * @param obj pointer to the menu
200 * @return pointer to sidebar header obj
201 */
202 lv_obj_t * lv_menu_get_sidebar_header(lv_obj_t * obj);
203 
204 /**
205 * Get a pointer to sidebar header obj
206 * @param obj pointer to the menu
207 * @return pointer to sidebar header back btn obj
208 */
209 lv_obj_t * lv_menu_get_sidebar_header_back_btn(lv_obj_t * obj);
210 
211 /**
212  * Check if an obj is a root back btn
213  * @param menu pointer to the menu
214  * @return true if it is a root back btn
215  */
216 bool lv_menu_back_btn_is_root(lv_obj_t * menu, lv_obj_t * obj);
217 
218 /**
219  * Clear menu history
220  * @param obj pointer to the menu
221  */
222 void lv_menu_clear_history(lv_obj_t * obj);
223 /**********************
224  *      MACROS
225  **********************/
226 
227 #endif /*LV_USE_MENU*/
228 
229 #ifdef __cplusplus
230 } /*extern "C"*/
231 #endif
232 
233 #endif /*LV_MENU_H*/
234