experiemnt with style transitions
This commit is contained in:
@@ -1429,13 +1429,32 @@ void lv_obj_clear_protect(lv_obj_t * obj, uint8_t prot)
|
||||
obj->protect &= prot;
|
||||
}
|
||||
|
||||
void lv_obj_state_anim_cb(void * p, lv_anim_value_t value)
|
||||
{
|
||||
lv_obj_t * obj = p;
|
||||
obj->state_anim = value;
|
||||
if(value == 255) obj->prev_state = obj->state;
|
||||
|
||||
lv_obj_refresh_style(obj);
|
||||
}
|
||||
|
||||
void lv_obj_set_state(lv_obj_t * obj, lv_obj_state_t state)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
|
||||
|
||||
lv_obj_state_t new_state = obj->state | state;
|
||||
if(obj->state != new_state) {
|
||||
obj->prev_state = obj->state;
|
||||
obj->state = new_state;
|
||||
obj->state_anim = 0;
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, obj, lv_obj_state_anim_cb);
|
||||
lv_anim_set_values(&a, 0, 255);
|
||||
lv_anim_set_time(&a, 1000, 0);
|
||||
lv_anim_create(&a);
|
||||
|
||||
lv_obj_refresh_style(obj);
|
||||
}
|
||||
}
|
||||
@@ -1447,7 +1466,18 @@ void lv_obj_clear_state(lv_obj_t * obj, lv_obj_state_t state)
|
||||
state = (~state) & 0xFF;
|
||||
lv_obj_state_t new_state = obj->state & state;
|
||||
if(obj->state != new_state) {
|
||||
obj->prev_state = obj->state;
|
||||
obj->state = new_state;
|
||||
obj->state_anim = 0;
|
||||
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, obj, lv_obj_state_anim_cb);
|
||||
lv_anim_set_values(&a, 0, 255);
|
||||
lv_anim_set_time(&a, 1000, 0);
|
||||
lv_anim_create(&a);
|
||||
|
||||
lv_obj_refresh_style(obj);
|
||||
}
|
||||
}
|
||||
@@ -2082,7 +2112,8 @@ lv_style_int_t lv_obj_get_style_int(const lv_obj_t * obj, uint8_t part, lv_style
|
||||
return 0;
|
||||
}
|
||||
|
||||
lv_color_t lv_obj_get_style_color(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop)
|
||||
|
||||
lv_color_t lv_obj_get_style_color_core(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop)
|
||||
{
|
||||
lv_style_property_t prop_ori = prop;
|
||||
|
||||
@@ -2119,12 +2150,29 @@ lv_color_t lv_obj_get_style_color(const lv_obj_t * obj, uint8_t part, lv_style_p
|
||||
case LV_STYLE_TEXT_COLOR:
|
||||
case LV_STYLE_BORDER_COLOR:
|
||||
case LV_STYLE_SHADOW_COLOR:
|
||||
return LV_COLOR_BLACK;
|
||||
}
|
||||
return LV_COLOR_BLACK;
|
||||
}
|
||||
|
||||
return LV_COLOR_WHITE;
|
||||
}
|
||||
|
||||
|
||||
lv_color_t lv_obj_get_style_color(lv_obj_t * obj, uint8_t part, lv_style_property_t prop)
|
||||
{
|
||||
if(obj->state == obj->prev_state) {
|
||||
return lv_obj_get_style_color_core(obj, part, prop);
|
||||
} else {
|
||||
lv_color_t act_color = lv_obj_get_style_color_core(obj, part, prop);
|
||||
|
||||
lv_obj_state_t state_ori = obj->state;
|
||||
obj->state = obj->prev_state;
|
||||
lv_color_t prev_color = lv_obj_get_style_color_core(obj, part, prop);
|
||||
obj->state = state_ori;
|
||||
|
||||
return lv_color_mix(prev_color, act_color, obj->state_anim);
|
||||
}
|
||||
}
|
||||
|
||||
lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop)
|
||||
{
|
||||
lv_style_property_t prop_ori = prop;
|
||||
|
||||
@@ -255,6 +255,8 @@ typedef struct _lv_obj_t
|
||||
uint8_t protect; /**< Automatically happening actions can be prevented.
|
||||
'OR'ed values from `lv_protect_t`*/
|
||||
uint8_t state;
|
||||
uint8_t prev_state;
|
||||
uint8_t state_anim;
|
||||
|
||||
#if LV_USE_OBJ_REALIGN
|
||||
lv_realign_t realign; /**< Information about the last call to ::lv_obj_align. */
|
||||
@@ -867,7 +869,7 @@ lv_style_dsc_t * lv_obj_get_style(const lv_obj_t * obj, uint8_t type);
|
||||
|
||||
lv_style_int_t lv_obj_get_style_int(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop);
|
||||
|
||||
lv_color_t lv_obj_get_style_color(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop);
|
||||
lv_color_t lv_obj_get_style_color(lv_obj_t * obj, uint8_t type, lv_style_property_t prop);
|
||||
|
||||
lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop);
|
||||
|
||||
|
||||
@@ -623,25 +623,30 @@ static lv_design_res_t lv_btnm_design(lv_obj_t * btnm, const lv_area_t * clip_ar
|
||||
|
||||
/*The state changes without re-caching the styles, disable the use of cache*/
|
||||
uint8_t state_ori = btnm->state;
|
||||
uint8_t prev_state_ori = btnm->prev_state;
|
||||
btnm->state = 0;
|
||||
btnm->prev_state = 0;
|
||||
lv_draw_rect_dsc_init(&draw_rect_rel_dsc);
|
||||
lv_draw_label_dsc_init(&draw_label_rel_dsc);
|
||||
lv_obj_init_draw_rect_dsc(btnm, LV_BTNM_PART_BTN, &draw_rect_rel_dsc);
|
||||
lv_obj_init_draw_label_dsc(btnm, LV_BTNM_PART_BTN, &draw_label_rel_dsc);
|
||||
|
||||
btnm->state = LV_OBJ_STATE_CHECKED;
|
||||
btnm->prev_state = LV_OBJ_STATE_CHECKED;
|
||||
lv_draw_rect_dsc_init(&draw_rect_chk_dsc);
|
||||
lv_draw_label_dsc_init(&draw_label_chk_dsc);
|
||||
lv_obj_init_draw_rect_dsc(btnm, LV_BTNM_PART_BTN, &draw_rect_chk_dsc);
|
||||
lv_obj_init_draw_label_dsc(btnm, LV_BTNM_PART_BTN, &draw_label_chk_dsc);
|
||||
|
||||
btnm->state = LV_OBJ_STATE_DISABLED;
|
||||
btnm->prev_state = LV_OBJ_STATE_DISABLED;
|
||||
lv_draw_rect_dsc_init(&draw_rect_ina_dsc);
|
||||
lv_draw_label_dsc_init(&draw_label_ina_dsc);
|
||||
lv_obj_init_draw_rect_dsc(btnm, LV_BTNM_PART_BTN, &draw_rect_ina_dsc);
|
||||
lv_obj_init_draw_label_dsc(btnm, LV_BTNM_PART_BTN, &draw_label_ina_dsc);
|
||||
|
||||
btnm->state = state_ori;
|
||||
btnm->prev_state = state_ori;
|
||||
|
||||
lv_style_int_t padding_top = lv_obj_get_style_int(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_TOP);
|
||||
lv_style_int_t padding_bottom = lv_obj_get_style_int(btnm, LV_BTNM_PART_BG, LV_STYLE_PAD_BOTTOM);
|
||||
|
||||
@@ -775,6 +775,7 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
|
||||
/*The state changes without re-caching the styles, disable the use of cache*/
|
||||
lv_obj_state_t state_ori = calendar->state;
|
||||
lv_obj_state_t prev_state_ori = calendar->prev_state;
|
||||
|
||||
lv_obj_state_t month_state = LV_OBJ_STATE_DISABLED;
|
||||
|
||||
@@ -855,6 +856,7 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
label_dsc.flag = LV_TXT_FLAG_CENTER;
|
||||
|
||||
calendar->state = day_state;
|
||||
calendar->prev_state = day_state;
|
||||
lv_obj_init_draw_label_dsc(calendar, LV_CALENDAR_PART_DATE_NUMS, &label_dsc);
|
||||
lv_obj_init_draw_rect_dsc(calendar, LV_CALENDAR_PART_DATE_NUMS, &rect_dsc);
|
||||
|
||||
@@ -880,6 +882,7 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
}
|
||||
}
|
||||
calendar->state = state_ori;
|
||||
calendar->prev_state = prev_state_ori;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user