/** * @file lv_obj.h * */ #ifndef LV_OBJ_H #define LV_OBJ_H #ifdef __cplusplus extern "C" { #endif /********************* * INCLUDES *********************/ #include "../lv_conf_internal.h" #include #include #include "lv_style.h" #include "lv_grid.h" #include "../lv_misc/lv_types.h" #include "../lv_misc/lv_area.h" #include "../lv_misc/lv_color.h" #include "../lv_misc/lv_debug.h" #include "../lv_hal/lv_hal.h" #include "../lv_draw/lv_draw_rect.h" #include "../lv_draw/lv_draw_label.h" #include "../lv_draw/lv_draw_line.h" #include "../lv_draw/lv_draw_img.h" /********************* * DEFINES *********************/ /*Error check of lv_conf.h*/ #if LV_HOR_RES_MAX == 0 || LV_VER_RES_MAX == 0 #error "LVGL: LV_HOR_RES_MAX and LV_VER_RES_MAX must be greater than 0" #endif #if LV_ANTIALIAS > 1 #error "LVGL: LV_ANTIALIAS can be only 0 or 1" #endif #define LV_MAX_ANCESTOR_NUM 8 #define LV_EXT_CLICK_AREA_OFF 0 #define LV_EXT_CLICK_AREA_TINY 1 #define LV_EXT_CLICK_AREA_FULL 2 #define _LV_OBJ_PART_VIRTUAL_FIRST 0x01 #define _LV_OBJ_PART_REAL_FIRST 0x40 /********************** * TYPEDEFS **********************/ struct _lv_obj_t; /** Design modes */ enum { LV_DESIGN_DRAW_MAIN, /**< Draw the main portion of the object */ LV_DESIGN_DRAW_POST, /**< Draw extras on the object */ LV_DESIGN_COVER_CHK, /**< Check if the object fully covers the 'mask_p' area */ }; typedef uint8_t lv_design_mode_t; /** Design results */ enum { LV_DESIGN_RES_OK, /**< Draw ready */ LV_DESIGN_RES_COVER, /**< Returned on `LV_DESIGN_COVER_CHK` if the areas is fully covered*/ LV_DESIGN_RES_NOT_COVER, /**< Returned on `LV_DESIGN_COVER_CHK` if the areas is not covered*/ LV_DESIGN_RES_MASKED, /**< Returned on `LV_DESIGN_COVER_CHK` if the areas is masked out (children also not cover)*/ }; typedef uint8_t lv_design_res_t; /** * The design callback is used to draw the object on the screen. * It accepts the object, a mask area, and the mode in which to draw the object. */ 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); enum { LV_EVENT_PRESSED, /**< The object has been pressed*/ LV_EVENT_PRESSING, /**< The object is being pressed (called continuously while pressing)*/ LV_EVENT_PRESS_LOST, /**< User is still pressing but slid cursor/finger off of the object */ LV_EVENT_SHORT_CLICKED, /**< User pressed object for a short period of time, then released it. Not called if scrolled. */ LV_EVENT_LONG_PRESSED, /**< Object has been pressed for at least `LV_INDEV_LONG_PRESS_TIME`. Not called if scrolled.*/ LV_EVENT_LONG_PRESSED_REPEAT, /**< Called after `LV_INDEV_LONG_PRESS_TIME` in every `LV_INDEV_LONG_PRESS_REP_TIME` ms. Not called if scrolled.*/ LV_EVENT_CLICKED, /**< Called on release if not scrolled (regardless to long press)*/ LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/ LV_EVENT_SCROLL_BEGIN, LV_EVENT_SCROLL_THROW_BEGIN, LV_EVENT_SCROLL_END, LV_EVENT_SCROLLED, LV_EVENT_GESTURE, /**< The object has been gesture*/ LV_EVENT_KEY, LV_EVENT_FOCUSED, LV_EVENT_DEFOCUSED, LV_EVENT_LEAVE, LV_EVENT_VALUE_CHANGED, /**< The object's value has changed (i.e. slider moved) */ LV_EVENT_INSERT, LV_EVENT_REFRESH, LV_EVENT_APPLY, /**< "Ok", "Apply" or similar specific button has clicked*/ LV_EVENT_CANCEL, /**< "Close", "Cancel" or similar specific button has clicked*/ LV_EVENT_DELETE, /**< Object is being deleted */ _LV_EVENT_LAST /** Number of events*/ }; typedef uint8_t lv_event_t; /**< Type of event being sent to the object. */ /** * @brief Event callback. * Events are used to notify the user of some action being taken on the object. * For details, see ::lv_event_t. */ typedef void (*lv_event_cb_t)(struct _lv_obj_t * obj, lv_event_t event); /** Signals are for use by the object itself or to extend the object's functionality. * Applications should use ::lv_obj_set_event_cb to be notified of events that occur * on the object. */ enum { /*General signals*/ LV_SIGNAL_CLEANUP, /**< Object is being deleted */ LV_SIGNAL_CHILD_CHG, /**< Child was removed/added */ LV_SIGNAL_COORD_CHG, /**< Object coordinates/size have changed */ LV_SIGNAL_STYLE_CHG, /**< Object's style has changed */ LV_SIGNAL_BASE_DIR_CHG, /**data1, and NOT da(ext)->data1 */ void * lv_obj_get_ext_attr(const lv_obj_t * obj); /** * Get object's and its ancestors type. Put their name in `type_buf` starting with the current type. * E.g. buf.type[0]="lv_btn", buf.type[1]="lv_cont", buf.type[2]="lv_obj" * @param obj pointer to an object which type should be get * @param buf pointer to an `lv_obj_type_t` buffer to store the types */ void lv_obj_get_type(const lv_obj_t * obj, lv_obj_type_t * buf); #if LV_USE_USER_DATA /** * Get the object's user data * @param obj pointer to an object * @return user data */ lv_obj_user_data_t lv_obj_get_user_data(const lv_obj_t * obj); /** * Get a pointer to the object's user data * @param obj pointer to an object * @return pointer to the user data */ lv_obj_user_data_t * lv_obj_get_user_data_ptr(const lv_obj_t * obj); /** * Set the object's user data. The data will be copied. * @param obj pointer to an object * @param data user data */ void lv_obj_set_user_data(lv_obj_t * obj, lv_obj_user_data_t data); #endif /** * Get the group of the object * @param obj pointer to an object * @return the pointer to group of the object */ void * lv_obj_get_group(const lv_obj_t * obj); /** * Tell whether the object is the focused object of a group or not. * @param obj pointer to an object * @return true: the object is focused, false: the object is not focused or not in a group */ bool lv_obj_is_focused(const lv_obj_t * obj); /** * Get the really focused object by taking `focus_parent` into account. * @param obj the start object * @return the object to really focus */ lv_obj_t * lv_obj_get_focused_obj(const lv_obj_t * obj); /*------------------- * OTHER FUNCTIONS *------------------*/ /** * Used in the signal callback to handle `LV_SIGNAL_GET_TYPE` signal * @param buf pointer to `lv_obj_type_t`. (`param` in the signal callback) * @param name name of the object. E.g. "lv_btn". (Only the pointer is saved) * @return LV_RES_OK */ lv_res_t lv_obj_handle_get_type_signal(lv_obj_type_t * buf, const char * name); /** * Initialize a rectangle descriptor from an object's styles * @param obj pointer to an object * @param type type of style. E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_SLIDER_KOB` * @param draw_dsc the descriptor the initialize * @note Only the relevant fields will be set. * E.g. if `border width == 0` the other border properties won't be evaluated. */ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t type, lv_draw_rect_dsc_t * draw_dsc); void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t type, lv_draw_label_dsc_t * draw_dsc); void lv_obj_init_draw_img_dsc(lv_obj_t * obj, uint8_t part, lv_draw_img_dsc_t * draw_dsc); void lv_obj_init_draw_line_dsc(lv_obj_t * obj, uint8_t part, lv_draw_line_dsc_t * draw_dsc); /** * Get the required extra size (around the object's part) to draw shadow, outline, value etc. * @param obj pointer to an object * @param part part of the object */ lv_coord_t lv_obj_get_draw_rect_ext_pad_size(lv_obj_t * obj, uint8_t part); /** * Check if any object has a given type * @param obj pointer to an object * @param obj_type type of the object. (e.g. "lv_btn") * @return true: valid */ bool lv_debug_check_obj_type(const lv_obj_t * obj, const char * obj_type); /** * Check if any object is still "alive", and part of the hierarchy * @param obj pointer to an object * @param obj_type type of the object. (e.g. "lv_btn") * @return true: valid */ bool lv_debug_check_obj_valid(const lv_obj_t * obj); void _lv_obj_move_children_by(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff); #include "lv_obj_style.h" /********************** * MACROS **********************/ /** * Helps to quickly declare an event callback function. * Will be expanded to: `static void (lv_obj_t * obj, lv_event_t e)` * * Examples: * LV_EVENT_CB_DECLARE(my_event1); //Prototype declaration * * LV_EVENT_CB_DECLARE(my_event1) * { * if(e == LV_EVENT_CLICKED) { * lv_obj_set_hidden(obj ,true); * } * } */ #define LV_EVENT_CB_DECLARE(name) static void name(lv_obj_t * obj, lv_event_t e) #if LV_USE_DEBUG # ifndef LV_DEBUG_IS_OBJ # define LV_DEBUG_IS_OBJ(obj_p, obj_type) (lv_debug_check_null(obj_p) && \ lv_debug_check_obj_valid(obj_p) && \ lv_debug_check_obj_type(obj_p, obj_type)) # endif # if LV_USE_ASSERT_OBJ # ifndef LV_ASSERT_OBJ # define LV_ASSERT_OBJ(obj_p, obj_type) LV_DEBUG_ASSERT(LV_DEBUG_IS_OBJ(obj_p, obj_type), "Invalid object", obj_p); # endif # else /* LV_USE_ASSERT_OBJ == 0 */ # if LV_USE_ASSERT_NULL /*Use at least LV_ASSERT_NULL if enabled*/ # define LV_ASSERT_OBJ(obj_p, obj_type) LV_ASSERT_NULL(obj_p) # else # define LV_ASSERT_OBJ(obj_p, obj_type) true # endif # endif #else # define LV_ASSERT_OBJ(obj, obj_type) true #endif #ifdef __cplusplus } /* extern "C" */ #endif #endif /*LV_OBJ_H*/