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