mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
make style transition more flexible
This commit is contained in:
parent
4fe3821719
commit
181692605a
@ -47,6 +47,7 @@
|
||||
#define LV_OBJ_DEF_WIDTH (LV_DPX(100))
|
||||
#define LV_OBJ_DEF_HEIGHT (LV_DPX(50))
|
||||
#define GRID_DEBUG 0 /*Draw rectangles on grid cells*/
|
||||
#define STYLE_TRANSITION_MAX 32
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@ -73,6 +74,22 @@ static void lv_obj_destructor(void * obj);
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static const uint16_t trans_prop_def[] =
|
||||
{
|
||||
LV_STYLE_RADIUS, LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_TRANSFORM_HEIGHT, LV_STYLE_TRANSFORM_ZOOM, LV_STYLE_TRANSFORM_ANGLE, LV_STYLE_OPA,
|
||||
LV_STYLE_COLOR_FILTER_CB, LV_STYLE_COLOR_FILTER_OPA,
|
||||
LV_STYLE_PAD_TOP, LV_STYLE_PAD_BOTTOM, LV_STYLE_PAD_LEFT, LV_STYLE_PAD_RIGHT,
|
||||
LV_STYLE_MARGIN_TOP, LV_STYLE_MARGIN_BOTTOM, LV_STYLE_MARGIN_LEFT, LV_STYLE_MARGIN_RIGHT,
|
||||
LV_STYLE_BG_COLOR, LV_STYLE_BG_OPA, LV_STYLE_BG_GRAD_COLOR, LV_STYLE_BG_MAIN_STOP, LV_STYLE_BG_GRAD_STOP,
|
||||
LV_STYLE_BORDER_COLOR, LV_STYLE_BORDER_OPA, LV_STYLE_BORDER_WIDTH,
|
||||
LV_STYLE_TEXT_COLOR, LV_STYLE_TEXT_OPA, LV_STYLE_TEXT_FONT, LV_STYLE_TEXT_LETTER_SPACE, LV_STYLE_TEXT_LINE_SPACE,
|
||||
LV_STYLE_IMG_OPA, LV_STYLE_IMG_RECOLOR, LV_STYLE_IMG_RECOLOR_OPA,
|
||||
LV_STYLE_OUTLINE_WIDTH, LV_STYLE_OUTLINE_COLOR, LV_STYLE_OUTLINE_OPA, LV_STYLE_OUTLINE_PAD,
|
||||
LV_STYLE_SHADOW_WIDTH, LV_STYLE_SHADOW_OFS_X, LV_STYLE_SHADOW_OFS_Y, LV_STYLE_SHADOW_SPREAD, LV_STYLE_SHADOW_COLOR, LV_STYLE_SHADOW_OPA,
|
||||
LV_STYLE_LINE_WIDTH, LV_STYLE_LINE_COLOR, LV_STYLE_LINE_OPA,
|
||||
LV_STYLE_CONTENT_OFS_X, LV_STYLE_CONTENT_OFS_Y,
|
||||
0
|
||||
};
|
||||
static bool lv_initialized = false;
|
||||
static lv_event_temp_data_t * event_temp_data_head;
|
||||
static const void * event_act_data;
|
||||
@ -633,29 +650,55 @@ void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state)
|
||||
/*If there is no difference in styles there is nothing else to do*/
|
||||
if(cmp_res == _LV_STYLE_STATE_CMP_SAME) return;
|
||||
|
||||
uint8_t part;
|
||||
for(part = 0; part < _LV_OBJ_PART_MAX; part++) {
|
||||
uint16_t time = lv_obj_get_style_transition_time(obj, part);
|
||||
if(time == 0) continue;
|
||||
typedef struct {
|
||||
uint16_t time;
|
||||
uint16_t delay;
|
||||
lv_part_t part;
|
||||
lv_state_t state;
|
||||
lv_style_prop_t prop;
|
||||
const lv_anim_path_t * path;
|
||||
}trans_set_t;
|
||||
|
||||
lv_style_prop_t props[LV_STYLE_TRANS_NUM_MAX];
|
||||
uint16_t delay = lv_obj_get_style_transition_delay(obj, part);
|
||||
const lv_anim_path_t * path = lv_obj_get_style_transition_path(obj, part);
|
||||
props[0] = lv_obj_get_style_transition_prop_1(obj, part);
|
||||
props[1] = lv_obj_get_style_transition_prop_2(obj, part);
|
||||
props[2] = lv_obj_get_style_transition_prop_3(obj, part);
|
||||
props[3] = lv_obj_get_style_transition_prop_4(obj, part);
|
||||
props[4] = lv_obj_get_style_transition_prop_5(obj, part);
|
||||
props[5] = lv_obj_get_style_transition_prop_6(obj, part);
|
||||
trans_set_t * ts = _lv_mem_buf_get(sizeof(trans_set_t) * STYLE_TRANSITION_MAX);
|
||||
_lv_memset_00(ts, sizeof(sizeof(trans_set_t) * 64));
|
||||
uint32_t tsi = 0;
|
||||
uint32_t i;
|
||||
for(i = 0; i < obj->style_list.style_cnt && tsi < STYLE_TRANSITION_MAX; i++) {
|
||||
lv_obj_style_t * obj_style = &obj->style_list.styles[i];
|
||||
if(obj_style->state & (~new_state)) continue; /*Skip unrelated styles*/
|
||||
if(obj_style->is_trans) continue;
|
||||
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_STYLE_TRANS_NUM_MAX; i++) {
|
||||
if(props[i] != _LV_STYLE_PROP_INV) {
|
||||
_lv_obj_create_style_transition(obj, props[i], part, prev_state, new_state, time, delay, path);
|
||||
lv_style_value_t v;
|
||||
if(lv_style_get_prop(obj_style->style, LV_STYLE_TRANSITION, &v) == false) continue;
|
||||
const lv_style_transiton_t * tr = v._ptr;
|
||||
|
||||
/*Add the props t the set is not added yet or added but with smaller weight*/
|
||||
uint32_t j;
|
||||
for(j = 0; tr->props[j] != 0 && tsi < STYLE_TRANSITION_MAX; j++) {
|
||||
uint32_t t;
|
||||
for(t = 0; t < tsi; t++) {
|
||||
if(ts[t].prop == tr->props[j] && ts[t].state > obj_style->state) break;
|
||||
}
|
||||
|
||||
/*If not found add it*/
|
||||
if(t == tsi) {
|
||||
ts[tsi].time = tr->time;
|
||||
ts[tsi].delay = tr->delay;
|
||||
ts[tsi].path = tr->path;
|
||||
ts[tsi].prop = tr->props[j];
|
||||
ts[tsi].part = obj_style->part;
|
||||
ts[tsi].state = obj_style->state;
|
||||
tsi++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0;i < tsi; i++) {
|
||||
_lv_obj_create_style_transition(obj, ts[i].prop, ts[i].part, prev_state, new_state, ts[i].time, ts[i].delay, ts[i].path);
|
||||
}
|
||||
|
||||
_lv_mem_buf_release(ts);
|
||||
|
||||
if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_LAYOUT) _lv_obj_refresh_style(obj, LV_STYLE_PROP_ALL);
|
||||
else if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD) _lv_obj_refresh_ext_draw_pad(obj);
|
||||
else if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_REDRAW) lv_obj_invalidate(obj);
|
||||
@ -1259,7 +1302,7 @@ lv_res_t _lv_obj_handle_get_type_signal(lv_obj_type_t * buf, const char * name)
|
||||
* @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_check_type(const lv_obj_t * obj, void * class_p)
|
||||
bool lv_obj_check_type(const lv_obj_t * obj, void * class_p)
|
||||
{
|
||||
return obj->class_p == class_p ? true : false;
|
||||
}
|
||||
|
@ -257,6 +257,8 @@ enum {
|
||||
LV_PART_HIGHLIGHT,
|
||||
};
|
||||
|
||||
typedef uint8_t lv_part_t;
|
||||
|
||||
/** Used by `lv_obj_get_type()`. The object's and its ancestor types are stored here*/
|
||||
typedef struct {
|
||||
const char * type[LV_MAX_ANCESTOR_NUM]; /**< [0]: the actual type, [1]: ancestor, [2] #1's ancestor
|
||||
@ -681,7 +683,7 @@ bool lv_obj_hit_test(lv_obj_t * obj, lv_point_t * point);
|
||||
*/
|
||||
void * lv_obj_get_ext_attr(const lv_obj_t * obj);
|
||||
|
||||
void * lv_obj_check_type(const lv_obj_t * obj, void * class_p);
|
||||
bool lv_obj_check_type(const lv_obj_t * obj, void * class_p);
|
||||
|
||||
#if LV_USE_USER_DATA
|
||||
/**
|
||||
|
@ -32,7 +32,6 @@ typedef struct {
|
||||
lv_style_value_t end_value;
|
||||
} lv_style_trans_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
lv_draw_rect_dsc_t rect;
|
||||
lv_draw_label_dsc_t label;
|
||||
@ -513,7 +512,7 @@ void _lv_obj_create_style_transition(lv_obj_t * obj, lv_style_prop_t prop, uint8
|
||||
obj->state = new_state;
|
||||
lv_style_value_t v2 = lv_obj_get_style_prop(obj, part, prop);
|
||||
obj->style_list.skip_trans = 0;
|
||||
// if(memcmp(&v1, &v2, sizeof(lv_style_value_t) == 0)) return;
|
||||
|
||||
if(v1._ptr == v2._ptr && v1._int == v2._int && v1._color.full == v2._color.full) return;
|
||||
obj->state = prev_state;
|
||||
v1 = lv_obj_get_style_prop(obj, part, prop);
|
||||
@ -581,16 +580,23 @@ _lv_style_state_cmp_t _lv_obj_style_state_compare(lv_obj_t * obj, lv_state_t sta
|
||||
if(valid1 != valid2) {
|
||||
lv_style_t * style = list->styles[i].style;
|
||||
|
||||
/*If there is layout difference, return immediately. There is no more serious difference*/
|
||||
if(list->styles[i].part == LV_PART_MAIN) {
|
||||
if(style->has_pad_bottom) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
if(style->has_pad_top) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
if(style->has_pad_left) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
if(style->has_pad_right) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
if(style->ext && style->ext->has_margin_bottom) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
if(style->ext && style->ext->has_margin_top) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
if(style->ext && style->ext->has_margin_left) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
if(style->ext && style->ext->has_margin_right) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
/*If there is layout difference on the main part, return immediately. There is no more serious difference*/
|
||||
_lv_style_state_cmp_t res_tmp = res;
|
||||
if(style->has_pad_bottom) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
else if(style->has_pad_top) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
else if(style->has_pad_left) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
else if(style->has_pad_right) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
else if(style->ext && style->ext->has_margin_bottom) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
else if(style->ext && style->ext->has_margin_top) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
else if(style->ext && style->ext->has_margin_left) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
else if(style->ext && style->ext->has_margin_right) res_tmp = _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
|
||||
if(res_tmp == _LV_STYLE_STATE_CMP_DIFF_LAYOUT) {
|
||||
if(list->styles[i].part == LV_PART_MAIN) return _LV_STYLE_STATE_CMP_DIFF_LAYOUT;
|
||||
else {
|
||||
res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/*Check for draw pad changes*/
|
||||
@ -611,7 +617,7 @@ _lv_style_state_cmp_t _lv_obj_style_state_compare(lv_obj_t * obj, lv_state_t sta
|
||||
else if(style->ext && style->ext->has_content_ofs_y) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
|
||||
else if(style->ext && style->ext->has_content_align) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD;
|
||||
else {
|
||||
res = _LV_STYLE_STATE_CMP_DIFF_REDRAW;
|
||||
if(res != _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD) res = _LV_STYLE_STATE_CMP_DIFF_REDRAW;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -712,14 +718,9 @@ static void trans_anim_cb(lv_style_trans_t * tr, lv_anim_value_t v)
|
||||
|
||||
lv_style_value_t value_final;
|
||||
switch (tr->prop) {
|
||||
|
||||
case LV_STYLE_BORDER_SIDE:
|
||||
case LV_STYLE_BORDER_POST:
|
||||
case LV_STYLE_TRANSITION_PROP_1:
|
||||
case LV_STYLE_TRANSITION_PROP_2:
|
||||
case LV_STYLE_TRANSITION_PROP_3:
|
||||
case LV_STYLE_TRANSITION_PROP_4:
|
||||
case LV_STYLE_TRANSITION_PROP_5:
|
||||
case LV_STYLE_TRANSITION_PROP_6:
|
||||
case LV_STYLE_BG_BLEND_MODE:
|
||||
case LV_STYLE_BORDER_BLEND_MODE:
|
||||
case LV_STYLE_OUTLINE_BLEND_MODE:
|
||||
@ -729,12 +730,17 @@ static void trans_anim_cb(lv_style_trans_t * tr, lv_anim_value_t v)
|
||||
if(v < 255) value_final._int = tr->start_value._int;
|
||||
else value_final._int = tr->end_value._int;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION:
|
||||
case LV_STYLE_TEXT_FONT:
|
||||
case LV_STYLE_COLOR_FILTER_CB:
|
||||
if(v < 255) value_final._ptr = tr->start_value._ptr;
|
||||
else value_final._ptr = tr->end_value._ptr;
|
||||
break;
|
||||
|
||||
case LV_STYLE_COLOR_FILTER_CB:
|
||||
if(tr->start_value._func == NULL) value_final._ptr = tr->end_value._func;
|
||||
else if(tr->end_value._func == NULL) value_final._ptr = tr->start_value._func;
|
||||
else if(v < 128) value_final._ptr = tr->start_value._ptr;
|
||||
else value_final._ptr = tr->end_value._ptr;
|
||||
break;
|
||||
case LV_STYLE_BG_COLOR:
|
||||
case LV_STYLE_BORDER_COLOR:
|
||||
case LV_STYLE_TEXT_COLOR:
|
||||
|
@ -378,32 +378,8 @@ static inline lv_coord_t lv_obj_get_style_content_ofs_x(const struct _lv_obj_t *
|
||||
static inline lv_coord_t lv_obj_get_style_content_ofs_y(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_CONTENT_OFS_Y); return v._int; }
|
||||
|
||||
static inline uint16_t lv_obj_get_style_transition_time(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION_TIME); return v._int; }
|
||||
|
||||
static inline uint16_t lv_obj_get_style_transition_delay(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION_DELAY); return v._int; }
|
||||
|
||||
static inline const lv_anim_path_t * lv_obj_get_style_transition_path(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION_PATH); return v._ptr; }
|
||||
|
||||
static inline lv_style_prop_t lv_obj_get_style_transition_prop_1(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION_PROP_1); return v._int; }
|
||||
|
||||
static inline lv_style_prop_t lv_obj_get_style_transition_prop_2(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION_PROP_2); return v._int; }
|
||||
|
||||
static inline lv_style_prop_t lv_obj_get_style_transition_prop_3(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION_PROP_3); return v._int; }
|
||||
|
||||
static inline lv_style_prop_t lv_obj_get_style_transition_prop_4(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION_PROP_4); return v._int; }
|
||||
|
||||
static inline lv_style_prop_t lv_obj_get_style_transition_prop_5(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION_PROP_5); return v._int; }
|
||||
|
||||
static inline lv_style_prop_t lv_obj_get_style_transition_prop_6(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION_PROP_6); return v._int; }
|
||||
static inline const lv_style_transiton_t * lv_obj_get_style_transition(const struct _lv_obj_t * obj, uint32_t part) {
|
||||
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION); return v._ptr; }
|
||||
|
||||
|
||||
/**********************
|
||||
|
@ -113,6 +113,15 @@ bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_
|
||||
return style->class_p->get_prop(style, prop, value);
|
||||
}
|
||||
|
||||
void lv_style_transition_init(lv_style_transiton_t * tr, const lv_style_prop_t * props, const lv_anim_path_t * path, uint32_t time, uint32_t delay)
|
||||
{
|
||||
_lv_memset_00(tr, sizeof(lv_style_transiton_t));
|
||||
tr->props = props;
|
||||
tr->path = path;
|
||||
tr->time = time;
|
||||
tr->delay = delay;
|
||||
}
|
||||
|
||||
lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop)
|
||||
{
|
||||
lv_style_value_t value;
|
||||
@ -141,9 +150,6 @@ lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop)
|
||||
case LV_STYLE_TEXT_FONT:
|
||||
value._ptr = LV_THEME_DEFAULT_FONT_NORMAL;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PATH:
|
||||
value._ptr = &lv_anim_path_def;
|
||||
break;
|
||||
default:
|
||||
value._ptr = NULL;
|
||||
value._int = 0;
|
||||
@ -504,50 +510,10 @@ static void set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t
|
||||
style->ext->has_content_ofs_y = 1;
|
||||
break;
|
||||
|
||||
case LV_STYLE_TRANSITION_TIME:
|
||||
case LV_STYLE_TRANSITION:
|
||||
_alloc_ext(style);
|
||||
style->ext->transition_time = value._int;
|
||||
style->ext->has_transition_time = 1;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_DELAY:
|
||||
_alloc_ext(style);
|
||||
style->ext->transition_delay = value._int;
|
||||
style->ext->has_transition_delay = 1;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PATH:
|
||||
_alloc_ext(style);
|
||||
style->ext->transition_path = value._ptr;
|
||||
style->ext->has_transition_path = 1;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_1:
|
||||
_alloc_ext(style);
|
||||
style->ext->transition_prop_1 = value._int;
|
||||
style->ext->has_transition_prop_1 = 1;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_2:
|
||||
_alloc_ext(style);
|
||||
style->ext->transition_prop_2 = value._int;
|
||||
style->ext->has_transition_prop_2 = 1;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_3:
|
||||
_alloc_ext(style);
|
||||
style->ext->transition_prop_3 = value._int;
|
||||
style->ext->has_transition_prop_3 = 1;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_4:
|
||||
_alloc_ext(style);
|
||||
style->ext->transition_prop_4 = value._int;
|
||||
style->ext->has_transition_prop_4 = 1;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_5:
|
||||
_alloc_ext(style);
|
||||
style->ext->transition_prop_5 = value._int;
|
||||
style->ext->has_transition_prop_5 = 1;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_6:
|
||||
_alloc_ext(style);
|
||||
style->ext->transition_prop_6 = value._int;
|
||||
style->ext->has_transition_prop_6 = 1;
|
||||
style->ext->transition = value._ptr;
|
||||
style->ext->has_transition = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -769,32 +735,8 @@ static bool get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_va
|
||||
if(style->ext && style->ext->has_content_ofs_y) { value->_int = style->ext->content_ofs_x; return true; }
|
||||
break;
|
||||
|
||||
case LV_STYLE_TRANSITION_TIME:
|
||||
if(style->ext && style->ext->has_transition_time) { value->_int = style->ext->transition_time; return true; }
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_DELAY:
|
||||
if(style->ext && style->ext->has_transition_delay) { value->_int = style->ext->transition_delay; return true; }
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PATH:
|
||||
if(style->ext && style->ext->has_transition_path) { value->_ptr = style->ext->transition_path; return true; }
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_1:
|
||||
if(style->ext && style->ext->has_transition_prop_1) { value->_int = style->ext->transition_prop_1; return true; }
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_2:
|
||||
if(style->ext && style->ext->has_transition_prop_2) { value->_int = style->ext->transition_prop_2; return true; }
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_3:
|
||||
if(style->ext && style->ext->has_transition_prop_3) { value->_int = style->ext->transition_prop_3; return true; }
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_4:
|
||||
if(style->ext && style->ext->has_transition_prop_4) { value->_int = style->ext->transition_prop_4; return true; }
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_5:
|
||||
if(style->ext && style->ext->has_transition_prop_5) { value->_int = style->ext->transition_prop_5; return true; }
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_6:
|
||||
if(style->ext && style->ext->has_transition_prop_6) { value->_int = style->ext->transition_prop_6; return true; }
|
||||
case LV_STYLE_TRANSITION:
|
||||
if(style->ext && style->ext->has_transition) { value->_ptr = style->ext->transition; return true; }
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -1012,32 +954,8 @@ static bool remove_prop(lv_style_t * style, lv_style_prop_t prop)
|
||||
if(style->ext) style->ext->has_content_src = 0;
|
||||
break;
|
||||
|
||||
case LV_STYLE_TRANSITION_TIME:
|
||||
if(style->ext) style->ext->has_transition_time = 0;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_DELAY:
|
||||
if(style->ext) style->ext->has_transition_delay = 0;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PATH:
|
||||
if(style->ext) style->ext->has_transition_path = 0;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_1:
|
||||
if(style->ext) style->ext->has_transition_prop_1 = 0;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_2:
|
||||
if(style->ext) style->ext->has_transition_prop_2 = 0;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_3:
|
||||
if(style->ext) style->ext->has_transition_prop_3 = 0;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_4:
|
||||
if(style->ext) style->ext->has_transition_prop_4 = 0;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_5:
|
||||
if(style->ext) style->ext->has_transition_prop_5 = 0;
|
||||
break;
|
||||
case LV_STYLE_TRANSITION_PROP_6:
|
||||
if(style->ext) style->ext->has_transition_prop_6 = 0;
|
||||
case LV_STYLE_TRANSITION:
|
||||
if(style->ext) style->ext->has_transition = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -37,8 +37,6 @@ LV_EXPORT_CONST_INT(LV_RADIUS_CIRCLE);
|
||||
#define LV_STYLE_PROP_LAYOUT_REFR (1 << 12)
|
||||
#define LV_STYLE_PROP_FILTER (1 << 13)
|
||||
|
||||
#define LV_STYLE_TRANS_NUM_MAX 6
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
@ -167,34 +165,22 @@ typedef enum {
|
||||
LV_STYLE_CONTENT_OFS_X = 92 | LV_STYLE_PROP_EXT_DRAW,
|
||||
LV_STYLE_CONTENT_OFS_Y = 93 | LV_STYLE_PROP_EXT_DRAW,
|
||||
|
||||
LV_STYLE_TRANSITION_TIME = 100,
|
||||
LV_STYLE_TRANSITION_DELAY = 101,
|
||||
LV_STYLE_TRANSITION_PATH = 102,
|
||||
LV_STYLE_TRANSITION_PROP_1 = 103,
|
||||
LV_STYLE_TRANSITION_PROP_2 = 104,
|
||||
LV_STYLE_TRANSITION_PROP_3 = 105,
|
||||
LV_STYLE_TRANSITION_PROP_4 = 106,
|
||||
LV_STYLE_TRANSITION_PROP_5 = 107,
|
||||
LV_STYLE_TRANSITION_PROP_6 = 108,
|
||||
LV_STYLE_TRANSITION = 100,
|
||||
|
||||
_LV_STYLE_LAST_BUIL_IN_PROP,
|
||||
|
||||
LV_STYLE_PROP_ALL = 0xFFFF
|
||||
}lv_style_prop_t;
|
||||
|
||||
struct _lv_style_transiton_t;
|
||||
|
||||
typedef struct {
|
||||
lv_color_filter_cb_t color_filter_cb;
|
||||
const lv_anim_path_t * transition_path;
|
||||
const struct _lv_style_transiton_t * transition;
|
||||
const char * content_text;
|
||||
|
||||
uint16_t transition_time;
|
||||
uint16_t transition_delay;
|
||||
uint16_t transition_prop_1;
|
||||
uint16_t transition_prop_2;
|
||||
uint16_t transition_prop_3;
|
||||
uint16_t transition_prop_4;
|
||||
uint16_t transition_prop_5;
|
||||
uint16_t transition_prop_6;
|
||||
|
||||
lv_color_t bg_grad_color;
|
||||
lv_color_t outline_color;
|
||||
@ -307,18 +293,17 @@ typedef struct {
|
||||
uint32_t has_content_ofs_x :1;
|
||||
uint32_t has_content_ofs_y :1;
|
||||
|
||||
uint32_t has_transition_time :1;
|
||||
uint32_t has_transition_delay :1;
|
||||
uint32_t has_transition_path :1;
|
||||
uint32_t has_transition_prop_1 :1;
|
||||
uint32_t has_transition_prop_2 :1;
|
||||
uint32_t has_transition_prop_3 :1;
|
||||
uint32_t has_transition_prop_4 :1;
|
||||
uint32_t has_transition_prop_5 :1;
|
||||
uint32_t has_transition_prop_6 :1;
|
||||
uint32_t has_transition :1;
|
||||
}lv_style_ext_t;
|
||||
|
||||
|
||||
typedef struct _lv_style_transiton_t{
|
||||
const lv_style_prop_t * props;
|
||||
const lv_anim_path_t * path;
|
||||
uint32_t time;
|
||||
uint32_t delay;
|
||||
}lv_style_transiton_t;
|
||||
|
||||
LV_CLASS_DECLARE_START(lv_style, lv_base);
|
||||
|
||||
#define _lv_style_constructor void (*constructor)(struct _lv_style_t * style)
|
||||
@ -398,6 +383,9 @@ void lv_style_reset(lv_style_t * style);
|
||||
void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value);
|
||||
|
||||
bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value);
|
||||
|
||||
void lv_style_transition_init(lv_style_transiton_t * tr, const lv_style_prop_t * props, const lv_anim_path_t * path, uint32_t time, uint32_t delay);
|
||||
|
||||
/**
|
||||
* Remove a property from a style
|
||||
* @param style pointer to a style
|
||||
@ -620,33 +608,8 @@ static inline void lv_style_set_content_ofs_x(lv_style_t * style, lv_coord_t val
|
||||
static inline void lv_style_set_content_ofs_y(lv_style_t * style, lv_coord_t value) {
|
||||
lv_style_value_t v = {._int = value}; lv_style_set_prop(style, LV_STYLE_CONTENT_OFS_Y, v); }
|
||||
|
||||
static inline void lv_style_set_transition_time(lv_style_t * style, uint16_t value) {
|
||||
lv_style_value_t v = {._int = value}; lv_style_set_prop(style, LV_STYLE_TRANSITION_TIME, v); }
|
||||
|
||||
static inline void lv_style_set_transition_delay(lv_style_t * style, uint16_t value) {
|
||||
lv_style_value_t v = {._int = value}; lv_style_set_prop(style, LV_STYLE_TRANSITION_DELAY, v); }
|
||||
|
||||
static inline void lv_style_set_transition_path(lv_style_t * style, const lv_anim_path_t * value) {
|
||||
lv_style_value_t v = {._ptr = value}; lv_style_set_prop(style, LV_STYLE_TRANSITION_PATH, v); }
|
||||
|
||||
static inline void lv_style_set_transition_prop_1(lv_style_t * style, lv_style_prop_t value) {
|
||||
lv_style_value_t v = {._int = value}; lv_style_set_prop(style, LV_STYLE_TRANSITION_PROP_1, v); }
|
||||
|
||||
static inline void lv_style_set_transition_prop_2(lv_style_t * style, lv_style_prop_t value) {
|
||||
lv_style_value_t v = {._int = value}; lv_style_set_prop(style, LV_STYLE_TRANSITION_PROP_2, v); }
|
||||
|
||||
static inline void lv_style_set_transition_prop_3(lv_style_t * style, lv_style_prop_t value) {
|
||||
lv_style_value_t v = {._int = value}; lv_style_set_prop(style, LV_STYLE_TRANSITION_PROP_3, v); }
|
||||
|
||||
static inline void lv_style_set_transition_prop_4(lv_style_t * style, lv_style_prop_t value) {
|
||||
lv_style_value_t v = {._int = value}; lv_style_set_prop(style, LV_STYLE_TRANSITION_PROP_4, v); }
|
||||
|
||||
static inline void lv_style_set_transition_prop_5(lv_style_t * style, lv_style_prop_t value) {
|
||||
lv_style_value_t v = {._int = value}; lv_style_set_prop(style, LV_STYLE_TRANSITION_PROP_5, v); }
|
||||
|
||||
static inline void lv_style_set_transition_prop_6(lv_style_t * style, lv_style_prop_t value) {
|
||||
lv_style_value_t v = {._int = value}; lv_style_set_prop(style, LV_STYLE_TRANSITION_PROP_6, v); }
|
||||
|
||||
static inline void lv_style_set_transition(lv_style_t * style, const lv_style_transiton_t * value) {
|
||||
lv_style_value_t v = {._ptr = value}; lv_style_set_prop(style, LV_STYLE_TRANSITION, v); }
|
||||
|
||||
|
||||
static inline void lv_style_set_pad_ver(lv_style_t * style, lv_coord_t value)
|
||||
|
@ -100,6 +100,7 @@ typedef struct {
|
||||
lv_style_t circle;
|
||||
lv_style_t no_radius;
|
||||
lv_style_t clip_corner;
|
||||
lv_style_t grow;
|
||||
|
||||
/*Parts*/
|
||||
lv_style_t knob;
|
||||
@ -187,6 +188,19 @@ static bool inited;
|
||||
|
||||
static void basic_init(void)
|
||||
{
|
||||
const static lv_style_prop_t trans_props[] = {
|
||||
LV_STYLE_BG_OPA, LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_TRANSFORM_HEIGHT, LV_STYLE_COLOR_FILTER_OPA, LV_STYLE_COLOR_FILTER_CB, 0
|
||||
};
|
||||
|
||||
static lv_style_transiton_t trans_delayed;
|
||||
lv_style_transition_init(&trans_delayed, trans_props, &lv_anim_path_def, TRANSITION_TIME, TRANSITION_TIME / 2);
|
||||
|
||||
static lv_style_transiton_t trans_slow;
|
||||
lv_style_transition_init(&trans_slow, trans_props, &lv_anim_path_def, TRANSITION_TIME * 2, 0);
|
||||
|
||||
static lv_style_transiton_t trans_normal;
|
||||
lv_style_transition_init(&trans_normal, trans_props, &lv_anim_path_def, TRANSITION_TIME, 0);
|
||||
|
||||
style_init_reset(&styles->scrollbar);
|
||||
lv_style_set_bg_opa(&styles->scrollbar, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&styles->scrollbar, (IS_LIGHT ? lv_color_hex(0xcccfd1) : lv_color_hex(0x777f85)));
|
||||
@ -195,12 +209,10 @@ static void basic_init(void)
|
||||
lv_style_set_margin_right(&styles->scrollbar, LV_DPX(7));
|
||||
lv_style_set_margin_top(&styles->scrollbar, LV_DPX(7));
|
||||
lv_style_set_bg_opa(&styles->scrollbar, LV_OPA_50);
|
||||
lv_style_set_transition_prop_6(&styles->scrollbar, LV_STYLE_BG_OPA);
|
||||
lv_style_set_transition_time(&styles->scrollbar, TRANSITION_TIME * 2);
|
||||
lv_style_set_transition(&styles->scrollbar, &trans_slow);
|
||||
|
||||
style_init_reset(&styles->scrollbar_scrolled);
|
||||
lv_style_set_bg_opa(&styles->scrollbar_scrolled, LV_OPA_COVER);
|
||||
lv_style_set_transition_time(&styles->scrollbar_scrolled, TRANSITION_TIME);
|
||||
|
||||
style_init_reset(&styles->scr);
|
||||
lv_style_set_bg_opa(&styles->scr, LV_OPA_COVER);
|
||||
@ -216,10 +228,7 @@ static void basic_init(void)
|
||||
lv_style_set_border_post(&styles->card, true);
|
||||
lv_style_set_text_color(&styles->card, CARD_TEXT_COLOR);
|
||||
lv_style_set_img_recolor(&styles->card, CARD_TEXT_COLOR);
|
||||
|
||||
lv_style_set_pad_all(&styles->card, PAD_DEF);
|
||||
lv_style_set_transition_time(&styles->card, TRANSITION_TIME);
|
||||
lv_style_set_transition_prop_6(&styles->card, LV_STYLE_BORDER_COLOR);
|
||||
|
||||
style_init_reset(&styles->focus_border);
|
||||
lv_style_set_border_color(&styles->focus_border, theme.color_primary);
|
||||
@ -246,11 +255,7 @@ static void basic_init(void)
|
||||
lv_style_set_img_recolor(&styles->btn, CARD_TEXT_COLOR);
|
||||
lv_style_set_pad_hor(&styles->btn, LV_DPX(40));
|
||||
lv_style_set_pad_ver(&styles->btn, LV_DPX(15));
|
||||
lv_style_set_transition_prop_5(&styles->btn, LV_STYLE_COLOR_FILTER_OPA);
|
||||
lv_style_set_transition_time(&styles->btn, TRANSITION_TIME);
|
||||
lv_style_set_transition_delay(&styles->btn, TRANSITION_TIME);
|
||||
lv_style_set_color_filter_cb(&styles->btn, lv_color_change_lightness);
|
||||
lv_style_set_color_filter_opa(&styles->btn, LV_OPA_50);
|
||||
lv_style_set_transition(&styles->btn, &trans_delayed); /*Go back to default state with delay*/
|
||||
|
||||
|
||||
style_init_reset(&styles->btn_color);
|
||||
@ -263,13 +268,14 @@ static void basic_init(void)
|
||||
lv_style_set_bg_color(&styles->btn_color_checked, BTN_CHK_PR_COLOR);
|
||||
|
||||
style_init_reset(&styles->pressed);
|
||||
lv_style_set_color_filter_opa(&styles->pressed, LV_OPA_40);
|
||||
lv_style_set_transition_delay(&styles->pressed, 0);
|
||||
lv_style_set_color_filter_cb(&styles->pressed, lv_color_darken);
|
||||
lv_style_set_color_filter_opa(&styles->pressed, LV_OPA_20);
|
||||
lv_style_set_transition(&styles->pressed, &trans_normal);
|
||||
|
||||
style_init_reset(&styles->disabled);
|
||||
lv_style_set_color_filter_opa(&styles->disabled, LV_OPA_70);
|
||||
lv_style_set_transition_time(&styles->disabled, 0);
|
||||
lv_style_set_transition_delay(&styles->disabled, 0);
|
||||
lv_style_set_color_filter_cb(&styles->disabled, lv_color_lighten);
|
||||
lv_style_set_color_filter_opa(&styles->disabled, LV_OPA_40);
|
||||
lv_style_set_transition(&styles->disabled, &trans_normal);
|
||||
|
||||
style_init_reset(&styles->clip_corner);
|
||||
lv_style_set_clip_corner(&styles->clip_corner, true);
|
||||
@ -292,6 +298,10 @@ static void basic_init(void)
|
||||
style_init_reset(&styles->circle);
|
||||
lv_style_set_radius(&styles->circle, LV_RADIUS_CIRCLE);
|
||||
|
||||
style_init_reset(&styles->grow);
|
||||
lv_style_set_transform_width(&styles->grow, LV_DPX(5));
|
||||
lv_style_set_transform_height(&styles->grow, LV_DPX(5));
|
||||
|
||||
style_init_reset(&styles->knob);
|
||||
lv_style_set_bg_color(&styles->knob, IS_LIGHT ? theme.color_primary : LV_COLOR_WHITE);
|
||||
lv_style_set_bg_opa(&styles->knob, LV_OPA_COVER);
|
||||
@ -698,6 +708,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->btn);
|
||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->btn_color);
|
||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_PRESSED, &styles->pressed);
|
||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_PRESSED, &styles->grow);
|
||||
lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_CHECKED, &styles->btn_color_checked);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user