1 /** 2 * @file lv_obj.h 3 * 4 */ 5 6 #ifndef LV_OBJ_H 7 #define LV_OBJ_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_style.h" 20 #include "../misc/lv_area.h" 21 #include "../misc/lv_color.h" 22 #include "../misc/lv_assert.h" 23 24 #include "lv_obj_tree.h" 25 #include "lv_obj_pos.h" 26 #include "lv_obj_scroll.h" 27 #include "lv_obj_style.h" 28 #include "lv_obj_draw.h" 29 #include "lv_obj_class.h" 30 #include "lv_obj_event.h" 31 #include "lv_obj_property.h" 32 #include "lv_group.h" 33 34 /********************* 35 * DEFINES 36 *********************/ 37 38 /********************** 39 * TYPEDEFS 40 **********************/ 41 42 /** 43 * Possible states of a widget. 44 * OR-ed values are possible 45 */ 46 enum { 47 LV_STATE_DEFAULT = 0x0000, 48 LV_STATE_CHECKED = 0x0001, 49 LV_STATE_FOCUSED = 0x0002, 50 LV_STATE_FOCUS_KEY = 0x0004, 51 LV_STATE_EDITED = 0x0008, 52 LV_STATE_HOVERED = 0x0010, 53 LV_STATE_PRESSED = 0x0020, 54 LV_STATE_SCROLLED = 0x0040, 55 LV_STATE_DISABLED = 0x0080, 56 LV_STATE_USER_1 = 0x1000, 57 LV_STATE_USER_2 = 0x2000, 58 LV_STATE_USER_3 = 0x4000, 59 LV_STATE_USER_4 = 0x8000, 60 61 LV_STATE_ANY = 0xFFFF, /**< Special value can be used in some functions to target all states*/ 62 }; 63 64 /** 65 * The possible parts of widgets. 66 * The parts can be considered as the internal building block of the widgets. 67 * E.g. slider = background + indicator + knob 68 * Not all parts are used by every widget 69 */ 70 71 enum { 72 LV_PART_MAIN = 0x000000, /**< A background like rectangle*/ 73 LV_PART_SCROLLBAR = 0x010000, /**< The scrollbar(s)*/ 74 LV_PART_INDICATOR = 0x020000, /**< Indicator, e.g. for slider, bar, switch, or the tick box of the checkbox*/ 75 LV_PART_KNOB = 0x030000, /**< Like handle to grab to adjust the value*/ 76 LV_PART_SELECTED = 0x040000, /**< Indicate the currently selected option or section*/ 77 LV_PART_ITEMS = 0x050000, /**< Used if the widget has multiple similar elements (e.g. table cells)*/ 78 LV_PART_CURSOR = 0x060000, /**< Mark a specific place e.g. for text area's cursor or on a chart*/ 79 80 LV_PART_CUSTOM_FIRST = 0x080000, /**< Extension point for custom widgets*/ 81 82 LV_PART_ANY = 0x0F0000, /**< Special value can be used in some functions to target all parts*/ 83 }; 84 85 /** 86 * On/Off features controlling the object's behavior. 87 * OR-ed values are possible 88 * 89 * Note: update obj flags corresponding properties below 90 * whenever add/remove flags or change bit definition of flags. 91 */ 92 typedef enum { 93 LV_OBJ_FLAG_HIDDEN = (1L << 0), /**< Make the object hidden. (Like it wasn't there at all)*/ 94 LV_OBJ_FLAG_CLICKABLE = (1L << 1), /**< Make the object clickable by the input devices*/ 95 LV_OBJ_FLAG_CLICK_FOCUSABLE = (1L << 2), /**< Add focused state to the object when clicked*/ 96 LV_OBJ_FLAG_CHECKABLE = (1L << 3), /**< Toggle checked state when the object is clicked*/ 97 LV_OBJ_FLAG_SCROLLABLE = (1L << 4), /**< Make the object scrollable*/ 98 LV_OBJ_FLAG_SCROLL_ELASTIC = (1L << 5), /**< Allow scrolling inside but with slower speed*/ 99 LV_OBJ_FLAG_SCROLL_MOMENTUM = (1L << 6), /**< Make the object scroll further when "thrown"*/ 100 LV_OBJ_FLAG_SCROLL_ONE = (1L << 7), /**< Allow scrolling only one snappable children*/ 101 LV_OBJ_FLAG_SCROLL_CHAIN_HOR = (1L << 8), /**< Allow propagating the horizontal scroll to a parent*/ 102 LV_OBJ_FLAG_SCROLL_CHAIN_VER = (1L << 9), /**< Allow propagating the vertical scroll to a parent*/ 103 LV_OBJ_FLAG_SCROLL_CHAIN = (LV_OBJ_FLAG_SCROLL_CHAIN_HOR | LV_OBJ_FLAG_SCROLL_CHAIN_VER), 104 LV_OBJ_FLAG_SCROLL_ON_FOCUS = (1L << 10), /**< Automatically scroll object to make it visible when focused*/ 105 LV_OBJ_FLAG_SCROLL_WITH_ARROW = (1L << 11), /**< Allow scrolling the focused object with arrow keys*/ 106 LV_OBJ_FLAG_SNAPPABLE = (1L << 12), /**< If scroll snap is enabled on the parent it can snap to this object*/ 107 LV_OBJ_FLAG_PRESS_LOCK = (1L << 13), /**< Keep the object pressed even if the press slid from the object*/ 108 LV_OBJ_FLAG_EVENT_BUBBLE = (1L << 14), /**< Propagate the events to the parent too*/ 109 LV_OBJ_FLAG_GESTURE_BUBBLE = (1L << 15), /**< Propagate the gestures to the parent*/ 110 LV_OBJ_FLAG_ADV_HITTEST = (1L << 16), /**< Allow performing more accurate hit (click) test. E.g. consider rounded corners.*/ 111 LV_OBJ_FLAG_IGNORE_LAYOUT = (1L << 17), /**< Make the object not positioned by the layouts*/ 112 LV_OBJ_FLAG_FLOATING = (1L << 18), /**< Do not scroll the object when the parent scrolls and ignore layout*/ 113 LV_OBJ_FLAG_SEND_DRAW_TASK_EVENTS = (1L << 19), /**< Send `LV_EVENT_DRAW_TASK_ADDED` events*/ 114 LV_OBJ_FLAG_OVERFLOW_VISIBLE = (1L << 20),/**< Do not clip the children to the parent's ext draw size*/ 115 #if LV_USE_FLEX 116 LV_OBJ_FLAG_FLEX_IN_NEW_TRACK = (1L << 21), /**< Start a new flex track on this item*/ 117 #endif 118 119 LV_OBJ_FLAG_LAYOUT_1 = (1L << 23), /**< Custom flag, free to use by layouts*/ 120 LV_OBJ_FLAG_LAYOUT_2 = (1L << 24), /**< Custom flag, free to use by layouts*/ 121 122 LV_OBJ_FLAG_WIDGET_1 = (1L << 25), /**< Custom flag, free to use by widget*/ 123 LV_OBJ_FLAG_WIDGET_2 = (1L << 26), /**< Custom flag, free to use by widget*/ 124 LV_OBJ_FLAG_USER_1 = (1L << 27), /**< Custom flag, free to use by user*/ 125 LV_OBJ_FLAG_USER_2 = (1L << 28), /**< Custom flag, free to use by user*/ 126 LV_OBJ_FLAG_USER_3 = (1L << 29), /**< Custom flag, free to use by user*/ 127 LV_OBJ_FLAG_USER_4 = (1L << 30), /**< Custom flag, free to use by user*/ 128 } lv_obj_flag_t; 129 130 #if LV_USE_OBJ_PROPERTY 131 enum { 132 /*OBJ flag properties */ 133 LV_PROPERTY_ID(OBJ, FLAG_START, LV_PROPERTY_TYPE_INT, 0), 134 LV_PROPERTY_ID(OBJ, FLAG_HIDDEN, LV_PROPERTY_TYPE_INT, 0), 135 LV_PROPERTY_ID(OBJ, FLAG_CLICKABLE, LV_PROPERTY_TYPE_INT, 1), 136 LV_PROPERTY_ID(OBJ, FLAG_CLICK_FOCUSABLE, LV_PROPERTY_TYPE_INT, 2), 137 LV_PROPERTY_ID(OBJ, FLAG_CHECKABLE, LV_PROPERTY_TYPE_INT, 3), 138 LV_PROPERTY_ID(OBJ, FLAG_SCROLLABLE, LV_PROPERTY_TYPE_INT, 4), 139 LV_PROPERTY_ID(OBJ, FLAG_SCROLL_ELASTIC, LV_PROPERTY_TYPE_INT, 5), 140 LV_PROPERTY_ID(OBJ, FLAG_SCROLL_MOMENTUM, LV_PROPERTY_TYPE_INT, 6), 141 LV_PROPERTY_ID(OBJ, FLAG_SCROLL_ONE, LV_PROPERTY_TYPE_INT, 7), 142 LV_PROPERTY_ID(OBJ, FLAG_SCROLL_CHAIN_HOR, LV_PROPERTY_TYPE_INT, 8), 143 LV_PROPERTY_ID(OBJ, FLAG_SCROLL_CHAIN_VER, LV_PROPERTY_TYPE_INT, 9), 144 LV_PROPERTY_ID(OBJ, FLAG_SCROLL_ON_FOCUS, LV_PROPERTY_TYPE_INT, 10), 145 LV_PROPERTY_ID(OBJ, FLAG_SCROLL_WITH_ARROW, LV_PROPERTY_TYPE_INT, 11), 146 LV_PROPERTY_ID(OBJ, FLAG_SNAPPABLE, LV_PROPERTY_TYPE_INT, 12), 147 LV_PROPERTY_ID(OBJ, FLAG_PRESS_LOCK, LV_PROPERTY_TYPE_INT, 13), 148 LV_PROPERTY_ID(OBJ, FLAG_EVENT_BUBBLE, LV_PROPERTY_TYPE_INT, 14), 149 LV_PROPERTY_ID(OBJ, FLAG_GESTURE_BUBBLE, LV_PROPERTY_TYPE_INT, 15), 150 LV_PROPERTY_ID(OBJ, FLAG_ADV_HITTEST, LV_PROPERTY_TYPE_INT, 16), 151 LV_PROPERTY_ID(OBJ, FLAG_IGNORE_LAYOUT, LV_PROPERTY_TYPE_INT, 17), 152 LV_PROPERTY_ID(OBJ, FLAG_FLOATING, LV_PROPERTY_TYPE_INT, 18), 153 LV_PROPERTY_ID(OBJ, FLAG_SEND_DRAW_TASK_EVENTS, LV_PROPERTY_TYPE_INT, 19), 154 LV_PROPERTY_ID(OBJ, FLAG_OVERFLOW_VISIBLE, LV_PROPERTY_TYPE_INT, 20), 155 LV_PROPERTY_ID(OBJ, FLAG_FLEX_IN_NEW_TRACK, LV_PROPERTY_TYPE_INT, 21), 156 LV_PROPERTY_ID(OBJ, FLAG_LAYOUT_1, LV_PROPERTY_TYPE_INT, 23), 157 LV_PROPERTY_ID(OBJ, FLAG_LAYOUT_2, LV_PROPERTY_TYPE_INT, 24), 158 LV_PROPERTY_ID(OBJ, FLAG_WIDGET_1, LV_PROPERTY_TYPE_INT, 25), 159 LV_PROPERTY_ID(OBJ, FLAG_WIDGET_2, LV_PROPERTY_TYPE_INT, 26), 160 LV_PROPERTY_ID(OBJ, FLAG_USER_1, LV_PROPERTY_TYPE_INT, 27), 161 LV_PROPERTY_ID(OBJ, FLAG_USER_2, LV_PROPERTY_TYPE_INT, 28), 162 LV_PROPERTY_ID(OBJ, FLAG_USER_3, LV_PROPERTY_TYPE_INT, 29), 163 LV_PROPERTY_ID(OBJ, FLAG_USER_4, LV_PROPERTY_TYPE_INT, 30), 164 LV_PROPERTY_ID(OBJ, FLAG_END, LV_PROPERTY_TYPE_INT, 30), 165 166 LV_PROPERTY_ID(OBJ, STATE_START, LV_PROPERTY_TYPE_INT, 31), 167 LV_PROPERTY_ID(OBJ, STATE_CHECKED, LV_PROPERTY_TYPE_INT, 31), 168 LV_PROPERTY_ID(OBJ, STATE_FOCUSED, LV_PROPERTY_TYPE_INT, 32), 169 LV_PROPERTY_ID(OBJ, STATE_FOCUS_KEY, LV_PROPERTY_TYPE_INT, 33), 170 LV_PROPERTY_ID(OBJ, STATE_EDITED, LV_PROPERTY_TYPE_INT, 34), 171 LV_PROPERTY_ID(OBJ, STATE_HOVERED, LV_PROPERTY_TYPE_INT, 35), 172 LV_PROPERTY_ID(OBJ, STATE_PRESSED, LV_PROPERTY_TYPE_INT, 36), 173 LV_PROPERTY_ID(OBJ, STATE_SCROLLED, LV_PROPERTY_TYPE_INT, 37), 174 LV_PROPERTY_ID(OBJ, STATE_DISABLED, LV_PROPERTY_TYPE_INT, 38), 175 /*not used bit8-bit11*/ 176 LV_PROPERTY_ID(OBJ, STATE_USER_1, LV_PROPERTY_TYPE_INT, 43), 177 LV_PROPERTY_ID(OBJ, STATE_USER_2, LV_PROPERTY_TYPE_INT, 44), 178 LV_PROPERTY_ID(OBJ, STATE_USER_3, LV_PROPERTY_TYPE_INT, 45), 179 LV_PROPERTY_ID(OBJ, STATE_USER_4, LV_PROPERTY_TYPE_INT, 46), 180 LV_PROPERTY_ID(OBJ, STATE_ANY, LV_PROPERTY_TYPE_INT, 47), 181 LV_PROPERTY_ID(OBJ, STATE_END, LV_PROPERTY_TYPE_INT, 47), 182 183 /*OBJ normal properties*/ 184 LV_PROPERTY_ID(OBJ, PARENT, LV_PROPERTY_TYPE_OBJ, 48), 185 LV_PROPERTY_ID(OBJ, X, LV_PROPERTY_TYPE_INT, 49), 186 LV_PROPERTY_ID(OBJ, Y, LV_PROPERTY_TYPE_INT, 50), 187 LV_PROPERTY_ID(OBJ, W, LV_PROPERTY_TYPE_INT, 51), 188 LV_PROPERTY_ID(OBJ, H, LV_PROPERTY_TYPE_INT, 52), 189 LV_PROPERTY_ID(OBJ, CONTENT_WIDTH, LV_PROPERTY_TYPE_INT, 53), 190 LV_PROPERTY_ID(OBJ, CONTENT_HEIGHT, LV_PROPERTY_TYPE_INT, 54), 191 LV_PROPERTY_ID(OBJ, LAYOUT, LV_PROPERTY_TYPE_INT, 55), 192 LV_PROPERTY_ID(OBJ, ALIGN, LV_PROPERTY_TYPE_INT, 56), 193 LV_PROPERTY_ID(OBJ, SCROLLBAR_MODE, LV_PROPERTY_TYPE_INT, 57), 194 LV_PROPERTY_ID(OBJ, SCROLL_DIR, LV_PROPERTY_TYPE_INT, 58), 195 LV_PROPERTY_ID(OBJ, SCROLL_SNAP_X, LV_PROPERTY_TYPE_INT, 59), 196 LV_PROPERTY_ID(OBJ, SCROLL_SNAP_Y, LV_PROPERTY_TYPE_INT, 60), 197 LV_PROPERTY_ID(OBJ, SCROLL_X, LV_PROPERTY_TYPE_INT, 61), 198 LV_PROPERTY_ID(OBJ, SCROLL_Y, LV_PROPERTY_TYPE_INT, 62), 199 LV_PROPERTY_ID(OBJ, SCROLL_TOP, LV_PROPERTY_TYPE_INT, 63), 200 LV_PROPERTY_ID(OBJ, SCROLL_BOTTOM, LV_PROPERTY_TYPE_INT, 64), 201 LV_PROPERTY_ID(OBJ, SCROLL_LEFT, LV_PROPERTY_TYPE_INT, 65), 202 LV_PROPERTY_ID(OBJ, SCROLL_RIGHT, LV_PROPERTY_TYPE_INT, 66), 203 LV_PROPERTY_ID(OBJ, SCROLL_END, LV_PROPERTY_TYPE_INT, 67), 204 LV_PROPERTY_ID(OBJ, EXT_DRAW_SIZE, LV_PROPERTY_TYPE_INT, 68), 205 LV_PROPERTY_ID(OBJ, EVENT_COUNT, LV_PROPERTY_TYPE_INT, 69), 206 LV_PROPERTY_ID(OBJ, SCREEN, LV_PROPERTY_TYPE_OBJ, 70), 207 LV_PROPERTY_ID(OBJ, DISPLAY, LV_PROPERTY_TYPE_POINTER, 71), 208 LV_PROPERTY_ID(OBJ, CHILD_COUNT, LV_PROPERTY_TYPE_INT, 72), 209 LV_PROPERTY_ID(OBJ, INDEX, LV_PROPERTY_TYPE_INT, 73), 210 211 LV_PROPERTY_OBJ_END, 212 }; 213 #endif 214 215 /** 216 * Make the base object's class publicly available. 217 */ 218 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_obj_class; 219 220 /********************** 221 * GLOBAL PROTOTYPES 222 **********************/ 223 224 /** 225 * Create a base object (a rectangle) 226 * @param parent pointer to a parent object. If NULL then a screen will be created. 227 * @return pointer to the new object 228 */ 229 lv_obj_t * lv_obj_create(lv_obj_t * parent); 230 231 /*===================== 232 * Setter functions 233 *====================*/ 234 235 /** 236 * Set one or more flags 237 * @param obj pointer to an object 238 * @param f OR-ed values from `lv_obj_flag_t` to set. 239 */ 240 void lv_obj_add_flag(lv_obj_t * obj, lv_obj_flag_t f); 241 242 /** 243 * Remove one or more flags 244 * @param obj pointer to an object 245 * @param f OR-ed values from `lv_obj_flag_t` to clear. 246 */ 247 void lv_obj_remove_flag(lv_obj_t * obj, lv_obj_flag_t f); 248 249 /** 250 * Set add or remove one or more flags. 251 * @param obj pointer to an object 252 * @param f OR-ed values from `lv_obj_flag_t` to update. 253 * @param v true: add the flags; false: remove the flags 254 */ 255 void lv_obj_update_flag(lv_obj_t * obj, lv_obj_flag_t f, bool v); 256 257 /** 258 * Add one or more states to the object. The other state bits will remain unchanged. 259 * If specified in the styles, transition animation will be started from the previous state to the current. 260 * @param obj pointer to an object 261 * @param state the states to add. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED` 262 */ 263 void lv_obj_add_state(lv_obj_t * obj, lv_state_t state); 264 265 /** 266 * Remove one or more states to the object. The other state bits will remain unchanged. 267 * If specified in the styles, transition animation will be started from the previous state to the current. 268 * @param obj pointer to an object 269 * @param state the states to add. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED` 270 */ 271 void lv_obj_remove_state(lv_obj_t * obj, lv_state_t state); 272 273 /** 274 * Add or remove one or more states to the object. The other state bits will remain unchanged. 275 * @param obj pointer to an object 276 * @param state the states to add. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED` 277 * @param v true: add the states; false: remove the states 278 */ 279 void lv_obj_set_state(lv_obj_t * obj, lv_state_t state, bool v); 280 281 /** 282 * Set the user_data field of the object 283 * @param obj pointer to an object 284 * @param user_data pointer to the new user_data. 285 */ 286 void lv_obj_set_user_data(lv_obj_t * obj, void * user_data); 287 288 /*======================= 289 * Getter functions 290 *======================*/ 291 292 /** 293 * Check if a given flag or all the given flags are set on an object. 294 * @param obj pointer to an object 295 * @param f the flag(s) to check (OR-ed values can be used) 296 * @return true: all flags are set; false: not all flags are set 297 */ 298 bool lv_obj_has_flag(const lv_obj_t * obj, lv_obj_flag_t f); 299 300 /** 301 * Check if a given flag or any of the flags are set on an object. 302 * @param obj pointer to an object 303 * @param f the flag(s) to check (OR-ed values can be used) 304 * @return true: at least one flag is set; false: none of the flags are set 305 */ 306 bool lv_obj_has_flag_any(const lv_obj_t * obj, lv_obj_flag_t f); 307 308 /** 309 * Get the state of an object 310 * @param obj pointer to an object 311 * @return the state (OR-ed values from `lv_state_t`) 312 */ 313 lv_state_t lv_obj_get_state(const lv_obj_t * obj); 314 315 /** 316 * Check if the object is in a given state or not. 317 * @param obj pointer to an object 318 * @param state a state or combination of states to check 319 * @return true: `obj` is in `state`; false: `obj` is not in `state` 320 */ 321 bool lv_obj_has_state(const lv_obj_t * obj, lv_state_t state); 322 323 /** 324 * Get the group of the object 325 * @param obj pointer to an object 326 * @return the pointer to group of the object 327 */ 328 lv_group_t * lv_obj_get_group(const lv_obj_t * obj); 329 330 /** 331 * Get the user_data field of the object 332 * @param obj pointer to an object 333 * @return the pointer to the user_data of the object 334 */ 335 void * lv_obj_get_user_data(lv_obj_t * obj); 336 337 /*======================= 338 * Other functions 339 *======================*/ 340 341 /** 342 * Allocate special data for an object if not allocated yet. 343 * @param obj pointer to an object 344 */ 345 void lv_obj_allocate_spec_attr(lv_obj_t * obj); 346 347 /** 348 * Check the type of obj. 349 * @param obj pointer to an object 350 * @param class_p a class to check (e.g. `lv_slider_class`) 351 * @return true: `class_p` is the `obj` class. 352 */ 353 bool lv_obj_check_type(const lv_obj_t * obj, const lv_obj_class_t * class_p); 354 355 /** 356 * Check if any object has a given class (type). 357 * It checks the ancestor classes too. 358 * @param obj pointer to an object 359 * @param class_p a class to check (e.g. `lv_slider_class`) 360 * @return true: `obj` has the given class 361 */ 362 bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p); 363 364 /** 365 * Get the class (type) of the object 366 * @param obj pointer to an object 367 * @return the class (type) of the object 368 */ 369 const lv_obj_class_t * lv_obj_get_class(const lv_obj_t * obj); 370 371 /** 372 * Check if any object is still "alive". 373 * @param obj pointer to an object 374 * @return true: valid 375 */ 376 bool lv_obj_is_valid(const lv_obj_t * obj); 377 378 /** 379 * Utility to set an object reference to NULL when it gets deleted. 380 * The reference should be in a location that will not become invalid 381 * during the object's lifetime, i.e. static or allocated. 382 * @param obj_ptr a pointer to a pointer to an object 383 */ 384 void lv_obj_null_on_delete(lv_obj_t ** obj_ptr); 385 386 #if LV_USE_OBJ_ID 387 /** 388 * Set an id for an object. 389 * @param obj pointer to an object 390 * @param id the id of the object 391 */ 392 void lv_obj_set_id(lv_obj_t * obj, void * id); 393 394 /** 395 * Get the id of an object. 396 * @param obj pointer to an object 397 * @return the id of the object 398 */ 399 void * lv_obj_get_id(const lv_obj_t * obj); 400 401 /** 402 * Get the child object by its id. 403 * It will check children and grandchildren recursively. 404 * Function `lv_obj_id_compare` is used to matched obj id with given id. 405 * 406 * @param obj pointer to an object 407 * @param id the id of the child object 408 * @return pointer to the child object or NULL if not found 409 */ 410 lv_obj_t * lv_obj_get_child_by_id(const lv_obj_t * obj, const void * id); 411 412 /** 413 * Assign id to object if not previously assigned. 414 * This function gets called automatically when LV_OBJ_ID_AUTO_ASSIGN is enabled. 415 * 416 * Set `LV_USE_OBJ_ID_BUILTIN` to use the builtin method to generate object ID. 417 * Otherwise, these functions including `lv_obj_[set|assign|free|stringify]_id` and 418 * `lv_obj_id_compare`should be implemented externally. 419 * 420 * @param class_p the class this obj belongs to. Note obj->class_p is the class currently being constructed. 421 * @param obj pointer to an object 422 */ 423 void lv_obj_assign_id(const lv_obj_class_t * class_p, lv_obj_t * obj); 424 425 /** 426 * Free resources allocated by `lv_obj_assign_id` or `lv_obj_set_id`. 427 * This function is also called automatically when object is deleted. 428 * @param obj pointer to an object 429 */ 430 void lv_obj_free_id(lv_obj_t * obj); 431 432 /** 433 * Compare two obj id, return 0 if they are equal. 434 * 435 * Set `LV_USE_OBJ_ID_BUILTIN` to use the builtin method for compare. 436 * Otherwise, it must be implemented externally. 437 * 438 * @param id1: the first id 439 * @param id2: the second id 440 * @return 0 if they are equal, non-zero otherwise. 441 */ 442 int lv_obj_id_compare(const void * id1, const void * id2); 443 444 /** 445 * Format an object's id into a string. 446 * @param obj pointer to an object 447 * @param buf buffer to write the string into 448 * @param len length of the buffer 449 */ 450 const char * lv_obj_stringify_id(lv_obj_t * obj, char * buf, uint32_t len); 451 452 #if LV_USE_OBJ_ID_BUILTIN 453 /** 454 * Free resources used by builtin ID generator. 455 */ 456 void lv_objid_builtin_destroy(void); 457 #endif 458 459 #endif /*LV_USE_OBJ_ID*/ 460 461 /********************** 462 * MACROS 463 **********************/ 464 465 #if LV_USE_ASSERT_OBJ 466 # define LV_ASSERT_OBJ(obj_p, obj_class) \ 467 do { \ 468 LV_ASSERT_MSG(obj_p != NULL, "The object is NULL"); \ 469 LV_ASSERT_MSG(lv_obj_has_class(obj_p, obj_class) == true, "Incompatible object type."); \ 470 LV_ASSERT_MSG(lv_obj_is_valid(obj_p) == true, "The object is invalid, deleted or corrupted?"); \ 471 } while(0) 472 # else 473 # define LV_ASSERT_OBJ(obj_p, obj_class) LV_ASSERT_NULL(obj_p) 474 #endif 475 476 #if LV_USE_LOG && LV_LOG_TRACE_OBJ_CREATE 477 # define LV_TRACE_OBJ_CREATE(...) LV_LOG_TRACE(__VA_ARGS__) 478 #else 479 # define LV_TRACE_OBJ_CREATE(...) 480 #endif 481 482 #ifdef __cplusplus 483 } /*extern "C"*/ 484 #endif 485 486 #endif /*LV_OBJ_H*/ 487