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 <stddef.h> 19 #include <stdbool.h> 20 #include "lv_style.h" 21 #include "../lv_misc/lv_types.h" 22 #include "../lv_misc/lv_area.h" 23 #include "../lv_misc/lv_color.h" 24 #include "../lv_misc/lv_debug.h" 25 #include "../lv_hal/lv_hal.h" 26 #include "../lv_draw/lv_draw_rect.h" 27 #include "../lv_draw/lv_draw_label.h" 28 #include "../lv_draw/lv_draw_line.h" 29 #include "../lv_draw/lv_draw_img.h" 30 31 /********************* 32 * DEFINES 33 *********************/ 34 35 /*Error check of lv_conf.h*/ 36 #if LV_HOR_RES_MAX == 0 || LV_VER_RES_MAX == 0 37 #error "LVGL: LV_HOR_RES_MAX and LV_VER_RES_MAX must be greater than 0" 38 #endif 39 40 #if LV_ANTIALIAS > 1 41 #error "LVGL: LV_ANTIALIAS can be only 0 or 1" 42 #endif 43 44 #define LV_MAX_ANCESTOR_NUM 8 45 46 #define LV_EXT_CLICK_AREA_OFF 0 47 #define LV_EXT_CLICK_AREA_TINY 1 48 #define LV_EXT_CLICK_AREA_FULL 2 49 50 #define _LV_OBJ_PART_VIRTUAL_FIRST 0x01 51 #define _LV_OBJ_PART_REAL_FIRST 0x40 52 53 /********************** 54 * TYPEDEFS 55 **********************/ 56 57 struct _lv_obj_t; 58 59 60 /** Design modes */ 61 enum { 62 LV_DESIGN_DRAW_MAIN, /**< Draw the main portion of the object */ 63 LV_DESIGN_DRAW_POST, /**< Draw extras on the object */ 64 LV_DESIGN_COVER_CHK, /**< Check if the object fully covers the 'mask_p' area */ 65 }; 66 typedef uint8_t lv_design_mode_t; 67 68 69 /** Design results */ 70 enum { 71 LV_DESIGN_RES_OK, /**< Draw ready */ 72 LV_DESIGN_RES_COVER, /**< Returned on `LV_DESIGN_COVER_CHK` if the areas is fully covered*/ 73 LV_DESIGN_RES_NOT_COVER, /**< Returned on `LV_DESIGN_COVER_CHK` if the areas is not covered*/ 74 LV_DESIGN_RES_MASKED, /**< Returned on `LV_DESIGN_COVER_CHK` if the areas is masked out (children also not cover)*/ 75 }; 76 typedef uint8_t lv_design_res_t; 77 78 /** 79 * The design callback is used to draw the object on the screen. 80 * It accepts the object, a mask area, and the mode in which to draw the object. 81 */ 82 typedef lv_design_res_t (*lv_design_cb_t)(struct _lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode); 83 84 enum { 85 LV_EVENT_PRESSED, /**< The object has been pressed*/ 86 LV_EVENT_PRESSING, /**< The object is being pressed (called continuously while pressing)*/ 87 LV_EVENT_PRESS_LOST, /**< User is still pressing but slid cursor/finger off of the object */ 88 LV_EVENT_SHORT_CLICKED, /**< User pressed object for a short period of time, then released it. Not called if dragged. */ 89 LV_EVENT_LONG_PRESSED, /**< Object has been pressed for at least `LV_INDEV_LONG_PRESS_TIME`. Not called if dragged.*/ 90 LV_EVENT_LONG_PRESSED_REPEAT, /**< Called after `LV_INDEV_LONG_PRESS_TIME` in every 91 `LV_INDEV_LONG_PRESS_REP_TIME` ms. Not called if dragged.*/ 92 LV_EVENT_CLICKED, /**< Called on release if not dragged (regardless to long press)*/ 93 LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/ 94 LV_EVENT_DRAG_BEGIN, 95 LV_EVENT_DRAG_END, 96 LV_EVENT_DRAG_THROW_BEGIN, 97 LV_EVENT_GESTURE, /**< The object has been gesture*/ 98 LV_EVENT_KEY, 99 LV_EVENT_FOCUSED, 100 LV_EVENT_DEFOCUSED, 101 LV_EVENT_LEAVE, 102 LV_EVENT_VALUE_CHANGED, /**< The object's value has changed (i.e. slider moved) */ 103 LV_EVENT_INSERT, 104 LV_EVENT_REFRESH, 105 LV_EVENT_APPLY, /**< "Ok", "Apply" or similar specific button has clicked*/ 106 LV_EVENT_CANCEL, /**< "Close", "Cancel" or similar specific button has clicked*/ 107 LV_EVENT_DELETE, /**< Object is being deleted */ 108 _LV_EVENT_LAST /** Number of events*/ 109 }; 110 typedef uint8_t lv_event_t; /**< Type of event being sent to the object. */ 111 112 /** 113 * @brief Event callback. 114 * Events are used to notify the user of some action being taken on the object. 115 * For details, see ::lv_event_t. 116 */ 117 typedef void (*lv_event_cb_t)(struct _lv_obj_t * obj, lv_event_t event); 118 119 /** Signals are for use by the object itself or to extend the object's functionality. 120 * Applications should use ::lv_obj_set_event_cb to be notified of events that occur 121 * on the object. */ 122 enum { 123 /*General signals*/ 124 LV_SIGNAL_CLEANUP, /**< Object is being deleted */ 125 LV_SIGNAL_CHILD_CHG, /**< Child was removed/added */ 126 LV_SIGNAL_COORD_CHG, /**< Object coordinates/size have changed */ 127 LV_SIGNAL_PARENT_SIZE_CHG, /**< Parent's size has changed */ 128 LV_SIGNAL_STYLE_CHG, /**< Object's style has changed */ 129 LV_SIGNAL_BASE_DIR_CHG, /**<The base dir has changed*/ 130 LV_SIGNAL_REFR_EXT_DRAW_PAD, /**< Object's extra padding has changed */ 131 LV_SIGNAL_GET_TYPE, /**< LVGL needs to retrieve the object's type */ 132 LV_SIGNAL_GET_STYLE, /**<Get the style of an object*/ 133 LV_SIGNAL_GET_STATE_DSC, /**<Get the state of the object*/ 134 135 /*Input device related*/ 136 LV_SIGNAL_HIT_TEST, /**< Advanced hit-testing */ 137 LV_SIGNAL_PRESSED, /**< The object has been pressed*/ 138 LV_SIGNAL_PRESSING, /**< The object is being pressed (called continuously while pressing)*/ 139 LV_SIGNAL_PRESS_LOST, /**< User is still pressing but slid cursor/finger off of the object */ 140 LV_SIGNAL_RELEASED, /**< User pressed object for a short period of time, then released it. Not called if dragged. */ 141 LV_SIGNAL_LONG_PRESS, /**< Object has been pressed for at least `LV_INDEV_LONG_PRESS_TIME`. Not called if dragged.*/ 142 LV_SIGNAL_LONG_PRESS_REP, /**< Called after `LV_INDEV_LONG_PRESS_TIME` in every `LV_INDEV_LONG_PRESS_REP_TIME` ms. Not called if dragged.*/ 143 LV_SIGNAL_DRAG_BEGIN, 144 LV_SIGNAL_DRAG_THROW_BEGIN, 145 LV_SIGNAL_DRAG_END, 146 LV_SIGNAL_GESTURE, /**< The object has been gesture*/ 147 LV_SIGNAL_LEAVE, /**< Another object is clicked or chosen via an input device */ 148 149 /*Group related*/ 150 LV_SIGNAL_FOCUS, 151 LV_SIGNAL_DEFOCUS, 152 LV_SIGNAL_CONTROL, 153 LV_SIGNAL_GET_EDITABLE, 154 }; 155 typedef uint8_t lv_signal_t; 156 157 typedef lv_res_t (*lv_signal_cb_t)(struct _lv_obj_t * obj, lv_signal_t sign, void * param); 158 159 #if LV_USE_OBJ_REALIGN 160 typedef struct { 161 const struct _lv_obj_t * base; 162 lv_coord_t xofs; 163 lv_coord_t yofs; 164 lv_align_t align; 165 uint8_t auto_realign : 1; 166 uint8_t mid_align : 1; /**< 1: the origo (center of the object) was aligned with 167 `lv_obj_align_origo`*/ 168 } lv_realign_t; 169 #endif 170 171 /*Protect some attributes (max. 8 bit)*/ 172 enum { 173 LV_PROTECT_NONE = 0x00, 174 LV_PROTECT_CHILD_CHG = 0x01, /**< Disable the child change signal. Used by the library*/ 175 LV_PROTECT_PARENT = 0x02, /**< Prevent automatic parent change (e.g. in lv_page)*/ 176 LV_PROTECT_POS = 0x04, /**< Prevent automatic positioning (e.g. in lv_cont layout)*/ 177 LV_PROTECT_FOLLOW = 0x08, /**< Prevent the object be followed in automatic ordering (e.g. in 178 lv_cont PRETTY layout)*/ 179 LV_PROTECT_PRESS_LOST = 0x10, /**< If the `indev` was pressing this object but swiped out while 180 pressing do not search other object.*/ 181 LV_PROTECT_CLICK_FOCUS = 0x20, /**< Prevent focusing the object by clicking on it*/ 182 }; 183 typedef uint8_t lv_protect_t; 184 185 enum { 186 LV_STATE_DEFAULT = 0x00, 187 LV_STATE_CHECKED = 0x01, 188 LV_STATE_FOCUSED = 0x02, 189 LV_STATE_EDITED = 0x04, 190 LV_STATE_HOVERED = 0x08, 191 LV_STATE_PRESSED = 0x10, 192 LV_STATE_DISABLED = 0x20, 193 }; 194 195 typedef uint8_t lv_state_t; 196 197 typedef struct _lv_obj_t { 198 struct _lv_obj_t * parent; /**< Pointer to the parent object*/ 199 lv_ll_t child_ll; /**< Linked list to store the children objects*/ 200 201 lv_area_t coords; /**< Coordinates of the object (x1, y1, x2, y2)*/ 202 203 lv_event_cb_t event_cb; /**< Event callback function */ 204 lv_signal_cb_t signal_cb; /**< Object type specific signal function*/ 205 lv_design_cb_t design_cb; /**< Object type specific design function*/ 206 207 void * ext_attr; /**< Object type specific extended data*/ 208 lv_style_list_t style_list; 209 210 #if LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_TINY 211 uint8_t ext_click_pad_hor; /**< Extra click padding in horizontal direction */ 212 uint8_t ext_click_pad_ver; /**< Extra click padding in vertical direction */ 213 #elif LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_FULL 214 lv_area_t ext_click_pad; /**< Extra click padding area. */ 215 #endif 216 217 lv_coord_t ext_draw_pad; /**< EXTend the size in every direction for drawing. */ 218 219 /*Attributes and states*/ 220 uint8_t click : 1; /**< 1: Can be pressed by an input device*/ 221 uint8_t drag : 1; /**< 1: Enable the dragging*/ 222 uint8_t drag_throw : 1; /**< 1: Enable throwing with drag*/ 223 uint8_t drag_parent : 1; /**< 1: Parent will be dragged instead*/ 224 uint8_t hidden : 1; /**< 1: Object is hidden*/ 225 uint8_t top : 1; /**< 1: If the object or its children is clicked it goes to the foreground*/ 226 uint8_t parent_event : 1; /**< 1: Send the object's events to the parent too. */ 227 uint8_t adv_hittest : 1; /**< 1: Use advanced hit-testing (slower) */ 228 uint8_t gesture_parent : 1; /**< 1: Parent will be gesture instead*/ 229 uint8_t focus_parent : 1; /**< 1: Parent will be focused instead*/ 230 231 lv_drag_dir_t drag_dir : 3; /**< Which directions the object can be dragged in */ 232 lv_bidi_dir_t base_dir : 2; /**< Base direction of texts related to this object */ 233 234 #if LV_USE_GROUP != 0 235 void * group_p; 236 #endif 237 238 uint8_t protect; /**< Automatically happening actions can be prevented. 239 'OR'ed values from `lv_protect_t`*/ 240 lv_state_t state; 241 242 #if LV_USE_OBJ_REALIGN 243 lv_realign_t realign; /**< Information about the last call to ::lv_obj_align. */ 244 #endif 245 246 #if LV_USE_USER_DATA 247 lv_obj_user_data_t user_data; /**< Custom user data for object. */ 248 #endif 249 250 } lv_obj_t; 251 252 enum { 253 LV_OBJ_PART_MAIN, 254 _LV_OBJ_PART_VIRTUAL_LAST = _LV_OBJ_PART_VIRTUAL_FIRST, 255 _LV_OBJ_PART_REAL_LAST = _LV_OBJ_PART_REAL_FIRST, 256 LV_OBJ_PART_ALL = 0xFF, 257 }; 258 259 typedef uint8_t lv_obj_part_t; 260 261 /** Used by `lv_obj_get_type()`. The object's and its ancestor types are stored here*/ 262 typedef struct { 263 const char * type[LV_MAX_ANCESTOR_NUM]; /**< [0]: the actual type, [1]: ancestor, [2] #1's ancestor 264 ... [x]: "lv_obj" */ 265 } lv_obj_type_t; 266 267 typedef struct { 268 lv_point_t * point; 269 bool result; 270 } lv_hit_test_info_t; 271 272 typedef struct { 273 uint8_t part; 274 lv_style_list_t * result; 275 } lv_get_style_info_t; 276 277 typedef struct { 278 uint8_t part; 279 lv_state_t result; 280 } lv_get_state_info_t; 281 282 /********************** 283 * GLOBAL PROTOTYPES 284 **********************/ 285 286 /** 287 * Init. the 'lv' library. 288 */ 289 void lv_init(void); 290 291 292 /** 293 * Deinit the 'lv' library 294 * Currently only implemented when not using custom allocators, or GC is enabled. 295 */ 296 #if LV_ENABLE_GC || !LV_MEM_CUSTOM 297 void lv_deinit(void); 298 #endif 299 300 /*-------------------- 301 * Create and delete 302 *-------------------*/ 303 304 /** 305 * Create a basic object 306 * @param parent pointer to a parent object. 307 * If NULL then a screen will be created 308 * @param copy pointer to a base object, if not NULL then the new object will be copied from it 309 * @return pointer to the new object 310 */ 311 lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy); 312 313 /** 314 * Delete 'obj' and all of its children 315 * @param obj pointer to an object to delete 316 * @return LV_RES_INV because the object is deleted 317 */ 318 lv_res_t lv_obj_del(lv_obj_t * obj); 319 320 #if LV_USE_ANIMATION 321 /** 322 * A function to be easily used in animation ready callback to delete an object when the animation is ready 323 * @param a pointer to the animation 324 */ 325 void lv_obj_del_anim_ready_cb(lv_anim_t * a); 326 #endif 327 328 /** 329 * Helper function for asynchronously deleting objects. 330 * Useful for cases where you can't delete an object directly in an `LV_EVENT_DELETE` handler (i.e. parent). 331 * @param obj object to delete 332 * @see lv_async_call 333 */ 334 void lv_obj_del_async(struct _lv_obj_t * obj); 335 336 /** 337 * Delete all children of an object 338 * @param obj pointer to an object 339 */ 340 void lv_obj_clean(lv_obj_t * obj); 341 342 343 /** 344 * Mark an area of an object as invalid. 345 * This area will be redrawn by 'lv_refr_task' 346 * @param obj pointer to an object 347 * @param area the area to redraw 348 */ 349 void lv_obj_invalidate_area(const lv_obj_t * obj, const lv_area_t * area); 350 351 /** 352 * Mark the object as invalid therefore its current position will be redrawn by 'lv_refr_task' 353 * @param obj pointer to an object 354 */ 355 void lv_obj_invalidate(const lv_obj_t * obj); 356 357 358 /** 359 * Tell whether an area of an object is visible (even partially) now or not 360 * @param obj pointer to an object 361 * @param area the are to check. The visible part of the area will be written back here. 362 * @return true: visible; false: not visible (hidden, out of parent, on other screen, etc) 363 */ 364 bool lv_obj_area_is_visible(const lv_obj_t * obj, lv_area_t * area); 365 366 /** 367 * Tell whether an object is visible (even partially) now or not 368 * @param obj pointer to an object 369 * @return true: visible; false: not visible (hidden, out of parent, on other screen, etc) 370 */ 371 bool lv_obj_is_visible(const lv_obj_t * obj); 372 373 /*===================== 374 * Setter functions 375 *====================*/ 376 377 /*-------------------- 378 * Parent/children set 379 *--------------------*/ 380 381 /** 382 * Set a new parent for an object. Its relative position will be the same. 383 * @param obj pointer to an object. Can't be a screen. 384 * @param parent pointer to the new parent object. (Can't be NULL) 385 */ 386 void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent); 387 388 /** 389 * Move and object to the foreground 390 * @param obj pointer to an object 391 */ 392 void lv_obj_move_foreground(lv_obj_t * obj); 393 394 /** 395 * Move and object to the background 396 * @param obj pointer to an object 397 */ 398 void lv_obj_move_background(lv_obj_t * obj); 399 400 /*-------------------- 401 * Coordinate set 402 * ------------------*/ 403 404 /** 405 * Set relative the position of an object (relative to the parent) 406 * @param obj pointer to an object 407 * @param x new distance from the left side of the parent 408 * @param y new distance from the top of the parent 409 */ 410 void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y); 411 412 /** 413 * Set the x coordinate of a object 414 * @param obj pointer to an object 415 * @param x new distance from the left side from the parent 416 */ 417 void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x); 418 419 /** 420 * Set the y coordinate of a object 421 * @param obj pointer to an object 422 * @param y new distance from the top of the parent 423 */ 424 void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y); 425 426 /** 427 * Set the size of an object 428 * @param obj pointer to an object 429 * @param w new width 430 * @param h new height 431 */ 432 void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); 433 434 /** 435 * Set the width of an object 436 * @param obj pointer to an object 437 * @param w new width 438 */ 439 void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w); 440 441 /** 442 * Set the height of an object 443 * @param obj pointer to an object 444 * @param h new height 445 */ 446 void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h); 447 448 /** 449 * Set the width reduced by the left and right padding. 450 * @param obj pointer to an object 451 * @param w the width without paddings 452 */ 453 void lv_obj_set_width_fit(lv_obj_t * obj, lv_coord_t w); 454 455 /** 456 * Set the height reduced by the top and bottom padding. 457 * @param obj pointer to an object 458 * @param h the height without paddings 459 */ 460 void lv_obj_set_height_fit(lv_obj_t * obj, lv_coord_t h); 461 462 /** 463 * Set the width of an object by taking the left and right margin into account. 464 * The object width will be `obj_w = w - margin_left - margin_right` 465 * @param obj pointer to an object 466 * @param w new height including margins 467 */ 468 void lv_obj_set_width_margin(lv_obj_t * obj, lv_coord_t w); 469 470 /** 471 * Set the height of an object by taking the top and bottom margin into account. 472 * The object height will be `obj_h = h - margin_top - margin_bottom` 473 * @param obj pointer to an object 474 * @param h new height including margins 475 */ 476 void lv_obj_set_height_margin(lv_obj_t * obj, lv_coord_t h); 477 478 /** 479 * Align an object to an other object. 480 * @param obj pointer to an object to align 481 * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. 482 * @param align type of alignment (see 'lv_align_t' enum) 483 * @param x_ofs x coordinate offset after alignment 484 * @param y_ofs y coordinate offset after alignment 485 */ 486 void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs); 487 488 /** 489 * Align an object to an other object horizontally. 490 * @param obj pointer to an object to align 491 * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. 492 * @param align type of alignment (see 'lv_align_t' enum) 493 * @param x_ofs x coordinate offset after alignment 494 */ 495 void lv_obj_align_x(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs); 496 497 /** 498 * Align an object to an other object vertically. 499 * @param obj pointer to an object to align 500 * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. 501 * @param align type of alignment (see 'lv_align_t' enum) 502 * @param y_ofs y coordinate offset after alignment 503 */ 504 void lv_obj_align_y(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t y_ofs); 505 506 /** 507 * Align an object to an other object. 508 * @param obj pointer to an object to align 509 * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. 510 * @param align type of alignment (see 'lv_align_t' enum) 511 * @param x_ofs x coordinate offset after alignment 512 * @param y_ofs y coordinate offset after alignment 513 */ 514 void lv_obj_align_mid(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs); 515 516 517 /** 518 * Align an object's middle point to an other object horizontally. 519 * @param obj pointer to an object to align 520 * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. 521 * @param align type of alignment (see 'lv_align_t' enum) 522 * @param x_ofs x coordinate offset after alignment 523 */ 524 void lv_obj_align_mid_x(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs); 525 526 /** 527 * Align an object's middle point to an other object vertically. 528 * @param obj pointer to an object to align 529 * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. 530 * @param align type of alignment (see 'lv_align_t' enum) 531 * @param y_ofs y coordinate offset after alignment 532 */ 533 void lv_obj_align_mid_y(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t y_ofs); 534 535 /** 536 * Realign the object based on the last `lv_obj_align` parameters. 537 * @param obj pointer to an object 538 */ 539 void lv_obj_realign(lv_obj_t * obj); 540 541 /** 542 * Enable the automatic realign of the object when its size has changed based on the last 543 * `lv_obj_align` parameters. 544 * @param obj pointer to an object 545 * @param en true: enable auto realign; false: disable auto realign 546 */ 547 void lv_obj_set_auto_realign(lv_obj_t * obj, bool en); 548 549 /** 550 * Set the size of an extended clickable area 551 * @param obj pointer to an object 552 * @param left extended clickable are on the left [px] 553 * @param right extended clickable are on the right [px] 554 * @param top extended clickable are on the top [px] 555 * @param bottom extended clickable are on the bottom [px] 556 */ 557 void lv_obj_set_ext_click_area(lv_obj_t * obj, lv_coord_t left, lv_coord_t right, lv_coord_t top, lv_coord_t bottom); 558 559 /*--------------------- 560 * Appearance set 561 *--------------------*/ 562 563 /** 564 * Add a new style to the style list of an object. 565 * @param obj pointer to an object 566 * @param part the part of the object which style property should be set. 567 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 568 * @param style pointer to a style to add (Only its pointer will be saved) 569 */ 570 void lv_obj_add_style(lv_obj_t * obj, uint8_t part, lv_style_t * style); 571 572 /** 573 * Remove a style from the style list of an object. 574 * @param obj pointer to an object 575 * @param part the part of the object which style property should be set. 576 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 577 * @param style pointer to a style to remove 578 */ 579 void lv_obj_remove_style(lv_obj_t * obj, uint8_t part, lv_style_t * style); 580 581 /** 582 * Reset a style to the default (empty) state. 583 * Release all used memories and cancel pending related transitions. 584 * Typically used in `LV_SIGN_CLEAN_UP. 585 * @param obj pointer to an object 586 * @param part the part of the object which style list should be reseted. 587 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 588 */ 589 void lv_obj_clean_style_list(lv_obj_t * obj, uint8_t part); 590 591 /** 592 * Reset a style to the default (empty) state. 593 * Release all used memories and cancel pending related transitions. 594 * Also notifies the object about the style change. 595 * @param obj pointer to an object 596 * @param part the part of the object which style list should be reseted. 597 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 598 */ 599 void lv_obj_reset_style_list(lv_obj_t * obj, uint8_t part); 600 601 /** 602 * Notify an object (and its children) about its style is modified 603 * @param obj pointer to an object 604 * @param prop `LV_STYLE_PROP_ALL` or an `LV_STYLE_...` property. It is used to optimize what needs to be refreshed. 605 */ 606 void lv_obj_refresh_style(lv_obj_t * obj, uint8_t part, lv_style_property_t prop); 607 608 /** 609 * Notify all object if a style is modified 610 * @param style pointer to a style. Only the objects with this style will be notified 611 * (NULL to notify all objects) 612 */ 613 void lv_obj_report_style_mod(lv_style_t * style); 614 615 /** 616 * Set a local style property of a part of an object in a given state. 617 * @param obj pointer to an object 618 * @param part the part of the object which style property should be set. 619 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 620 * @param prop a style property ORed with a state. 621 * E.g. `LV_STYLE_BORDER_COLOR | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` 622 * @param the value to set 623 * @note shouldn't be used directly. Use the specific property get functions instead. 624 * For example: `lv_obj_style_get_border_opa()` 625 * @note for performance reasons it's not checked if the property really has color type 626 */ 627 void _lv_obj_set_style_local_color(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, lv_color_t color); 628 629 /** 630 * Set a local style property of a part of an object in a given state. 631 * @param obj pointer to an object 632 * @param part the part of the object which style property should be set. 633 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 634 * @param prop a style property ORed with a state. 635 * E.g. `LV_STYLE_BORDER_WIDTH | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` 636 * @param the value to set 637 * @note shouldn't be used directly. Use the specific property get functions instead. 638 * For example: `lv_obj_style_get_border_opa()` 639 * @note for performance reasons it's not checked if the property really has integer type 640 */ 641 void _lv_obj_set_style_local_int(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, lv_style_int_t value); 642 643 /** 644 * Set a local style property of a part of an object in a given state. 645 * @param obj pointer to an object 646 * @param part the part of the object which style property should be set. 647 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 648 * @param prop a style property ORed with a state. 649 * E.g. `LV_STYLE_BORDER_OPA | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` 650 * @param the value to set 651 * @note shouldn't be used directly. Use the specific property get functions instead. 652 * For example: `lv_obj_style_get_border_opa()` 653 * @note for performance reasons it's not checked if the property really has opacity type 654 */ 655 void _lv_obj_set_style_local_opa(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, lv_opa_t opa); 656 657 /** 658 * Set a local style property of a part of an object in a given state. 659 * @param obj pointer to an object 660 * @param part the part of the object which style property should be set. 661 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 662 * @param prop a style property ORed with a state. 663 * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` 664 * @param the value to set 665 * @note shouldn't be used directly. Use the specific property get functions instead. 666 * For example: `lv_obj_style_get_border_opa()` 667 * @note for performance reasons it's not checked if the property really has pointer type 668 */ 669 void _lv_obj_set_style_local_ptr(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, const void * value); 670 671 /** 672 * Remove a local style property from a part of an object with a given state. 673 * @param obj pointer to an object 674 * @param part the part of the object which style property should be removed. 675 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 676 * @param prop a style property ORed with a state. 677 * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` 678 * @note shouldn't be used directly. Use the specific property remove functions instead. 679 * For example: `lv_obj_style_remove_border_opa()` 680 * @return true: the property was found and removed; false: the property was not found 681 */ 682 bool lv_obj_remove_style_local_prop(lv_obj_t * obj, uint8_t part, lv_style_property_t prop); 683 684 /** 685 * Enable/disable the use of style cahche for an object 686 * @param obj pointer to an object 687 * @param dis true: disable; false: enable (re-enable) 688 */ 689 void _lv_obj_disable_style_caching(lv_obj_t * obj, bool dis); 690 691 /*----------------- 692 * Attribute set 693 *----------------*/ 694 695 /** 696 * Hide an object. It won't be visible and clickable. 697 * @param obj pointer to an object 698 * @param en true: hide the object 699 */ 700 void lv_obj_set_hidden(lv_obj_t * obj, bool en); 701 702 /** 703 * Set whether advanced hit-testing is enabled on an object 704 * @param obj pointer to an object 705 * @param en true: advanced hit-testing is enabled 706 */ 707 void lv_obj_set_adv_hittest(lv_obj_t * obj, bool en); 708 709 /** 710 * Enable or disable the clicking of an object 711 * @param obj pointer to an object 712 * @param en true: make the object clickable 713 */ 714 void lv_obj_set_click(lv_obj_t * obj, bool en); 715 716 /** 717 * Enable to bring this object to the foreground if it 718 * or any of its children is clicked 719 * @param obj pointer to an object 720 * @param en true: enable the auto top feature 721 */ 722 void lv_obj_set_top(lv_obj_t * obj, bool en); 723 724 /** 725 * Enable the dragging of an object 726 * @param obj pointer to an object 727 * @param en true: make the object draggable 728 */ 729 void lv_obj_set_drag(lv_obj_t * obj, bool en); 730 731 /** 732 * Set the directions an object can be dragged in 733 * @param obj pointer to an object 734 * @param drag_dir bitwise OR of allowed drag directions 735 */ 736 void lv_obj_set_drag_dir(lv_obj_t * obj, lv_drag_dir_t drag_dir); 737 738 /** 739 * Enable the throwing of an object after is is dragged 740 * @param obj pointer to an object 741 * @param en true: enable the drag throw 742 */ 743 void lv_obj_set_drag_throw(lv_obj_t * obj, bool en); 744 745 /** 746 * Enable to use parent for drag related operations. 747 * If trying to drag the object the parent will be moved instead 748 * @param obj pointer to an object 749 * @param en true: enable the 'drag parent' for the object 750 */ 751 void lv_obj_set_drag_parent(lv_obj_t * obj, bool en); 752 753 /** 754 * Enable to use parent for focus state. 755 * When object is focused the parent will get the state instead (visual only) 756 * @param obj pointer to an object 757 * @param en true: enable the 'focus parent' for the object 758 */ 759 void lv_obj_set_focus_parent(lv_obj_t * obj, bool en); 760 761 /** 762 * Enable to use parent for gesture related operations. 763 * If trying to gesture the object the parent will be moved instead 764 * @param obj pointer to an object 765 * @param en true: enable the 'gesture parent' for the object 766 */ 767 void lv_obj_set_gesture_parent(lv_obj_t * obj, bool en); 768 769 /** 770 * Propagate the events to the parent too 771 * @param obj pointer to an object 772 * @param en true: enable the event propagation 773 */ 774 void lv_obj_set_parent_event(lv_obj_t * obj, bool en); 775 776 /** 777 * Set the base direction of the object 778 * @param obj pointer to an object 779 * @param dir the new base direction. `LV_BIDI_DIR_LTR/RTL/AUTO/INHERIT` 780 */ 781 void lv_obj_set_base_dir(lv_obj_t * obj, lv_bidi_dir_t dir); 782 783 /** 784 * Set a bit or bits in the protect filed 785 * @param obj pointer to an object 786 * @param prot 'OR'-ed values from `lv_protect_t` 787 */ 788 void lv_obj_add_protect(lv_obj_t * obj, uint8_t prot); 789 790 /** 791 * Clear a bit or bits in the protect filed 792 * @param obj pointer to an object 793 * @param prot 'OR'-ed values from `lv_protect_t` 794 */ 795 void lv_obj_clear_protect(lv_obj_t * obj, uint8_t prot); 796 797 /** 798 * Set the state (fully overwrite) of an object. 799 * If specified in the styles a transition animation will be started 800 * from the previous state to the current 801 * @param obj pointer to an object 802 * @param state the new state 803 */ 804 void lv_obj_set_state(lv_obj_t * obj, lv_state_t state); 805 806 /** 807 * Add a given state or states to the object. The other state bits will remain unchanged. 808 * If specified in the styles a transition animation will be started 809 * from the previous state to the current 810 * @param obj pointer to an object 811 * @param state the state bits to add. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED` 812 */ 813 void lv_obj_add_state(lv_obj_t * obj, lv_state_t state); 814 815 /** 816 * Remove a given state or states to the object. The other state bits will remain unchanged. 817 * If specified in the styles a transition animation will be started 818 * from the previous state to the current 819 * @param obj pointer to an object 820 * @param state the state bits to remove. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED` 821 */ 822 void lv_obj_clear_state(lv_obj_t * obj, lv_state_t state); 823 824 #if LV_USE_ANIMATION 825 /** 826 * Finish all pending transitions on a part of an object 827 * @param obj pointer to an object 828 * @param part part of the object, e.g `LV_BRN_PART_MAIN` or `LV_OBJ_PART_ALL` for all parts 829 */ 830 void lv_obj_finish_transitions(lv_obj_t * obj, uint8_t part); 831 #endif 832 833 /** 834 * Set a an event handler function for an object. 835 * Used by the user to react on event which happens with the object. 836 * @param obj pointer to an object 837 * @param event_cb the new event function 838 */ 839 void lv_obj_set_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb); 840 841 /** 842 * Send an event to the object 843 * @param obj pointer to an object 844 * @param event the type of the event from `lv_event_t`. 845 * @param data arbitrary data depending on the object type and the event. (Usually `NULL`) 846 * @return LV_RES_OK: `obj` was not deleted in the event; LV_RES_INV: `obj` was deleted in the event 847 */ 848 lv_res_t lv_event_send(lv_obj_t * obj, lv_event_t event, const void * data); 849 850 851 /** 852 * Send LV_EVENT_REFRESH event to an object 853 * @param obj point to an obejct. (Can NOT be NULL) 854 * @return LV_RES_OK: success, LV_RES_INV: to object become invalid (e.g. deleted) due to this event. 855 */ 856 lv_res_t lv_event_send_refresh(lv_obj_t * obj); 857 858 /** 859 * Send LV_EVENT_REFRESH event to an object and all of its children 860 * @param obj pointer to an object or NULL to refresh all objects of all displays 861 */ 862 void lv_event_send_refresh_recursive(lv_obj_t * obj); 863 864 /** 865 * Call an event function with an object, event, and data. 866 * @param event_xcb an event callback function. If `NULL` `LV_RES_OK` will return without any actions. 867 * (the 'x' in the argument name indicates that its not a fully generic function because it not follows 868 * the `func_name(object, callback, ...)` convention) 869 * @param obj pointer to an object to associate with the event (can be `NULL` to simply call the `event_cb`) 870 * @param event an event 871 * @param data pointer to a custom data 872 * @return LV_RES_OK: `obj` was not deleted in the event; LV_RES_INV: `obj` was deleted in the event 873 */ 874 lv_res_t lv_event_send_func(lv_event_cb_t event_xcb, lv_obj_t * obj, lv_event_t event, const void * data); 875 876 /** 877 * Get the `data` parameter of the current event 878 * @return the `data` parameter 879 */ 880 const void * lv_event_get_data(void); 881 882 /** 883 * Set the a signal function of an object. Used internally by the library. 884 * Always call the previous signal function in the new. 885 * @param obj pointer to an object 886 * @param signal_cb the new signal function 887 */ 888 void lv_obj_set_signal_cb(lv_obj_t * obj, lv_signal_cb_t signal_cb); 889 890 891 /** 892 * Send an event to the object 893 * @param obj pointer to an object 894 * @param event the type of the event from `lv_event_t`. 895 * @return LV_RES_OK or LV_RES_INV 896 */ 897 lv_res_t lv_signal_send(lv_obj_t * obj, lv_signal_t signal, void * param); 898 899 /** 900 * Set a new design function for an object 901 * @param obj pointer to an object 902 * @param design_cb the new design function 903 */ 904 void lv_obj_set_design_cb(lv_obj_t * obj, lv_design_cb_t design_cb); 905 906 /*---------------- 907 * Other set 908 *--------------*/ 909 910 /** 911 * Allocate a new ext. data for an object 912 * @param obj pointer to an object 913 * @param ext_size the size of the new ext. data 914 * @return pointer to the allocated ext 915 */ 916 void * lv_obj_allocate_ext_attr(lv_obj_t * obj, uint16_t ext_size); 917 918 /** 919 * Send a 'LV_SIGNAL_REFR_EXT_SIZE' signal to the object to refresh the extended draw area. 920 * he object needs to be invalidated by `lv_obj_invalidate(obj)` manually after this function. 921 * @param obj pointer to an object 922 */ 923 void lv_obj_refresh_ext_draw_pad(lv_obj_t * obj); 924 925 /*======================= 926 * Getter functions 927 *======================*/ 928 929 /** 930 * Return with the screen of an object 931 * @param obj pointer to an object 932 * @return pointer to a screen 933 */ 934 lv_obj_t * lv_obj_get_screen(const lv_obj_t * obj); 935 936 /** 937 * Get the display of an object 938 * @return pointer the object's display 939 */ 940 lv_disp_t * lv_obj_get_disp(const lv_obj_t * obj); 941 942 /*--------------------- 943 * Parent/children get 944 *--------------------*/ 945 946 /** 947 * Returns with the parent of an object 948 * @param obj pointer to an object 949 * @return pointer to the parent of 'obj' 950 */ 951 lv_obj_t * lv_obj_get_parent(const lv_obj_t * obj); 952 953 /** 954 * Iterate through the children of an object (start from the "youngest, lastly created") 955 * @param obj pointer to an object 956 * @param child NULL at first call to get the next children 957 * and the previous return value later 958 * @return the child after 'act_child' or NULL if no more child 959 */ 960 lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, const lv_obj_t * child); 961 962 /** 963 * Iterate through the children of an object (start from the "oldest", firstly created) 964 * @param obj pointer to an object 965 * @param child NULL at first call to get the next children 966 * and the previous return value later 967 * @return the child after 'act_child' or NULL if no more child 968 */ 969 lv_obj_t * lv_obj_get_child_back(const lv_obj_t * obj, const lv_obj_t * child); 970 971 /** 972 * Count the children of an object (only children directly on 'obj') 973 * @param obj pointer to an object 974 * @return children number of 'obj' 975 */ 976 uint16_t lv_obj_count_children(const lv_obj_t * obj); 977 978 /** Recursively count the children of an object 979 * @param obj pointer to an object 980 * @return children number of 'obj' 981 */ 982 uint16_t lv_obj_count_children_recursive(const lv_obj_t * obj); 983 984 /*--------------------- 985 * Coordinate get 986 *--------------------*/ 987 988 /** 989 * Copy the coordinates of an object to an area 990 * @param obj pointer to an object 991 * @param cords_p pointer to an area to store the coordinates 992 */ 993 void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p); 994 995 /** 996 * Reduce area retried by `lv_obj_get_coords()` the get graphically usable area of an object. 997 * (Without the size of the border or other extra graphical elements) 998 * @param coords_p store the result area here 999 */ 1000 void lv_obj_get_inner_coords(const lv_obj_t * obj, lv_area_t * coords_p); 1001 1002 /** 1003 * Get the x coordinate of object 1004 * @param obj pointer to an object 1005 * @return distance of 'obj' from the left side of its parent 1006 */ 1007 lv_coord_t lv_obj_get_x(const lv_obj_t * obj); 1008 1009 /** 1010 * Get the y coordinate of object 1011 * @param obj pointer to an object 1012 * @return distance of 'obj' from the top of its parent 1013 */ 1014 lv_coord_t lv_obj_get_y(const lv_obj_t * obj); 1015 1016 /** 1017 * Get the width of an object 1018 * @param obj pointer to an object 1019 * @return the width 1020 */ 1021 lv_coord_t lv_obj_get_width(const lv_obj_t * obj); 1022 1023 /** 1024 * Get the height of an object 1025 * @param obj pointer to an object 1026 * @return the height 1027 */ 1028 lv_coord_t lv_obj_get_height(const lv_obj_t * obj); 1029 1030 /** 1031 * Get that width reduced by the left and right padding. 1032 * @param obj pointer to an object 1033 * @return the width which still fits into the container 1034 */ 1035 lv_coord_t lv_obj_get_width_fit(const lv_obj_t * obj); 1036 1037 /** 1038 * Get that height reduced by the top an bottom padding. 1039 * @param obj pointer to an object 1040 * @return the height which still fits into the container 1041 */ 1042 lv_coord_t lv_obj_get_height_fit(const lv_obj_t * obj); 1043 1044 /** 1045 * Get the height of an object by taking the top and bottom margin into account. 1046 * The returned height will be `obj_h + margin_top + margin_bottom` 1047 * @param obj pointer to an object 1048 * @return the height including thee margins 1049 */ 1050 lv_coord_t lv_obj_get_height_margin(lv_obj_t * obj); 1051 1052 /** 1053 * Get the width of an object by taking the left and right margin into account. 1054 * The returned width will be `obj_w + margin_left + margin_right` 1055 * @param obj pointer to an object 1056 * @return the height including thee margins 1057 */ 1058 lv_coord_t lv_obj_get_width_margin(lv_obj_t * obj); 1059 1060 /** 1061 * Divide the width of the object and get the width of a given number of columns. 1062 * Take paddings into account. 1063 * @param obj pointer to an object 1064 * @param div indicates how many columns are assumed. 1065 * If 1 the width will be set the the parent's width 1066 * If 2 only half parent width - inner padding of the parent 1067 * If 3 only third parent width - 2 * inner padding of the parent 1068 * @param span how many columns are combined 1069 * @return the width according to the given parameters 1070 */ 1071 lv_coord_t lv_obj_get_width_grid(lv_obj_t * obj, uint8_t div, uint8_t span); 1072 1073 /** 1074 * Divide the height of the object and get the width of a given number of columns. 1075 * Take paddings into account. 1076 * @param obj pointer to an object 1077 * @param div indicates how many rows are assumed. 1078 * If 1 the height will be set the the parent's height 1079 * If 2 only half parent height - inner padding of the parent 1080 * If 3 only third parent height - 2 * inner padding of the parent 1081 * @param span how many rows are combined 1082 * @return the height according to the given parameters 1083 */ 1084 lv_coord_t lv_obj_get_height_grid(lv_obj_t * obj, uint8_t div, uint8_t span); 1085 1086 /** 1087 * Get the automatic realign property of the object. 1088 * @param obj pointer to an object 1089 * @return true: auto realign is enabled; false: auto realign is disabled 1090 */ 1091 bool lv_obj_get_auto_realign(const lv_obj_t * obj); 1092 1093 /** 1094 * Get the left padding of extended clickable area 1095 * @param obj pointer to an object 1096 * @return the extended left padding 1097 */ 1098 lv_coord_t lv_obj_get_ext_click_pad_left(const lv_obj_t * obj); 1099 1100 /** 1101 * Get the right padding of extended clickable area 1102 * @param obj pointer to an object 1103 * @return the extended right padding 1104 */ 1105 lv_coord_t lv_obj_get_ext_click_pad_right(const lv_obj_t * obj); 1106 1107 /** 1108 * Get the top padding of extended clickable area 1109 * @param obj pointer to an object 1110 * @return the extended top padding 1111 */ 1112 lv_coord_t lv_obj_get_ext_click_pad_top(const lv_obj_t * obj); 1113 1114 /** 1115 * Get the bottom padding of extended clickable area 1116 * @param obj pointer to an object 1117 * @return the extended bottom padding 1118 */ 1119 lv_coord_t lv_obj_get_ext_click_pad_bottom(const lv_obj_t * obj); 1120 1121 /** 1122 * Get the extended size attribute of an object 1123 * @param obj pointer to an object 1124 * @return the extended size attribute 1125 */ 1126 lv_coord_t lv_obj_get_ext_draw_pad(const lv_obj_t * obj); 1127 1128 /*----------------- 1129 * Appearance get 1130 *---------------*/ 1131 1132 /** 1133 * Get the style list of an object's part. 1134 * @param obj pointer to an object. 1135 * @param part part the part of the object which style list should be get. 1136 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 1137 * @return pointer to the style list. (Can be `NULL`) 1138 */ 1139 lv_style_list_t * lv_obj_get_style_list(const lv_obj_t * obj, uint8_t part); 1140 1141 /** 1142 * Get a style property of a part of an object in the object's current state. 1143 * If there is a running transitions it is taken into account 1144 * @param obj pointer to an object 1145 * @param part the part of the object which style property should be get. 1146 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 1147 * @param prop the property to get. E.g. `LV_STYLE_BORDER_WIDTH`. 1148 * The state of the object will be added internally 1149 * @return the value of the property of the given part in the current state. 1150 * If the property is not found a default value will be returned. 1151 * @note shouldn't be used directly. Use the specific property get functions instead. 1152 * For example: `lv_obj_style_get_border_width()` 1153 * @note for performance reasons it's not checked if the property really has integer type 1154 */ 1155 lv_style_int_t _lv_obj_get_style_int(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop); 1156 1157 /** 1158 * Get a style property of a part of an object in the object's current state. 1159 * If there is a running transitions it is taken into account 1160 * @param obj pointer to an object 1161 * @param part the part of the object which style property should be get. 1162 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 1163 * @param prop the property to get. E.g. `LV_STYLE_BORDER_COLOR`. 1164 * The state of the object will be added internally 1165 * @return the value of the property of the given part in the current state. 1166 * If the property is not found a default value will be returned. 1167 * @note shouldn't be used directly. Use the specific property get functions instead. 1168 * For example: `lv_obj_style_get_border_color()` 1169 * @note for performance reasons it's not checked if the property really has color type 1170 */ 1171 lv_color_t _lv_obj_get_style_color(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop); 1172 1173 /** 1174 * Get a style property of a part of an object in the object's current state. 1175 * If there is a running transitions it is taken into account 1176 * @param obj pointer to an object 1177 * @param part the part of the object which style property should be get. 1178 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 1179 * @param prop the property to get. E.g. `LV_STYLE_BORDER_OPA`. 1180 * The state of the object will be added internally 1181 * @return the value of the property of the given part in the current state. 1182 * If the property is not found a default value will be returned. 1183 * @note shouldn't be used directly. Use the specific property get functions instead. 1184 * For example: `lv_obj_style_get_border_opa()` 1185 * @note for performance reasons it's not checked if the property really has opacity type 1186 */ 1187 lv_opa_t _lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop); 1188 1189 /** 1190 * Get a style property of a part of an object in the object's current state. 1191 * If there is a running transitions it is taken into account 1192 * @param obj pointer to an object 1193 * @param part the part of the object which style property should be get. 1194 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 1195 * @param prop the property to get. E.g. `LV_STYLE_TEXT_FONT`. 1196 * The state of the object will be added internally 1197 * @return the value of the property of the given part in the current state. 1198 * If the property is not found a default value will be returned. 1199 * @note shouldn't be used directly. Use the specific property get functions instead. 1200 * For example: `lv_obj_style_get_border_opa()` 1201 * @note for performance reasons it's not checked if the property really has pointer type 1202 */ 1203 const void * _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop); 1204 1205 /** 1206 * Get the local style of a part of an object. 1207 * @param obj pointer to an object 1208 * @param part the part of the object which style property should be set. 1209 * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` 1210 * @return pointer to the local style if exists else `NULL`. 1211 */ 1212 lv_style_t * lv_obj_get_local_style(lv_obj_t * obj, uint8_t part); 1213 1214 1215 #include "lv_obj_style_dec.h" 1216 1217 /*----------------- 1218 * Attribute get 1219 *----------------*/ 1220 1221 /** 1222 * Get the hidden attribute of an object 1223 * @param obj pointer to an object 1224 * @return true: the object is hidden 1225 */ 1226 bool lv_obj_get_hidden(const lv_obj_t * obj); 1227 1228 /** 1229 * Get whether advanced hit-testing is enabled on an object 1230 * @param obj pointer to an object 1231 * @return true: advanced hit-testing is enabled 1232 */ 1233 bool lv_obj_get_adv_hittest(const lv_obj_t * obj); 1234 1235 /** 1236 * Get the click enable attribute of an object 1237 * @param obj pointer to an object 1238 * @return true: the object is clickable 1239 */ 1240 bool lv_obj_get_click(const lv_obj_t * obj); 1241 1242 /** 1243 * Get the top enable attribute of an object 1244 * @param obj pointer to an object 1245 * @return true: the auto top feature is enabled 1246 */ 1247 bool lv_obj_get_top(const lv_obj_t * obj); 1248 1249 /** 1250 * Get the drag enable attribute of an object 1251 * @param obj pointer to an object 1252 * @return true: the object is draggable 1253 */ 1254 bool lv_obj_get_drag(const lv_obj_t * obj); 1255 1256 /** 1257 * Get the directions an object can be dragged 1258 * @param obj pointer to an object 1259 * @return bitwise OR of allowed directions an object can be dragged in 1260 */ 1261 lv_drag_dir_t lv_obj_get_drag_dir(const lv_obj_t * obj); 1262 1263 /** 1264 * Get the drag throw enable attribute of an object 1265 * @param obj pointer to an object 1266 * @return true: drag throw is enabled 1267 */ 1268 bool lv_obj_get_drag_throw(const lv_obj_t * obj); 1269 1270 /** 1271 * Get the drag parent attribute of an object 1272 * @param obj pointer to an object 1273 * @return true: drag parent is enabled 1274 */ 1275 bool lv_obj_get_drag_parent(const lv_obj_t * obj); 1276 1277 1278 /** 1279 * Get the focus parent attribute of an object 1280 * @param obj pointer to an object 1281 * @return true: focus parent is enabled 1282 */ 1283 bool lv_obj_get_focus_parent(const lv_obj_t * obj); 1284 1285 1286 /** 1287 * Get the drag parent attribute of an object 1288 * @param obj pointer to an object 1289 * @return true: drag parent is enabled 1290 */ 1291 bool lv_obj_get_parent_event(const lv_obj_t * obj); 1292 1293 /** 1294 * Get the gesture parent attribute of an object 1295 * @param obj pointer to an object 1296 * @return true: gesture parent is enabled 1297 */ 1298 bool lv_obj_get_gesture_parent(const lv_obj_t * obj); 1299 1300 lv_bidi_dir_t lv_obj_get_base_dir(const lv_obj_t * obj); 1301 1302 /** 1303 * Get the protect field of an object 1304 * @param obj pointer to an object 1305 * @return protect field ('OR'ed values of `lv_protect_t`) 1306 */ 1307 uint8_t lv_obj_get_protect(const lv_obj_t * obj); 1308 1309 /** 1310 * Check at least one bit of a given protect bitfield is set 1311 * @param obj pointer to an object 1312 * @param prot protect bits to test ('OR'ed values of `lv_protect_t`) 1313 * @return false: none of the given bits are set, true: at least one bit is set 1314 */ 1315 bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot); 1316 1317 1318 lv_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part); 1319 1320 /** 1321 * Get the signal function of an object 1322 * @param obj pointer to an object 1323 * @return the signal function 1324 */ 1325 lv_signal_cb_t lv_obj_get_signal_cb(const lv_obj_t * obj); 1326 1327 /** 1328 * Get the design function of an object 1329 * @param obj pointer to an object 1330 * @return the design function 1331 */ 1332 lv_design_cb_t lv_obj_get_design_cb(const lv_obj_t * obj); 1333 1334 /** 1335 * Get the event function of an object 1336 * @param obj pointer to an object 1337 * @return the event function 1338 */ 1339 lv_event_cb_t lv_obj_get_event_cb(const lv_obj_t * obj); 1340 1341 /*------------------ 1342 * Other get 1343 *-----------------*/ 1344 1345 /** 1346 * Check if a given screen-space point is on an object's coordinates. 1347 * 1348 * This method is intended to be used mainly by advanced hit testing algorithms to check 1349 * whether the point is even within the object (as an optimization). 1350 * @param obj object to check 1351 * @param point screen-space point 1352 */ 1353 bool lv_obj_is_point_on_coords(lv_obj_t * obj, const lv_point_t * point); 1354 1355 /** 1356 * Hit-test an object given a particular point in screen space. 1357 * @param obj object to hit-test 1358 * @param point screen-space point 1359 * @return true if the object is considered under the point 1360 */ 1361 bool lv_obj_hittest(lv_obj_t * obj, lv_point_t * point); 1362 1363 /** 1364 * Get the ext pointer 1365 * @param obj pointer to an object 1366 * @return the ext pointer but not the dynamic version 1367 * Use it as ext->data1, and NOT da(ext)->data1 1368 */ 1369 void * lv_obj_get_ext_attr(const lv_obj_t * obj); 1370 1371 /** 1372 * Get object's and its ancestors type. Put their name in `type_buf` starting with the current type. 1373 * E.g. buf.type[0]="lv_btn", buf.type[1]="lv_cont", buf.type[2]="lv_obj" 1374 * @param obj pointer to an object which type should be get 1375 * @param buf pointer to an `lv_obj_type_t` buffer to store the types 1376 */ 1377 void lv_obj_get_type(const lv_obj_t * obj, lv_obj_type_t * buf); 1378 1379 #if LV_USE_USER_DATA 1380 /** 1381 * Get the object's user data 1382 * @param obj pointer to an object 1383 * @return user data 1384 */ 1385 lv_obj_user_data_t lv_obj_get_user_data(const lv_obj_t * obj); 1386 1387 /** 1388 * Get a pointer to the object's user data 1389 * @param obj pointer to an object 1390 * @return pointer to the user data 1391 */ 1392 lv_obj_user_data_t * lv_obj_get_user_data_ptr(const lv_obj_t * obj); 1393 1394 /** 1395 * Set the object's user data. The data will be copied. 1396 * @param obj pointer to an object 1397 * @param data user data 1398 */ 1399 void lv_obj_set_user_data(lv_obj_t * obj, lv_obj_user_data_t data); 1400 1401 #endif 1402 1403 /** 1404 * Get the group of the object 1405 * @param obj pointer to an object 1406 * @return the pointer to group of the object 1407 */ 1408 void * lv_obj_get_group(const lv_obj_t * obj); 1409 1410 /** 1411 * Tell whether the object is the focused object of a group or not. 1412 * @param obj pointer to an object 1413 * @return true: the object is focused, false: the object is not focused or not in a group 1414 */ 1415 bool lv_obj_is_focused(const lv_obj_t * obj); 1416 1417 /** 1418 * Get the really focused object by taking `focus_parent` into account. 1419 * @param obj the start object 1420 * @return the object to really focus 1421 */ 1422 lv_obj_t * lv_obj_get_focused_obj(const lv_obj_t * obj); 1423 1424 /*------------------- 1425 * OTHER FUNCTIONS 1426 *------------------*/ 1427 1428 /** 1429 * Used in the signal callback to handle `LV_SIGNAL_GET_TYPE` signal 1430 * @param buf pointer to `lv_obj_type_t`. (`param` in the signal callback) 1431 * @param name name of the object. E.g. "lv_btn". (Only the pointer is saved) 1432 * @return LV_RES_OK 1433 */ 1434 lv_res_t lv_obj_handle_get_type_signal(lv_obj_type_t * buf, const char * name); 1435 1436 /** 1437 * Initialize a rectangle descriptor from an object's styles 1438 * @param obj pointer to an object 1439 * @param type type of style. E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_SLIDER_KOB` 1440 * @param draw_dsc the descriptor the initialize 1441 * @note Only the relevant fields will be set. 1442 * E.g. if `border width == 0` the other border properties won't be evaluated. 1443 */ 1444 void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t type, lv_draw_rect_dsc_t * draw_dsc); 1445 1446 void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t type, lv_draw_label_dsc_t * draw_dsc); 1447 1448 void lv_obj_init_draw_img_dsc(lv_obj_t * obj, uint8_t part, lv_draw_img_dsc_t * draw_dsc); 1449 1450 void lv_obj_init_draw_line_dsc(lv_obj_t * obj, uint8_t part, lv_draw_line_dsc_t * draw_dsc); 1451 1452 /** 1453 * Get the required extra size (around the object's part) to draw shadow, outline, value etc. 1454 * @param obj pointer to an object 1455 * @param part part of the object 1456 */ 1457 lv_coord_t lv_obj_get_draw_rect_ext_pad_size(lv_obj_t * obj, uint8_t part); 1458 1459 /** 1460 * Fade in (from transparent to fully cover) an object and all its children using an `opa_scale` animation. 1461 * @param obj the object to fade in 1462 * @param time duration of the animation [ms] 1463 * @param delay wait before the animation starts [ms] 1464 */ 1465 void lv_obj_fade_in(lv_obj_t * obj, uint32_t time, uint32_t delay); 1466 1467 /** 1468 * Fade out (from fully cover to transparent) an object and all its children using an `opa_scale` animation. 1469 * @param obj the object to fade in 1470 * @param time duration of the animation [ms] 1471 * @param delay wait before the animation starts [ms] 1472 */ 1473 void lv_obj_fade_out(lv_obj_t * obj, uint32_t time, uint32_t delay); 1474 1475 /** 1476 * Check if any object has a given type 1477 * @param obj pointer to an object 1478 * @param obj_type type of the object. (e.g. "lv_btn") 1479 * @return true: valid 1480 */ 1481 bool lv_debug_check_obj_type(const lv_obj_t * obj, const char * obj_type); 1482 1483 /** 1484 * Check if any object is still "alive", and part of the hierarchy 1485 * @param obj pointer to an object 1486 * @param obj_type type of the object. (e.g. "lv_btn") 1487 * @return true: valid 1488 */ 1489 bool lv_debug_check_obj_valid(const lv_obj_t * obj); 1490 1491 1492 /********************** 1493 * MACROS 1494 **********************/ 1495 1496 /** 1497 * Helps to quickly declare an event callback function. 1498 * Will be expanded to: `static void <name> (lv_obj_t * obj, lv_event_t e)` 1499 * 1500 * Examples: 1501 * LV_EVENT_CB_DECLARE(my_event1); //Prototype declaration 1502 * 1503 * LV_EVENT_CB_DECLARE(my_event1) 1504 * { 1505 * if(e == LV_EVENT_CLICKED) { 1506 * lv_obj_set_hidden(obj ,true); 1507 * } 1508 * } 1509 */ 1510 #define LV_EVENT_CB_DECLARE(name) static void name(lv_obj_t * obj, lv_event_t e) 1511 1512 1513 #if LV_USE_DEBUG 1514 1515 # ifndef LV_DEBUG_IS_OBJ 1516 # define LV_DEBUG_IS_OBJ(obj_p, obj_type) (lv_debug_check_null(obj_p) && \ 1517 lv_debug_check_obj_valid(obj_p) && \ 1518 lv_debug_check_obj_type(obj_p, obj_type)) 1519 # endif 1520 1521 1522 # if LV_USE_ASSERT_OBJ 1523 # ifndef LV_ASSERT_OBJ 1524 # define LV_ASSERT_OBJ(obj_p, obj_type) LV_DEBUG_ASSERT(LV_DEBUG_IS_OBJ(obj_p, obj_type), "Invalid object", obj_p); 1525 # endif 1526 # else /* LV_USE_ASSERT_OBJ == 0 */ 1527 # if LV_USE_ASSERT_NULL /*Use at least LV_ASSERT_NULL if enabled*/ 1528 # define LV_ASSERT_OBJ(obj_p, obj_type) LV_ASSERT_NULL(obj_p) 1529 # else 1530 # define LV_ASSERT_OBJ(obj_p, obj_type) 1531 # endif 1532 # endif 1533 #else 1534 # define LV_ASSERT_OBJ(obj, obj_type) 1535 #endif 1536 1537 1538 #ifdef __cplusplus 1539 } /* extern "C" */ 1540 #endif 1541 1542 #endif /*LV_OBJ_H*/ 1543