1 /** 2 * @file lv_group.h 3 * 4 */ 5 6 #ifndef LV_GROUP_H 7 #define LV_GROUP_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /********************* 14 * INCLUDES 15 *********************/ 16 17 #include "../lv_conf_internal.h" 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 #include "../misc/lv_ll.h" 22 #include "../misc/lv_types.h" 23 24 /********************* 25 * DEFINES 26 *********************/ 27 /*Predefined keys to control the focused object via lv_group_send(group, c)*/ 28 29 enum { 30 LV_KEY_UP = 17, /*0x11*/ 31 LV_KEY_DOWN = 18, /*0x12*/ 32 LV_KEY_RIGHT = 19, /*0x13*/ 33 LV_KEY_LEFT = 20, /*0x14*/ 34 LV_KEY_ESC = 27, /*0x1B*/ 35 LV_KEY_DEL = 127, /*0x7F*/ 36 LV_KEY_BACKSPACE = 8, /*0x08*/ 37 LV_KEY_ENTER = 10, /*0x0A, '\n'*/ 38 LV_KEY_NEXT = 9, /*0x09, '\t'*/ 39 LV_KEY_PREV = 11, /*0x0B, '*/ 40 LV_KEY_HOME = 2, /*0x02, STX*/ 41 LV_KEY_END = 3, /*0x03, ETX*/ 42 }; 43 typedef uint8_t lv_key_t; 44 45 /********************** 46 * TYPEDEFS 47 **********************/ 48 49 struct _lv_obj_t; 50 struct _lv_group_t; 51 52 typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *); 53 54 /** 55 * Groups can be used to logically hold objects so that they can be individually focused. 56 * They are NOT for laying out objects on a screen (try layouts for that). 57 */ 58 typedef struct _lv_group_t { 59 lv_ll_t obj_ll; /**< Linked list to store the objects in the group*/ 60 struct _lv_obj_t ** obj_focus; /**< The object in focus*/ 61 62 lv_group_focus_cb_t focus_cb; /**< A function to call when a new object is focused (optional)*/ 63 #if LV_USE_USER_DATA 64 void * user_data; 65 #endif 66 67 uint8_t frozen : 1; /**< 1: can't focus to new object*/ 68 uint8_t editing : 1; /**< 1: Edit mode, 0: Navigate mode*/ 69 uint8_t refocus_policy : 1; /**< 1: Focus prev if focused on deletion. 0: Focus next if focused on 70 deletion.*/ 71 uint8_t wrap : 1; /**< 1: Focus next/prev can wrap at end of list. 0: Focus next/prev stops at end 72 of list.*/ 73 } lv_group_t; 74 75 76 typedef enum { 77 LV_GROUP_REFOCUS_POLICY_NEXT = 0, 78 LV_GROUP_REFOCUS_POLICY_PREV = 1 79 } lv_group_refocus_policy_t; 80 81 /********************** 82 * GLOBAL PROTOTYPES 83 **********************/ 84 85 /** 86 * Init. the group module 87 * @remarks Internal function, do not call directly. 88 */ 89 void _lv_group_init(void); 90 91 /** 92 * Create a new object group 93 * @return pointer to the new object group 94 */ 95 lv_group_t * lv_group_create(void); 96 97 /** 98 * Delete a group object 99 * @param group pointer to a group 100 */ 101 void lv_group_del(lv_group_t * group); 102 103 /** 104 * Set a default group. New object are added to this group if it's enabled in their class with `add_to_def_group = true` 105 * @param group pointer to a group (can be `NULL`) 106 */ 107 void lv_group_set_default(lv_group_t * group); 108 109 /** 110 * Get the default group 111 * @return pointer to the default group 112 */ 113 lv_group_t * lv_group_get_default(void); 114 115 /** 116 * Add an object to a group 117 * @param group pointer to a group 118 * @param obj pointer to an object to add 119 */ 120 void lv_group_add_obj(lv_group_t * group, struct _lv_obj_t * obj); 121 122 /** 123 * Swap 2 object in a group. The object must be in the same group 124 * @param obj1 pointer to an object 125 * @param obj2 pointer to an other object 126 */ 127 void lv_group_swap_obj(struct _lv_obj_t * obj1, struct _lv_obj_t * obj2); 128 129 /** 130 * Remove an object from its group 131 * @param obj pointer to an object to remove 132 */ 133 void lv_group_remove_obj(struct _lv_obj_t * obj); 134 135 /** 136 * Remove all objects from a group 137 * @param group pointer to a group 138 */ 139 void lv_group_remove_all_objs(lv_group_t * group); 140 141 /** 142 * Focus on an object (defocus the current) 143 * @param obj pointer to an object to focus on 144 */ 145 void lv_group_focus_obj(struct _lv_obj_t * obj); 146 147 /** 148 * Focus the next object in a group (defocus the current) 149 * @param group pointer to a group 150 */ 151 void lv_group_focus_next(lv_group_t * group); 152 153 /** 154 * Focus the previous object in a group (defocus the current) 155 * @param group pointer to a group 156 */ 157 void lv_group_focus_prev(lv_group_t * group); 158 159 /** 160 * Do not let to change the focus from the current object 161 * @param group pointer to a group 162 * @param en true: freeze, false: release freezing (normal mode) 163 */ 164 void lv_group_focus_freeze(lv_group_t * group, bool en); 165 166 /** 167 * Send a control character to the focuses object of a group 168 * @param group pointer to a group 169 * @param c a character (use LV_KEY_.. to navigate) 170 * @return result of focused object in group. 171 */ 172 lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c); 173 174 /** 175 * Set a function for a group which will be called when a new object is focused 176 * @param group pointer to a group 177 * @param focus_cb the call back function or NULL if unused 178 */ 179 void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb); 180 181 /** 182 * Set whether the next or previous item in a group is focused if the currently focused obj is 183 * deleted. 184 * @param group pointer to a group 185 * @param policy new refocus policy enum 186 */ 187 void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy); 188 189 /** 190 * Manually set the current mode (edit or navigate). 191 * @param group pointer to group 192 * @param edit true: edit mode; false: navigate mode 193 */ 194 void lv_group_set_editing(lv_group_t * group, bool edit); 195 196 /** 197 * Set whether focus next/prev will allow wrapping from first->last or last->first object. 198 * @param group pointer to group 199 * @param en true: wrapping enabled; false: wrapping disabled 200 */ 201 void lv_group_set_wrap(lv_group_t * group, bool en); 202 203 /** 204 * Get the focused object or NULL if there isn't one 205 * @param group pointer to a group 206 * @return pointer to the focused object 207 */ 208 struct _lv_obj_t * lv_group_get_focused(const lv_group_t * group); 209 210 /** 211 * Get the focus callback function of a group 212 * @param group pointer to a group 213 * @return the call back function or NULL if not set 214 */ 215 lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group); 216 217 /** 218 * Get the current mode (edit or navigate). 219 * @param group pointer to group 220 * @return true: edit mode; false: navigate mode 221 */ 222 bool lv_group_get_editing(const lv_group_t * group); 223 224 /** 225 * Get whether focus next/prev will allow wrapping from first->last or last->first object. 226 * @param group pointer to group 227 * @param en true: wrapping enabled; false: wrapping disabled 228 */ 229 bool lv_group_get_wrap(lv_group_t * group); 230 231 /** 232 * Get the number of object in the group 233 * @param group pointer to a group 234 * @return number of objects in the group 235 */ 236 uint32_t lv_group_get_obj_count(lv_group_t * group); 237 238 /********************** 239 * MACROS 240 **********************/ 241 242 #ifdef __cplusplus 243 } /*extern "C"*/ 244 #endif 245 246 #endif /*LV_GROUP_H*/ 247