From b1677205b0413e8c0776734b4de9f9f03fd4e8e7 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 27 Feb 2021 12:50:45 +0100 Subject: [PATCH] minor fixes --- src/lv_core/lv_obj.c | 130 +++++++++++++++++++---------------- src/lv_core/lv_obj.h | 8 --- src/lv_widgets/lv_dropdown.c | 2 + 3 files changed, 71 insertions(+), 69 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 7c90fa887..97df1d4cf 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -59,14 +59,15 @@ typedef struct { /********************** * STATIC PROTOTYPES **********************/ +static void lv_obj_constructor(lv_obj_t * obj, const lv_obj_t * copy); +static void lv_obj_destructor(lv_obj_t * obj); static lv_draw_res_t lv_obj_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode); static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param); static void draw_scrollbar(lv_obj_t * obj, const lv_area_t * clip_area); static lv_res_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc); static bool obj_valid_child(const lv_obj_t * parent, const lv_obj_t * obj_to_find); +static void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state); static void base_dir_refr_children(lv_obj_t * obj); -static void lv_obj_constructor(lv_obj_t * obj, const lv_obj_t * copy); -static void lv_obj_destructor(lv_obj_t * obj); /********************** * STATIC VARIABLES @@ -334,65 +335,6 @@ void lv_obj_clear_flag(lv_obj_t * obj, lv_obj_flag_t f) if(f & LV_OBJ_FLAG_IGNORE_LAYOUT) lv_signal_send(lv_obj_get_parent(obj), LV_SIGNAL_CHILD_CHG, obj); } -void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state) -{ - if(obj->state == new_state) return; - - LV_ASSERT_OBJ(obj, MY_CLASS); - - lv_state_t prev_state = obj->state; - obj->state = new_state; - - _lv_style_state_cmp_t cmp_res = _lv_obj_style_state_compare(obj, prev_state, new_state); - /*If there is no difference in styles there is nothing else to do*/ - if(cmp_res == _LV_STYLE_STATE_CMP_SAME) return; - - 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; - - lv_style_value_t v; - if(lv_style_get_prop(obj_style->style, LV_STYLE_TRANSITION, &v) == false) continue; - const lv_style_transition_dsc_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_style_create_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); - - lv_obj_invalidate(obj); - - if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_LAYOUT) lv_obj_refresh_style(obj, LV_PART_ANY, LV_STYLE_PROP_ALL); - else if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD) lv_obj_refresh_ext_draw_size(obj); -} - void lv_obj_add_state(lv_obj_t * obj, lv_state_t state) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -1008,6 +950,72 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) return res; } +/** + * Set the state (fully overwrite) of an object. + * If specified in the styles, transition animations will be started from the previous state to the current. + * @param obj pointer to an object + * @param state the new state + */ +static void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state) +{ + if(obj->state == new_state) return; + + LV_ASSERT_OBJ(obj, MY_CLASS); + + lv_state_t prev_state = obj->state; + obj->state = new_state; + + _lv_style_state_cmp_t cmp_res = _lv_obj_style_state_compare(obj, prev_state, new_state); + /*If there is no difference in styles there is nothing else to do*/ + if(cmp_res == _LV_STYLE_STATE_CMP_SAME) return; + + 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; + + lv_style_value_t v; + if(lv_style_get_prop(obj_style->style, LV_STYLE_TRANSITION, &v) == false) continue; + const lv_style_transition_dsc_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_style_create_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); + + lv_obj_invalidate(obj); + + if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_LAYOUT) lv_obj_refresh_style(obj, LV_PART_ANY, LV_STYLE_PROP_ALL); + else if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD) lv_obj_refresh_ext_draw_size(obj); +} + + static void base_dir_refr_children(lv_obj_t * obj) { uint32_t i; diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 8d3f9d874..3472f6750 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -376,14 +376,6 @@ void lv_obj_add_flag(lv_obj_t * obj, lv_obj_flag_t f); */ void lv_obj_clear_flag(lv_obj_t * obj, lv_obj_flag_t f); -/** - * Set the state (fully overwrite) of an object. - * If specified in the styles, transition animations will be started from the previous state to the current. - * @param obj pointer to an object - * @param state the new state - */ -void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state); - /** * Add one or more states to the object. The other state bits will remain unchanged. diff --git a/src/lv_widgets/lv_dropdown.c b/src/lv_widgets/lv_dropdown.c index cdd3c3ad3..70b63d4d2 100644 --- a/src/lv_widgets/lv_dropdown.c +++ b/src/lv_widgets/lv_dropdown.c @@ -541,6 +541,7 @@ static void lv_dropdown_constructor(lv_obj_t * obj, const lv_obj_t * copy) if(copy == NULL) { + lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS); lv_obj_set_width(obj, LV_DPX(150)); lv_dropdown_set_options_static(obj, "Option 1\nOption 2\nOption 3"); } @@ -764,6 +765,7 @@ static lv_draw_res_t lv_dropdown_list_draw(lv_obj_t * list_obj, const lv_area_t static void lv_dropdown_list_constructor(lv_obj_t * obj, const lv_obj_t * copy) { LV_UNUSED(copy); + lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS); lv_label_create(obj, NULL); }