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 #if LV_USE_FLEX == 0
21 #error "LV_USE_FLEX needs to be enabled"
22 #endif
23 
24 /*********************
25  *      DEFINES
26  *********************/
27 
28 /**********************
29  *      TYPEDEFS
30  **********************/
31 typedef enum {
32     LV_MENU_HEADER_TOP_FIXED,   /**< Header is positioned at the top */
33     LV_MENU_HEADER_TOP_UNFIXED, /**< Header is positioned at the top and can be scrolled out of view*/
34     LV_MENU_HEADER_BOTTOM_FIXED /**< Header is positioned at the bottom */
35 } lv_menu_mode_header_t;
36 
37 typedef enum {
38     LV_MENU_ROOT_BACK_BUTTON_DISABLED,
39     LV_MENU_ROOT_BACK_BUTTON_ENABLED
40 } lv_menu_mode_root_back_button_t;
41 
42 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_menu_class;
43 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_menu_page_class;
44 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_menu_cont_class;
45 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_menu_section_class;
46 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_menu_separator_class;
47 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_menu_sidebar_cont_class;
48 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_menu_main_cont_class;
49 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_menu_sidebar_header_cont_class;
50 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_menu_main_header_cont_class;
51 /**********************
52  * GLOBAL PROTOTYPES
53  **********************/
54 
55 /**
56  * Create a menu object
57  * @param parent    pointer to an object, it will be the parent of the new menu
58  * @return          pointer to the created menu
59  */
60 lv_obj_t * lv_menu_create(lv_obj_t * parent);
61 
62 /**
63  * Create a menu page object
64  * @param parent    pointer to menu object
65  * @param title     pointer to text for title in header (NULL to not display title)
66  * @return          pointer to the created menu page
67  */
68 lv_obj_t * lv_menu_page_create(lv_obj_t * parent, char const * const title);
69 
70 /**
71  * Create a menu cont object
72  * @param parent    pointer to a menu page object, it will be the parent of the new menu cont object
73  * @return          pointer to the created menu cont
74  */
75 lv_obj_t * lv_menu_cont_create(lv_obj_t * parent);
76 
77 /**
78  * Create a menu section object
79  * @param parent    pointer to a menu page object, it will be the parent of the new menu section object
80  * @return          pointer to the created menu section
81  */
82 lv_obj_t * lv_menu_section_create(lv_obj_t * parent);
83 
84 /**
85  * Create a menu separator object
86  * @param parent    pointer to a menu page object, it will be the parent of the new menu separator object
87  * @return          pointer to the created menu separator
88  */
89 lv_obj_t * lv_menu_separator_create(lv_obj_t * parent);
90 /*=====================
91  * Setter functions
92  *====================*/
93 /**
94  * Set menu page to display in main
95  * @param obj       pointer to the menu
96  * @param page      pointer to the menu page to set (NULL to clear main and clear menu history)
97  */
98 void lv_menu_set_page(lv_obj_t * obj, lv_obj_t * page);
99 
100 /**
101  * Set menu page title
102  * @param page      pointer to the menu page
103  * @param title     pointer to text for title in header (NULL to not display title)
104  */
105 void lv_menu_set_page_title(lv_obj_t * page, char const * const title);
106 
107 /**
108  * Set menu page title with a static text. It will not be saved by the label so the 'text' variable
109  * has to be 'alive' while the page exists.
110  * @param page      pointer to the menu page
111  * @param title     pointer to text for title in header (NULL to not display title)
112  */
113 void lv_menu_set_page_title_static(lv_obj_t * page, char const * const title);
114 
115 /**
116  * Set menu page to display in sidebar
117  * @param obj       pointer to the menu
118  * @param page      pointer to the menu page to set (NULL to clear sidebar)
119  */
120 void lv_menu_set_sidebar_page(lv_obj_t * obj, lv_obj_t * page);
121 
122 /**
123  * Set the how the header should behave and its position
124  * @param obj       pointer to a menu
125  * @param mode      LV_MENU_HEADER_TOP_FIXED/TOP_UNFIXED/BOTTOM_FIXED
126  */
127 void lv_menu_set_mode_header(lv_obj_t * obj, lv_menu_mode_header_t mode);
128 
129 /**
130  * Set whether back button should appear at root
131  * @param obj       pointer to a menu
132  * @param mode      LV_MENU_ROOT_BACK_BUTTON_DISABLED/ENABLED
133  */
134 void lv_menu_set_mode_root_back_button(lv_obj_t * obj, lv_menu_mode_root_back_button_t mode);
135 
136 /**
137  * Add menu to the menu item
138  * @param menu      pointer to the menu
139  * @param obj       pointer to the obj
140  * @param page      pointer to the page to load when obj is clicked
141  */
142 void lv_menu_set_load_page_event(lv_obj_t * menu, lv_obj_t * obj, lv_obj_t * page);
143 
144 /*=====================
145  * Getter functions
146  *====================*/
147 /**
148 * Get a pointer to menu page that is currently displayed in main
149 * @param obj        pointer to the menu
150 * @return           pointer to current page
151 */
152 lv_obj_t * lv_menu_get_cur_main_page(lv_obj_t * obj);
153 
154 /**
155 * Get a pointer to menu page that is currently displayed in sidebar
156 * @param obj        pointer to the menu
157 * @return           pointer to current page
158 */
159 lv_obj_t * lv_menu_get_cur_sidebar_page(lv_obj_t * obj);
160 
161 /**
162 * Get a pointer to main header obj
163 * @param obj        pointer to the menu
164 * @return           pointer to main header obj
165 */
166 lv_obj_t * lv_menu_get_main_header(lv_obj_t * obj);
167 
168 /**
169 * Get a pointer to main header back btn obj
170 * @param obj        pointer to the menu
171 * @return           pointer to main header back btn obj
172 */
173 lv_obj_t * lv_menu_get_main_header_back_button(lv_obj_t * obj);
174 
175 /**
176 * Get a pointer to sidebar header obj
177 * @param obj        pointer to the menu
178 * @return           pointer to sidebar header obj
179 */
180 lv_obj_t * lv_menu_get_sidebar_header(lv_obj_t * obj);
181 
182 /**
183 * Get a pointer to sidebar header obj
184 * @param obj        pointer to the menu
185 * @return           pointer to sidebar header back btn obj
186 */
187 lv_obj_t * lv_menu_get_sidebar_header_back_button(lv_obj_t * obj);
188 
189 /**
190  * Check if an obj is a root back btn
191  * @param menu      pointer to the menu
192  * @param obj       pointer to the back button
193  * @return          true if it is a root back btn
194  */
195 bool lv_menu_back_button_is_root(lv_obj_t * menu, lv_obj_t * obj);
196 
197 /**
198  * Clear menu history
199  * @param obj       pointer to the menu
200  */
201 void lv_menu_clear_history(lv_obj_t * obj);
202 
203 /**********************
204  *      MACROS
205  **********************/
206 
207 #endif /*LV_USE_MENU*/
208 
209 #ifdef __cplusplus
210 } /*extern "C"*/
211 #endif
212 
213 #endif /*LV_MENU_H*/
214