mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(obj): add obj state property (#4969)
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
parent
4c10e4a992
commit
1dac562ac1
@ -835,6 +835,16 @@ static lv_result_t lv_obj_set_any(lv_obj_t * obj, lv_prop_id_t id, const lv_prop
|
||||
else lv_obj_remove_flag(obj, flag);
|
||||
return LV_RESULT_OK;
|
||||
}
|
||||
else if(id >= LV_PROPERTY_OBJ_STATE_START && id <= LV_PROPERTY_OBJ_STATE_END) {
|
||||
lv_state_t state = 1L << (id - LV_PROPERTY_OBJ_STATE_START);
|
||||
if(id == LV_PROPERTY_OBJ_STATE_ANY) {
|
||||
state = LV_STATE_ANY;
|
||||
}
|
||||
|
||||
if(prop->num) lv_obj_add_state(obj, state);
|
||||
else lv_obj_remove_state(obj, state);
|
||||
return LV_RESULT_OK;
|
||||
}
|
||||
else {
|
||||
return LV_RESULT_INVALID;
|
||||
}
|
||||
@ -849,6 +859,17 @@ static lv_result_t lv_obj_get_any(const lv_obj_t * obj, lv_prop_id_t id, lv_prop
|
||||
prop->num = obj->flags & flag;
|
||||
return LV_RESULT_OK;
|
||||
}
|
||||
else if(id >= LV_PROPERTY_OBJ_STATE_START && id <= LV_PROPERTY_OBJ_STATE_END) {
|
||||
prop->id = id;
|
||||
if(id == LV_PROPERTY_OBJ_STATE_ANY) {
|
||||
prop->num = obj->state;
|
||||
}
|
||||
else {
|
||||
lv_obj_flag_t flag = 1L << (id - LV_PROPERTY_OBJ_STATE_START);
|
||||
prop->num = obj->state & flag;
|
||||
}
|
||||
return LV_RESULT_OK;
|
||||
}
|
||||
else {
|
||||
return LV_RESULT_INVALID;
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ enum _lv_state_t {
|
||||
LV_STATE_PRESSED = 0x0020,
|
||||
LV_STATE_SCROLLED = 0x0040,
|
||||
LV_STATE_DISABLED = 0x0080,
|
||||
|
||||
LV_STATE_USER_1 = 0x1000,
|
||||
LV_STATE_USER_2 = 0x2000,
|
||||
LV_STATE_USER_3 = 0x4000,
|
||||
@ -177,6 +176,23 @@ enum {
|
||||
LV_PROPERTY_ID(OBJ, FLAG_USER_4, LV_PROPERTY_TYPE_INT, 30),
|
||||
LV_PROPERTY_ID(OBJ, FLAG_END, LV_PROPERTY_TYPE_INT, 30),
|
||||
|
||||
LV_PROPERTY_ID(OBJ, STATE_START, LV_PROPERTY_TYPE_INT, 31),
|
||||
LV_PROPERTY_ID(OBJ, STATE_CHECKED, LV_PROPERTY_TYPE_INT, 31),
|
||||
LV_PROPERTY_ID(OBJ, STATE_FOCUSED, LV_PROPERTY_TYPE_INT, 32),
|
||||
LV_PROPERTY_ID(OBJ, STATE_FOCUS_KEY, LV_PROPERTY_TYPE_INT, 33),
|
||||
LV_PROPERTY_ID(OBJ, STATE_EDITED, LV_PROPERTY_TYPE_INT, 34),
|
||||
LV_PROPERTY_ID(OBJ, STATE_HOVERED, LV_PROPERTY_TYPE_INT, 35),
|
||||
LV_PROPERTY_ID(OBJ, STATE_PRESSED, LV_PROPERTY_TYPE_INT, 36),
|
||||
LV_PROPERTY_ID(OBJ, STATE_SCROLLED, LV_PROPERTY_TYPE_INT, 37),
|
||||
LV_PROPERTY_ID(OBJ, STATE_DISABLED, LV_PROPERTY_TYPE_INT, 38),
|
||||
/*not used bit8-bit11*/
|
||||
LV_PROPERTY_ID(OBJ, STATE_USER_1, LV_PROPERTY_TYPE_INT, 43),
|
||||
LV_PROPERTY_ID(OBJ, STATE_USER_2, LV_PROPERTY_TYPE_INT, 44),
|
||||
LV_PROPERTY_ID(OBJ, STATE_USER_3, LV_PROPERTY_TYPE_INT, 45),
|
||||
LV_PROPERTY_ID(OBJ, STATE_USER_4, LV_PROPERTY_TYPE_INT, 46),
|
||||
LV_PROPERTY_ID(OBJ, STATE_ANY, LV_PROPERTY_TYPE_INT, 47),
|
||||
LV_PROPERTY_ID(OBJ, STATE_END, LV_PROPERTY_TYPE_INT, 47),
|
||||
|
||||
/*OBJ normal properties*/
|
||||
LV_PROPERTY_ID(OBJ, PARENT, LV_PROPERTY_TYPE_POINTER, 31),
|
||||
|
||||
@ -203,21 +219,21 @@ LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_obj_class;
|
||||
* They are allocated automatically if any elements is set.
|
||||
*/
|
||||
typedef struct {
|
||||
struct _lv_obj_t ** children; /**< Store the pointer of the children in an array.*/
|
||||
struct _lv_obj_t ** children; /**< Store the pointer of the children in an array.*/
|
||||
lv_group_t * group_p;
|
||||
lv_event_list_t event_list;
|
||||
|
||||
lv_point_t scroll; /**< The current X/Y scroll offset*/
|
||||
lv_point_t scroll; /**< The current X/Y scroll offset*/
|
||||
|
||||
int32_t ext_click_pad; /**< Extra click padding in all direction*/
|
||||
int32_t ext_draw_size; /**< EXTend the size in every direction for drawing.*/
|
||||
int32_t ext_click_pad; /**< Extra click padding in all direction*/
|
||||
int32_t ext_draw_size; /**< EXTend the size in every direction for drawing.*/
|
||||
|
||||
uint16_t child_cnt; /**< Number of children*/
|
||||
lv_scrollbar_mode_t scrollbar_mode : 2; /**< How to display scrollbars*/
|
||||
lv_scroll_snap_t scroll_snap_x : 2; /**< Where to align the snappable children horizontally*/
|
||||
lv_scroll_snap_t scroll_snap_y : 2; /**< Where to align the snappable children vertically*/
|
||||
lv_dir_t scroll_dir : 4; /**< The allowed scroll direction(s)*/
|
||||
uint8_t layer_type : 2; /**< Cache the layer type here. Element of @lv_intermediate_layer_type_t */
|
||||
uint16_t child_cnt; /**< Number of children*/
|
||||
uint16_t scrollbar_mode : 2; /**< How to display scrollbars, see `lv_scrollbar_mode_t`*/
|
||||
uint16_t scroll_snap_x : 2; /**< Where to align the snappable children horizontally, see `lv_scroll_snap_t`*/
|
||||
uint16_t scroll_snap_y : 2; /**< Where to align the snappable children vertically*/
|
||||
uint16_t scroll_dir : 4; /**< The allowed scroll direction(s), see `lv_dir_t`*/
|
||||
uint16_t layer_type : 2; /**< Cache the layer type here. Element of @lv_intermediate_layer_type_t */
|
||||
} _lv_obj_spec_attr_t;
|
||||
|
||||
typedef struct _lv_obj_t {
|
||||
|
@ -154,4 +154,50 @@ void test_obj_property_flag(void)
|
||||
}
|
||||
}
|
||||
|
||||
void test_obj_property_state(void)
|
||||
{
|
||||
const struct {
|
||||
uint32_t state;
|
||||
uint32_t id;
|
||||
} states[] = {
|
||||
{ LV_STATE_CHECKED, LV_PROPERTY_OBJ_STATE_CHECKED },
|
||||
{ LV_STATE_FOCUSED, LV_PROPERTY_OBJ_STATE_FOCUSED },
|
||||
{ LV_STATE_FOCUS_KEY, LV_PROPERTY_OBJ_STATE_FOCUS_KEY },
|
||||
{ LV_STATE_EDITED, LV_PROPERTY_OBJ_STATE_EDITED },
|
||||
{ LV_STATE_HOVERED, LV_PROPERTY_OBJ_STATE_HOVERED },
|
||||
{ LV_STATE_PRESSED, LV_PROPERTY_OBJ_STATE_PRESSED },
|
||||
{ LV_STATE_SCROLLED, LV_PROPERTY_OBJ_STATE_SCROLLED },
|
||||
{ LV_STATE_DISABLED, LV_PROPERTY_OBJ_STATE_DISABLED },
|
||||
{ LV_STATE_USER_1, LV_PROPERTY_OBJ_STATE_USER_1 },
|
||||
{ LV_STATE_USER_2, LV_PROPERTY_OBJ_STATE_USER_2 },
|
||||
{ LV_STATE_USER_3, LV_PROPERTY_OBJ_STATE_USER_3 },
|
||||
{ LV_STATE_USER_4, LV_PROPERTY_OBJ_STATE_USER_4 },
|
||||
};
|
||||
|
||||
lv_obj_t * obj = lv_obj_create(lv_screen_active());
|
||||
obj->state = 0;
|
||||
for(unsigned long i = 0; i < sizeof(states) / sizeof(states[0]); i++) {
|
||||
TEST_ASSERT_FALSE(lv_obj_get_property(obj, states[i].id).num);
|
||||
lv_obj_add_state(obj, states[i].state);
|
||||
printf("state: %d, value: %d\n", states[i].state, lv_obj_get_property(obj, states[i].id).num);
|
||||
TEST_ASSERT_TRUE(lv_obj_get_property(obj, states[i].id).num);
|
||||
|
||||
lv_obj_remove_state(obj, states[i].state);
|
||||
TEST_ASSERT_FALSE(lv_obj_get_property(obj, states[i].id).num);
|
||||
|
||||
lv_property_t prop = { };
|
||||
prop.id = states[i].id;
|
||||
prop.num = 1;
|
||||
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||
TEST_ASSERT_TRUE(lv_obj_get_property(obj, states[i].id).num);
|
||||
TEST_ASSERT_TRUE(lv_obj_get_state(obj) & states[i].state);
|
||||
|
||||
prop.id = states[i].id;
|
||||
prop.num = 0;
|
||||
TEST_ASSERT_TRUE(lv_obj_set_property(obj, &prop) == LV_RESULT_OK);
|
||||
TEST_ASSERT_FALSE(lv_obj_get_property(obj, states[i].id).num);
|
||||
TEST_ASSERT_FALSE(lv_obj_get_state(obj) & states[i].state);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user