1 /** 2 * @file lv_obj_property.h 3 * 4 */ 5 6 #ifndef LV_OBJ_PROPERTY_H 7 #define LV_OBJ_PROPERTY_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /********************* 14 * INCLUDES 15 *********************/ 16 #include "../misc/lv_types.h" 17 #include "../misc/lv_style.h" 18 19 #if LV_USE_OBJ_PROPERTY 20 21 /********************* 22 * DEFINES 23 *********************/ 24 25 /*All possible property value types*/ 26 #define LV_PROPERTY_TYPE_INVALID 0 /*Use default 0 as invalid to detect program outliers*/ 27 #define LV_PROPERTY_TYPE_INT 1 /*int32_t type*/ 28 #define LV_PROPERTY_TYPE_PRECISE 2 /*lv_value_precise_t, int32_t or float depending on LV_USE_FLOAT*/ 29 #define LV_PROPERTY_TYPE_COLOR 3 /*ARGB8888 type*/ 30 #define LV_PROPERTY_TYPE_POINT 4 /*lv_point_t */ 31 #define LV_PROPERTY_TYPE_POINTER 5 /*void * pointer*/ 32 #define LV_PROPERTY_TYPE_IMGSRC 6 /*Special pointer for image*/ 33 #define LV_PROPERTY_TYPE_TEXT 7 /*Special pointer of char* */ 34 #define LV_PROPERTY_TYPE_OBJ 8 /*Special pointer of lv_obj_t* */ 35 #define LV_PROPERTY_TYPE_DISPLAY 9 /*Special pointer of lv_display_t* */ 36 #define LV_PROPERTY_TYPE_FONT 10 /*Special pointer of lv_font_t* */ 37 #define LV_PROPERTY_TYPE_BOOL 11 /*int32_t type*/ 38 39 #define LV_PROPERTY_TYPE_SHIFT 28 40 #define LV_PROPERTY_TYPE2_SHIFT 24 41 #define LV_PROPERTY_ID(clz, name, type, index) LV_PROPERTY_## clz ##_##name = (LV_PROPERTY_## clz ##_START + (index)) | ((type) << LV_PROPERTY_TYPE_SHIFT) 42 #define LV_PROPERTY_ID2(clz, name, type, type2, index) LV_PROPERTY_ID(clz, name, type, index) | ((type2) << LV_PROPERTY_TYPE2_SHIFT) 43 44 #define LV_PROPERTY_ID_TYPE(id) ((id) >> LV_PROPERTY_TYPE_SHIFT) 45 #define LV_PROPERTY_ID_TYPE2(id) ((id) >> LV_PROPERTY_TYPE_SHIFT) 46 #define LV_PROPERTY_ID_INDEX(id) ((id) & 0xfffffff) 47 48 /*Set properties from an array of lv_property_t*/ 49 #define LV_OBJ_SET_PROPERTY_ARRAY(obj, array) lv_obj_set_properties(obj, array, sizeof(array)/sizeof(array[0])) 50 51 52 /********************** 53 * TYPEDEFS 54 **********************/ 55 56 /** 57 * Group of predefined widget ID start value. 58 */ 59 enum { 60 LV_PROPERTY_ID_INVALID = 0, 61 62 /*ID 0x01 to 0xff are style ID, check lv_style_prop_t*/ 63 LV_PROPERTY_STYLE_START = 0x00, 64 65 LV_PROPERTY_ID_START = 0x0100, /*ID smaller than 0xff is style ID*/ 66 /*Define the property ID for every widget here. */ 67 LV_PROPERTY_OBJ_START = 0x0100, /* lv_obj.c */ 68 LV_PROPERTY_IMAGE_START = 0x0200, /* lv_image.c */ 69 LV_PROPERTY_LABEL_START = 0x0300, /* lv_label.c */ 70 LV_PROPERTY_KEYBOARD_START = 0x0400, /* lv_keyboard.c */ 71 LV_PROPERTY_TEXTAREA_START = 0x0500, /* lv_textarea.c */ 72 LV_PROPERTY_ROLLER_START = 0x0600, /* lv_roller.c */ 73 LV_PROPERTY_DROPDOWN_START = 0x0700, /* lv_dropdown.c */ 74 LV_PROPERTY_SLIDER_START = 0x0800, /* lv_slider.c */ 75 LV_PROPERTY_ANIMIMAGE_START = 0x0900, /* lv_animimage.c */ 76 77 /*Special ID, use it to extend ID and make sure it's unique and compile time determinant*/ 78 LV_PROPERTY_ID_BUILTIN_LAST = 0xffff, /*ID of 0x10000 ~ 0xfffffff is reserved for user*/ 79 80 LV_PROPERTY_ID_ANY = 0x7ffffffe, /*Special ID used by lvgl to intercept all setter/getter call.*/ 81 }; 82 83 struct _lv_property_name_t { 84 const char * name; 85 lv_prop_id_t id; 86 }; 87 88 typedef struct { 89 lv_prop_id_t id; 90 union { 91 int32_t num; /**< Signed integer number (enums or "normal" numbers)*/ 92 uint32_t num_u; /**< Unsigned integer number (opacity, Booleans) */ 93 bool enable; /**< Booleans */ 94 const void * ptr; /**< Constant pointers (font, cone text, etc.) */ 95 lv_color_t color; /**< Colors */ 96 lv_value_precise_t precise; /**< float or int for precise value */ 97 lv_point_t point; /**< Point, contains two int32_t */ 98 99 struct { 100 /** 101 * Note that place struct member `style` at first place is intended. 102 * `style` shares same memory with `num`, `ptr`, `color`. 103 * So we set the style value directly without using `prop.style.num`. 104 * 105 * E.g. 106 * 107 * static const lv_property_t obj_pos_x = { 108 * .id = LV_PROPERTY_STYLE_X, 109 * .num = 123, 110 * .selector = LV_STATE_PRESSED, 111 * } 112 * 113 * instead of: 114 * static const lv_property_t obj_pos_x = { 115 * .id = LV_PROPERTY_STYLE_X, 116 * .style.num = 123, // note this line. 117 * .selector = LV_STATE_PRESSED, 118 * } 119 */ 120 lv_style_value_t style; /**< Make sure it's the first element in struct. */ 121 uint32_t selector; /**< Style selector, lv_part_t | lv_state_t */ 122 }; 123 124 /** 125 * For some properties like slider range, it contains two simple (4-byte) values 126 * so we can use `arg1.num` and `arg2.num` to set the argument. 127 */ 128 struct { 129 union { 130 int32_t num; 131 uint32_t num_u; 132 bool enable; 133 const void * ptr; 134 lv_color_t color; 135 lv_value_precise_t precise; 136 } arg1, arg2; 137 }; 138 }; 139 } lv_property_t; 140 141 typedef struct { 142 lv_prop_id_t id; 143 144 void * setter; /**< Callback used to set property. */ 145 void * getter; /**< Callback used to get property. */ 146 } lv_property_ops_t; 147 148 /********************** 149 * GLOBAL PROTOTYPES 150 **********************/ 151 152 /*===================== 153 * Setter functions 154 *====================*/ 155 156 /** 157 * Set Widget property. 158 * @param obj pointer to Widget 159 * @param value property value to set 160 * @return return LV_RESULT_OK if call succeeded 161 */ 162 lv_result_t lv_obj_set_property(lv_obj_t * obj, const lv_property_t * value); 163 164 /** 165 * Set multiple Widget properties. Helper `LV_OBJ_SET_PROPERTY_ARRAY` can be used for constant property array. 166 * @param obj pointer to Widget 167 * @param value property value array to set 168 * @param count number of array elements 169 * @return return LV_RESULT_OK if call succeeded 170 */ 171 lv_result_t lv_obj_set_properties(lv_obj_t * obj, const lv_property_t * value, uint32_t count); 172 173 /*===================== 174 * Getter functions 175 *====================*/ 176 177 /** 178 * Read property value from Widget. 179 * If id is a style property. Style selector is 0 by default. 180 * @param obj pointer to Widget 181 * @param id ID of property to read 182 * @return return property value read. The returned property ID is set to `LV_PROPERTY_ID_INVALID` if read failed. 183 */ 184 lv_property_t lv_obj_get_property(lv_obj_t * obj, lv_prop_id_t id); 185 186 /** 187 * Read style property value from Widget 188 * @param obj pointer to Widget 189 * @param id ID of style property 190 * @param selector selector for style property 191 * @return return property value read. The returned property ID is set to `LV_PROPERTY_ID_INVALID` if read failed. 192 */ 193 lv_property_t lv_obj_get_style_property(lv_obj_t * obj, lv_prop_id_t id, uint32_t selector); 194 195 /** 196 * Get property ID by recursively searching for name in Widget's class hierarchy, and 197 * if still not found, then search style properties. 198 * Requires to enabling `LV_USE_OBJ_PROPERTY_NAME`. 199 * @param obj pointer to Widget whose class and base-class hierarchy are to be searched. 200 * @param name property name 201 * @return property ID found or `LV_PROPERTY_ID_INVALID` if not found. 202 */ 203 lv_prop_id_t lv_obj_property_get_id(const lv_obj_t * obj, const char * name); 204 205 /** 206 * Get property ID by doing a non-recursive search for name directly in Widget class properties. 207 * Requires enabling `LV_USE_OBJ_PROPERTY_NAME`. 208 * @param clz pointer to Widget class that has specified property. 209 * @param name property name 210 * @return property ID found or `LV_PROPERTY_ID_INVALID` if not found. 211 */ 212 lv_prop_id_t lv_obj_class_property_get_id(const lv_obj_class_t * clz, const char * name); 213 214 /** 215 * Get style property ID by name. Requires enabling `LV_USE_OBJ_PROPERTY_NAME`. 216 * @param name property name 217 * @return property ID found or `LV_PROPERTY_ID_INVALID` if not found. 218 */ 219 lv_prop_id_t lv_style_property_get_id(const char * name); 220 221 /********************** 222 * MACROS 223 **********************/ 224 225 #include "../widgets/property/lv_obj_property_names.h" 226 #include "../widgets/property/lv_style_properties.h" 227 228 #endif /*LV_USE_OBJ_PROPERTY*/ 229 230 #ifdef __cplusplus 231 } /*extern "C"*/ 232 #endif 233 234 #endif /*LV_OBJ_PROPERTY_H*/ 235