From de1683a4ec443ceb805d8baa6a090d5e412e2ce1 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 19 Dec 2019 23:16:53 +0100 Subject: [PATCH] children inherit obj state --- src/lv_core/lv_obj.c | 51 ++++++++++++++++++++++---------------- src/lv_core/lv_obj.h | 4 +-- src/lv_draw/lv_draw_rect.h | 26 +++++++++++++------ src/lv_objx/lv_btn.c | 5 ++-- src/lv_objx/lv_label.c | 5 ++-- 5 files changed, 55 insertions(+), 36 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 68f1f99d9..ff874f0cd 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -53,7 +53,7 @@ typedef struct _lv_event_temp_data static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff); static inline lv_res_t get_style_prop_core(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop, void * out); static void report_style_mod_core(void * style_p, lv_obj_t * obj); -static void refresh_children_style(lv_obj_t * obj); +static void refresh_children_style(lv_obj_t * obj, uint8_t type); static void delete_children(lv_obj_t * obj); static void base_dir_refr_children(lv_obj_t * obj); static void lv_event_mark_deleted(lv_obj_t * obj); @@ -1253,7 +1253,7 @@ void lv_obj_add_style_class(lv_obj_t * obj, uint8_t type, lv_style_t * style) } /** - * Notify an object about its style is modified + * Notify an object (and its children) about its style is modified * @param obj pointer to an object */ void lv_obj_refresh_style(lv_obj_t * obj, uint8_t type) @@ -1264,7 +1264,7 @@ void lv_obj_refresh_style(lv_obj_t * obj, uint8_t type) obj->signal_cb(obj, LV_SIGNAL_STYLE_CHG, &type); lv_obj_invalidate(obj); - refresh_children_style(obj, type) + refresh_children_style(obj, type); } /** @@ -2070,6 +2070,9 @@ lv_style_dsc_t * lv_obj_get_style(const lv_obj_t * obj, uint8_t type) lv_style_value_t lv_obj_get_style_value(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop) { + uint8_t state = lv_obj_get_state(obj); + prop = (uint16_t)prop + ((uint16_t)state << LV_STYLE_STATE_POS); + lv_style_attr_t attr; attr.full = prop >> 8; @@ -2129,6 +2132,9 @@ lv_style_value_t lv_obj_get_style_value(const lv_obj_t * obj, uint8_t type, lv_s lv_color_t lv_obj_get_style_color(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop) { + uint8_t state = lv_obj_get_state(obj); + prop = (uint16_t)prop + ((uint16_t)state << LV_STYLE_STATE_POS); + lv_style_attr_t attr; attr.full = prop >> 8; @@ -2187,6 +2193,9 @@ lv_color_t lv_obj_get_style_color(const lv_obj_t * obj, uint8_t type, lv_style_p lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop) { + uint8_t state = lv_obj_get_state(obj); + prop = (uint16_t)prop + ((uint16_t)state << LV_STYLE_STATE_POS); + lv_style_attr_t attr; attr.full = prop >> 8; @@ -2241,6 +2250,9 @@ lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t type, lv_style_prope void * lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t type, lv_style_property_t prop) { + uint8_t state = lv_obj_get_state(obj); + prop = (uint16_t)prop + ((uint16_t)state << LV_STYLE_STATE_POS); + lv_style_attr_t attr; attr.full = prop >> 8; @@ -2680,32 +2692,27 @@ static void lv_obj_del_async_cb(void * obj) * @note Only the relevant fields will be set. * E.g. if `border width == 0` the other border properties won't be evaluated. */ -void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t type, lv_obj_state_t state, lv_draw_rect_dsc_t * draw_dsc) +void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t type, lv_draw_rect_dsc_t * draw_dsc) { - lv_style_state_t style_state = state << LV_STYLE_STATE_POS; + draw_dsc->radius = lv_obj_get_style_value(obj, type, LV_STYLE_RADIUS); - draw_dsc->radius = lv_obj_get_style_value(obj, type, LV_STYLE_RADIUS | style_state); + draw_dsc->bg_color = lv_obj_get_style_color(obj, type, LV_STYLE_BG_COLOR); - draw_dsc->bg_color = lv_obj_get_style_color(obj, type, LV_STYLE_BG_COLOR | style_state); - - draw_dsc->border_width = lv_obj_get_style_value(obj, type, LV_STYLE_BORDER_WIDTH | style_state); + draw_dsc->border_width = lv_obj_get_style_value(obj, type, LV_STYLE_BORDER_WIDTH); if(draw_dsc->border_width) { - draw_dsc->border_opa = lv_obj_get_style_opa(obj, type, LV_STYLE_BORDER_OPA | style_state); + draw_dsc->border_opa = lv_obj_get_style_opa(obj, type, LV_STYLE_BORDER_OPA); if(draw_dsc->border_opa >= LV_OPA_MIN) { - draw_dsc->border_part = lv_obj_get_style_value(obj, type, LV_STYLE_BORDER_PART | style_state); - draw_dsc->border_color = lv_obj_get_style_color(obj, type, LV_STYLE_BORDER_COLOR | style_state); + draw_dsc->border_part = lv_obj_get_style_value(obj, type, LV_STYLE_BORDER_PART); + draw_dsc->border_color = lv_obj_get_style_color(obj, type, LV_STYLE_BORDER_COLOR); } } } -void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t type, lv_obj_state_t state, lv_draw_label_dsc_t * draw_dsc) +void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t type, lv_draw_label_dsc_t * draw_dsc) { + draw_dsc->color = lv_obj_get_style_color(obj, type, LV_STYLE_TEXT_COLOR); - lv_style_state_t style_state = state << LV_STYLE_STATE_POS; - - draw_dsc->color = lv_obj_get_style_color(obj, type, LV_STYLE_TEXT_COLOR| style_state); - - draw_dsc->font = lv_obj_get_style_ptr(obj, type, LV_STYLE_FONT | style_state); + draw_dsc->font = lv_obj_get_style_ptr(obj, type, LV_STYLE_FONT); } /** @@ -2757,7 +2764,7 @@ static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area else if(mode == LV_DESIGN_DRAW_MAIN) { lv_draw_rect_dsc_t draw_dsc; lv_draw_rect_dsc_init(&draw_dsc); - lv_obj_init_draw_rect_dsc(obj, LV_OBJ_STYLE_MAIN, lv_obj_get_state(obj), &draw_dsc); + lv_obj_init_draw_rect_dsc(obj, LV_OBJ_STYLE_MAIN, &draw_dsc); lv_draw_rect(&obj->coords, clip_area, &draw_dsc, lv_obj_get_opa_scale(obj)); if(lv_obj_get_style_value(obj, LV_OBJ_STYLE_MAIN, LV_STYLE_BG_CLIP_CORNER)) { @@ -2874,8 +2881,10 @@ static void refresh_children_style(lv_obj_t * obj, uint8_t type) { lv_obj_t * child = lv_obj_get_child(obj, NULL); while(child != NULL) { - refresh_children_style(child); /*Check children too*/ - lv_obj_refresh_style(child); /*Notify the child about the style change*/ + refresh_children_style(child, type); /*Check children too*/ + lv_obj_invalidate(child); + child->signal_cb(child, LV_SIGNAL_STYLE_CHG, &type); + lv_obj_invalidate(child); child = lv_obj_get_child(obj, child); } } diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index a6c3084af..44caf45d8 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -1037,9 +1037,9 @@ lv_res_t lv_obj_handle_get_type_signal(lv_obj_type_t * buf, const char * name); * @note Only the relevant fields will be set. * E.g. if `border width == 0` the other border properties won't be evaluated. */ -void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t type, lv_obj_state_t state, lv_draw_rect_dsc_t * draw_dsc); +void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t type, lv_draw_rect_dsc_t * draw_dsc); -void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t type, lv_obj_state_t state, lv_draw_label_dsc_t * draw_dsc); +void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t type, lv_draw_label_dsc_t * draw_dsc); /********************** * MACROS diff --git a/src/lv_draw/lv_draw_rect.h b/src/lv_draw/lv_draw_rect.h index 9fd58a796..d71c641f0 100644 --- a/src/lv_draw/lv_draw_rect.h +++ b/src/lv_draw/lv_draw_rect.h @@ -25,17 +25,29 @@ extern "C" { **********************/ typedef struct { + lv_style_value_t radius; + + /*Background*/ lv_color_t bg_color; lv_color_t bg_grad_color; - lv_style_value_t border_width; - lv_color_t border_color; - lv_blend_mode_t border_blend_mode; + lv_grad_dir_t bg_grad_dir; + lv_blend_mode_t bg_blend_mode; lv_opa_t bg_opa; - lv_opa_t border_opa; - lv_style_value_t radius; + + /*Border*/ + lv_color_t border_color; + lv_style_value_t border_width; + lv_blend_mode_t border_blend_mode; lv_style_value_t border_part; - lv_style_value_t bg_grad_dir; - lv_style_value_t bg_blend_mode; + lv_opa_t border_opa; + + /*Shadow*/ + lv_color_t shadow_color; + lv_style_value_t shadow_blur; + lv_style_value_t shadow_ofs_x; + lv_style_value_t shadow_ofs_y; + lv_opa_t shadow_opa; + }lv_draw_rect_dsc_t; /********************** diff --git a/src/lv_objx/lv_btn.c b/src/lv_objx/lv_btn.c index 780a27e4a..bd0d3608d 100644 --- a/src/lv_objx/lv_btn.c +++ b/src/lv_objx/lv_btn.c @@ -452,11 +452,10 @@ static lv_design_res_t lv_btn_design(lv_obj_t * btn, const lv_area_t * clip_area } #else lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); - lv_obj_state_t state = lv_obj_get_state(btn); lv_draw_rect_dsc_t draw_dsc; lv_draw_rect_dsc_init(&draw_dsc); - lv_obj_init_draw_rect_dsc(btn, LV_OBJ_STYLE_MAIN, state, &draw_dsc); + lv_obj_init_draw_rect_dsc(btn, LV_OBJ_STYLE_MAIN, &draw_dsc); lv_draw_rect(&btn->coords, clip_area, &draw_dsc, lv_obj_get_opa_scale(btn)); @@ -580,7 +579,7 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) if(res != LV_RES_OK) return res; } } else { /*If dragged change back the state*/ - if(ext == LV_BTN_STATE_PR) { + if(state == LV_BTN_STATE_PR) { lv_btn_set_state(btn, LV_BTN_STATE_REL); } else if(state == LV_BTN_STATE_TGL_PR) { lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); diff --git a/src/lv_objx/lv_label.c b/src/lv_objx/lv_label.c index c8292581b..703586b30 100644 --- a/src/lv_objx/lv_label.c +++ b/src/lv_objx/lv_label.c @@ -1051,7 +1051,6 @@ static lv_design_res_t lv_label_design(lv_obj_t * label, const lv_area_t * clip_ lv_obj_get_coords(label, &coords); lv_label_ext_t * ext = lv_obj_get_ext_attr(label); - lv_obj_state_t state = lv_obj_get_state(label); if(ext->body_draw) { lv_area_t bg; lv_obj_get_coords(label, &bg); @@ -1067,7 +1066,7 @@ static lv_design_res_t lv_label_design(lv_obj_t * label, const lv_area_t * clip_ lv_draw_rect_dsc_t draw_rect_dsc; lv_draw_rect_dsc_init(&draw_rect_dsc); - lv_obj_init_draw_rect_dsc(label, LV_LABEL_STYLE_MAIN, state, &draw_rect_dsc); + lv_obj_init_draw_rect_dsc(label, LV_LABEL_STYLE_MAIN, &draw_rect_dsc); lv_draw_rect(&bg, clip_area, &draw_rect_dsc, lv_obj_get_opa_scale(label)); } @@ -1110,7 +1109,7 @@ static lv_design_res_t lv_label_design(lv_obj_t * label, const lv_area_t * clip_ label_draw_dsc.ofs_x = ext->offset.x; label_draw_dsc.ofs_y = ext->offset.y; label_draw_dsc.flag = flag; - lv_obj_init_draw_label_dsc(label, LV_LABEL_STYLE_MAIN, state, &label_draw_dsc); + lv_obj_init_draw_label_dsc(label, LV_LABEL_STYLE_MAIN, &label_draw_dsc); lv_draw_label(&coords, clip_area, &label_draw_dsc, ext->text, opa_scale, hint);