diff --git a/Kconfig b/Kconfig index 56691a9c40..65b9918b43 100644 --- a/Kconfig +++ b/Kconfig @@ -55,7 +55,6 @@ menu "LVGL configuration" config LV_COLOR_CHROMA_KEY_HEX hex "Images pixels with this color will not be drawn (if they are chroma keyed)." - depends on LV_COLOR_SCREEN_TRANSP range 0x000000 0xFFFFFF default 0x00FF00 help diff --git a/src/core/lv_obj.c b/src/core/lv_obj.c index c27f67bb90..f8f5b0a8b5 100644 --- a/src/core/lv_obj.c +++ b/src/core/lv_obj.c @@ -685,19 +685,17 @@ static void lv_obj_event(const lv_obj_class_t * class_p, lv_event_t * e) lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED | LV_STATE_FOCUS_KEY); } else if(code == LV_EVENT_SIZE_CHANGED) { - uint32_t i; - for(i = 0; i < lv_obj_get_child_cnt(obj); i++) { - lv_obj_t * child = lv_obj_get_child(obj, i); - - lv_obj_refr_size(child); - lv_obj_refr_pos(child); - } - lv_coord_t align = lv_obj_get_style_align(obj, LV_PART_MAIN); uint16_t layout = lv_obj_get_style_layout(obj, LV_PART_MAIN); if(layout || align) { lv_obj_mark_layout_as_dirty(obj); } + + uint32_t i; + for(i = 0; i < lv_obj_get_child_cnt(obj); i++) { + lv_obj_t * child = lv_obj_get_child(obj, i); + lv_obj_mark_layout_as_dirty(child); + } } else if(code == LV_EVENT_CHILD_CHANGED) { lv_coord_t w = lv_obj_get_style_width(obj, LV_PART_MAIN); @@ -723,20 +721,6 @@ static void lv_obj_event(const lv_obj_class_t * class_p, lv_event_t * e) lv_coord_t d = lv_obj_calculate_ext_draw_size(obj, LV_PART_MAIN); *s = LV_MAX(*s, d); } - else if(code == LV_EVENT_STYLE_CHANGED) { - /*Padding might have changed so the layout should be recalculated*/ - uint32_t i; - for(i = 0; i < lv_obj_get_child_cnt(obj); i++) { - lv_obj_t * child = lv_obj_get_child(obj, i); - - lv_obj_refr_size(child); - lv_obj_refr_pos(child); - } - - lv_obj_mark_layout_as_dirty(obj); - - lv_obj_refresh_ext_draw_size(obj); - } else if(code == LV_EVENT_DRAW_MAIN || code == LV_EVENT_DRAW_POST || code == LV_EVENT_COVER_CHECK) { lv_obj_draw(e); } diff --git a/src/core/lv_obj.h b/src/core/lv_obj.h index 9dab4429f0..4b7a63ef0c 100644 --- a/src/core/lv_obj.h +++ b/src/core/lv_obj.h @@ -164,7 +164,6 @@ typedef struct _lv_obj_t { void * user_data; #endif lv_area_t coords; - lv_point_t self_size; lv_obj_flag_t flags; lv_state_t state; uint16_t layout_inv :1; diff --git a/src/core/lv_obj_pos.c b/src/core/lv_obj_pos.c index 468b638475..f39d256194 100644 --- a/src/core/lv_obj_pos.c +++ b/src/core/lv_obj_pos.c @@ -87,6 +87,7 @@ void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y) bool lv_obj_refr_size(lv_obj_t * obj) { + LV_ASSERT_OBJ(obj, MY_CLASS); /*If the width or height is set by a layout do not modify them*/ @@ -190,7 +191,6 @@ bool lv_obj_refr_size(lv_obj_t * obj) /*Invalidate the new area*/ lv_obj_invalidate(obj); - /*Be sure the bottom side is not remains scrolled in*/ /*With snapping the content can't be scrolled in*/ if(lv_obj_get_scroll_snap_y(obj) == LV_SCROLL_SNAP_NONE) { @@ -592,22 +592,25 @@ void lv_obj_get_content_coords(const lv_obj_t * obj, lv_area_t * area) lv_coord_t lv_obj_get_self_width(struct _lv_obj_t * obj) { - return obj->self_size.x; + lv_point_t p = {0, LV_COORD_MIN}; + lv_event_send((lv_obj_t * )obj, LV_EVENT_REFR_SELF_SIZE, &p); + return p.x; } lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj) { - return obj->self_size.y; + lv_point_t p = {LV_COORD_MIN, 0}; + lv_event_send((lv_obj_t * )obj, LV_EVENT_REFR_SELF_SIZE, &p); + return p.y; } bool lv_obj_refresh_self_size(struct _lv_obj_t * obj) { - lv_obj_update_layout(obj); - obj->self_size.x = 0; - obj->self_size.y = 0; - lv_event_send(obj, LV_EVENT_REFR_SELF_SIZE, &obj->self_size); + lv_coord_t w_set = lv_obj_get_style_width(obj, LV_PART_MAIN); + lv_coord_t h_set = lv_obj_get_style_height(obj, LV_PART_MAIN); + if(w_set != LV_SIZE_CONTENT && h_set != LV_SIZE_CONTENT) return false; - lv_obj_refr_size(obj); + lv_obj_mark_layout_as_dirty(obj); return true; } @@ -944,7 +947,7 @@ static void layout_update_core(lv_obj_t * obj) if(obj->layout_inv == 0) return; - if(lv_obj_get_screen(obj) != obj) obj->layout_inv = 0; + obj->layout_inv = 0; lv_obj_refr_size(obj); lv_obj_refr_pos(obj); diff --git a/src/core/lv_obj_style.c b/src/core/lv_obj_style.c index a7c7397240..26cf31c6e7 100644 --- a/src/core/lv_obj_style.c +++ b/src/core/lv_obj_style.c @@ -173,14 +173,15 @@ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_selector_t selector, lv_style lv_part_t part = lv_obj_style_get_selector_part(selector); if((part == LV_PART_ANY || part == LV_PART_MAIN) && (prop == LV_STYLE_PROP_ANY || (prop & LV_STYLE_PROP_LAYOUT_REFR))) { - lv_event_send(obj, LV_EVENT_STYLE_CHANGED, NULL); /*To update layout*/ - if(obj->parent) obj->parent->layout_inv = 1; + lv_event_send(obj, LV_EVENT_STYLE_CHANGED, NULL); + lv_obj_mark_layout_as_dirty(obj); } if((part == LV_PART_ANY || part == LV_PART_MAIN) && (prop == LV_STYLE_PROP_ANY || (prop & LV_STYLE_PROP_PARENT_LAYOUT_REFR))) { lv_obj_t * parent = lv_obj_get_parent(obj); if(parent) lv_obj_mark_layout_as_dirty(parent); } - else if(prop & LV_STYLE_PROP_EXT_DRAW) { + + if(prop == LV_STYLE_PROP_ANY || (prop & LV_STYLE_PROP_EXT_DRAW)) { lv_obj_refresh_ext_draw_size(obj); } lv_obj_invalidate(obj); @@ -791,7 +792,6 @@ static void trans_anim_ready_cb(lv_anim_t * a) if(lv_style_is_empty(obj->styles[i].style)) { lv_obj_remove_style(obj, obj_style->style, obj_style->selector); - //trans_del(obj, obj_style->part, prop, NULL); } break; diff --git a/src/extra/layouts/flex/lv_flex.c b/src/extra/layouts/flex/lv_flex.c index dc1d8bba98..51ee161c2f 100644 --- a/src/extra/layouts/flex/lv_flex.c +++ b/src/extra/layouts/flex/lv_flex.c @@ -362,7 +362,10 @@ static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, i if(grow_size) { lv_coord_t s = 0; for(i = 0; i < t->grow_item_cnt; i++) { - if(t->grow_dsc[i].item == item) s = t->grow_dsc[i].final_size; + if(t->grow_dsc[i].item == item) { + s = t->grow_dsc[i].final_size; + break; + } } lv_area_t old_coords; lv_area_copy(&old_coords, &item->coords); diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index c16d0a8f8b..ec166cd55d 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -643,7 +643,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR); lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); } -#if LV_USE_BTN + #if LV_USE_BTN else if(lv_obj_check_type(obj, &lv_btn_class)) { lv_obj_add_style(obj, &styles->btn, 0); lv_obj_add_style(obj, &styles->bg_color_primary, 0); diff --git a/src/widgets/lv_label.c b/src/widgets/lv_label.c index 8f61a2f3a4..18ae9d3d56 100644 --- a/src/widgets/lv_label.c +++ b/src/widgets/lv_label.c @@ -46,7 +46,6 @@ static void lv_label_revert_dots(lv_obj_t * label); static bool lv_label_set_dot_tmp(lv_obj_t * label, char * data, uint32_t len); static char * lv_label_get_dot_tmp(lv_obj_t * label); static void lv_label_dot_tmp_free(lv_obj_t * label); -static void get_txt_coords(const lv_obj_t * label, lv_area_t * area); static void set_ofs_x_anim(void * obj, int32_t v); static void set_ofs_y_anim(void * obj, int32_t v); @@ -307,7 +306,7 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t } lv_area_t txt_coords; - get_txt_coords(obj, &txt_coords); + lv_obj_get_content_coords(obj, &txt_coords); lv_label_t * label = (lv_label_t *)obj; uint32_t line_start = 0; @@ -404,7 +403,7 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in) pos.y = pos_in->y - lv_obj_get_style_pad_top(obj, LV_PART_MAIN); lv_area_t txt_coords; - get_txt_coords(obj, &txt_coords); + lv_obj_get_content_coords(obj, &txt_coords); const char * txt = lv_label_get_text(obj); uint32_t line_start = 0; uint32_t new_line_start = 0; @@ -523,7 +522,7 @@ bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos) LV_ASSERT_NULL(pos); lv_area_t txt_coords; - get_txt_coords(obj, &txt_coords); + lv_obj_get_content_coords(obj, &txt_coords); const char * txt = lv_label_get_text(obj); lv_label_t * label = (lv_label_t*)obj; uint32_t line_start = 0; @@ -772,11 +771,10 @@ static void lv_label_event(const lv_obj_class_t * class_p, lv_event_t * e) lv_text_flag_t flag = LV_TEXT_FLAG_NONE; if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR; if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND; - if(lv_obj_get_style_width(obj, LV_PART_MAIN) == LV_SIZE_CONTENT && !obj->w_layout) flag |= LV_TEXT_FLAG_FIT; - lv_coord_t w = lv_obj_get_style_width(obj, LV_PART_MAIN); - if(flag & LV_TEXT_FLAG_FIT) w = LV_COORD_MAX; - else w = lv_obj_get_width(obj); + lv_coord_t w = lv_obj_get_content_width(obj); + if(lv_obj_get_style_width(obj, LV_PART_MAIN) == LV_SIZE_CONTENT && !obj->w_layout) w = LV_COORD_MAX; + else w = lv_obj_get_content_width(obj); lv_txt_get_size(&size, label->text, font, letter_space, line_space, w, flag); @@ -803,11 +801,7 @@ static void draw_main(lv_event_t * e) const lv_area_t * clip_area = lv_event_get_param(e); lv_area_t txt_coords; - get_txt_coords(obj, &txt_coords); - - lv_area_t txt_clip; - bool is_common = _lv_area_intersect(&txt_clip, clip_area, &txt_coords); - if(!is_common) return; + lv_obj_get_content_coords(obj, &txt_coords); lv_text_align_t align = lv_obj_get_style_text_align(obj, LV_PART_MAIN); lv_text_flag_t flag = LV_TEXT_FLAG_NONE; @@ -820,6 +814,7 @@ static void draw_main(lv_event_t * e) label_draw_dsc.ofs_x = label->offset.x; label_draw_dsc.ofs_y = label->offset.y; + label_draw_dsc.flag = flag; lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_draw_dsc); @@ -851,6 +846,16 @@ static void draw_main(lv_event_t * e) lv_draw_label_hint_t * hint = NULL; #endif + lv_area_t txt_clip; + bool is_common = _lv_area_intersect(&txt_clip, clip_area, clip_area); + if(!is_common) return; + + if(label->long_mode == LV_LABEL_LONG_WRAP) { + lv_coord_t s = lv_obj_get_scroll_top(obj); + lv_area_move(&txt_coords, 0, -s); + txt_coords.y2 = obj->coords.y2; + } + lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint); if(label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR) { @@ -890,7 +895,7 @@ static void lv_label_refr_text(lv_obj_t * obj) #endif lv_area_t txt_coords; - get_txt_coords(obj, &txt_coords); + lv_obj_get_content_coords(obj, &txt_coords); lv_coord_t max_w = lv_area_get_width(&txt_coords); const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN); lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN); @@ -1226,20 +1231,6 @@ static void lv_label_dot_tmp_free(lv_obj_t * obj) label->dot.tmp_ptr = NULL; } -static void get_txt_coords(const lv_obj_t * obj, lv_area_t * area) -{ - lv_obj_get_coords(obj, area); - - lv_coord_t left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN); - lv_coord_t right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN); - lv_coord_t top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN); - lv_coord_t bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN); - area->x1 += left; - area->x2 -= right; - area->y1 += top; - area->y2 -= bottom; -} - static void set_ofs_x_anim(void * obj, int32_t v) {