From d04d5ab4d4e539bffa679345eb1ace0b76747bc7 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 8 Apr 2020 11:12:06 +0200 Subject: [PATCH 1/2] add initials version of margin (style property) --- src/lv_core/lv_obj.c | 119 ++++++++++++++++++++++++++- src/lv_core/lv_obj.h | 58 ++++++++++++++ src/lv_core/lv_obj_style_dec.h | 4 + src/lv_core/lv_style.h | 10 ++- src/lv_themes/lv_theme_material.c | 91 +++++++++++---------- src/lv_widgets/lv_bar.c | 12 ++- src/lv_widgets/lv_cont.c | 129 +++++++++++++++++++----------- src/lv_widgets/lv_page.c | 49 +++++++++++- src/lv_widgets/lv_page.h | 30 ++++++- src/lv_widgets/lv_table.c | 88 ++++++++++++++++++-- src/lv_widgets/lv_table.h | 9 +++ src/lv_widgets/lv_textarea.c | 10 ++- 12 files changed, 501 insertions(+), 108 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index a97e99574..7855198c8 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -40,9 +40,8 @@ * DEFINES *********************/ #define LV_OBJX_NAME "lv_obj" -#define LV_OBJ_DEF_WIDTH (LV_DPI) -#define LV_OBJ_DEF_HEIGHT (2 * LV_DPI / 3) -#define LV_DRAW_RECT_CACHE_SIZE 0 +#define LV_OBJ_DEF_WIDTH (LV_DPI / 2) +#define LV_OBJ_DEF_HEIGHT (LV_DPI / 4) /********************** * TYPEDEFS @@ -801,6 +800,35 @@ void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h) lv_obj_set_size(obj, lv_obj_get_width(obj), h); } +/** + * Set the width of an object by taking the left and right margin into account. + * The object heigwidthht will be `obj_w = w - margon_left - margin_right` + * @param obj pointer to an object + * @param w new height including margins + */ +void lv_obj_set_width_margin(lv_obj_t * obj, lv_coord_t w) +{ + lv_style_int_t mleft = lv_obj_get_style_margin_left(obj, LV_OBJ_PART_MAIN); + lv_style_int_t mright = lv_obj_get_style_margin_right(obj, LV_OBJ_PART_MAIN); + + lv_obj_set_width(obj, w - mleft - mright); +} + +/** + * Set the height of an object by taking the top and bottom margin into account. + * The object height will be `obj_h = h - margon_top - margin_bottom` + * @param obj pointer to an object + * @param h new height including margins + */ +void lv_obj_set_height_margin(lv_obj_t * obj, lv_coord_t h) +{ + lv_style_int_t mtop = lv_obj_get_style_margin_top(obj, LV_OBJ_PART_MAIN); + lv_style_int_t mbottom = lv_obj_get_style_margin_bottom(obj, LV_OBJ_PART_MAIN); + + lv_obj_set_height(obj, h - mtop - mbottom); +} + + /** * Align an object to an other object. * @param obj pointer to an object to align @@ -1258,6 +1286,10 @@ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_property_t prop) case LV_STYLE_PAD_LEFT: case LV_STYLE_PAD_RIGHT: case LV_STYLE_PAD_INNER: + case LV_STYLE_MARGIN_TOP: + case LV_STYLE_MARGIN_BOTTOM: + case LV_STYLE_MARGIN_LEFT: + case LV_STYLE_MARGIN_RIGHT: case LV_STYLE_OUTLINE_WIDTH: case LV_STYLE_OUTLINE_PAD: case LV_STYLE_OUTLINE_OPA: @@ -1287,6 +1319,17 @@ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_property_t prop) if(real_refr) { lv_obj_invalidate(obj); obj->signal_cb(obj, LV_SIGNAL_STYLE_CHG, NULL); + + switch(prop) { + case LV_STYLE_PROP_ALL: + case LV_STYLE_MARGIN_TOP: + case LV_STYLE_MARGIN_BOTTOM: + case LV_STYLE_MARGIN_LEFT: + case LV_STYLE_MARGIN_RIGHT: + if(obj->parent) obj->parent->signal_cb(obj->parent, LV_SIGNAL_CHILD_CHG, NULL); + break; + } + lv_obj_invalidate(obj); if(prop == LV_STYLE_PROP_ALL || (prop & LV_STYLE_INHERIT_MASK)) @@ -2087,6 +2130,76 @@ lv_coord_t lv_obj_get_height_fit(const lv_obj_t * obj) return lv_obj_get_height(obj) - top - bottom; } +/** + * Get the height of an object by taking the top and bottom margin into account. + * The returned height will be `obj_h + margon_top + margin_bottom` + * @param obj pointer to an object + * @return the height including thee margins + */ +lv_coord_t lv_obj_get_height_margin(lv_obj_t * obj) +{ + lv_style_int_t mtop = lv_obj_get_style_margin_top(obj, LV_OBJ_PART_MAIN); + lv_style_int_t mbottom = lv_obj_get_style_margin_bottom(obj, LV_OBJ_PART_MAIN); + + return lv_obj_get_height(obj) + mtop + mbottom; +} + +/** + * Get the width of an object by taking the left and right margin into account. + * The returned width will be `obj_w + margon_left + margin_right` + * @param obj pointer to an object + * @return the height including thee margins + */ +lv_coord_t lv_obj_get_width_margin(lv_obj_t * obj) +{ + lv_style_int_t mleft = lv_obj_get_style_margin_left(obj, LV_OBJ_PART_MAIN); + lv_style_int_t mright = lv_obj_get_style_margin_right(obj, LV_OBJ_PART_MAIN); + + return lv_obj_get_width(obj) + mleft + mright; +} + +/** + * Set that width reduced by the left and right padding of the parent. + * @param obj pointer to an object + * @param div indicates how many columns are assumed. + * If 1 the width will be set the the parent's width + * If 2 only half parent width - inner padding of the parent + * If 3 only third parent width - 2 * inner padding of the parent + * @param span how many columns are combined + * @return the width according to the given parameters + */ +lv_coord_t lv_obj_get_width_grid(lv_obj_t * obj, uint8_t div, uint8_t span) +{ + lv_coord_t obj_w = lv_obj_get_width_fit(obj); + lv_style_int_t pinner = lv_obj_get_style_pad_inner(obj, LV_OBJ_PART_MAIN); + + lv_coord_t r = obj_w / div - (div - 1) * pinner; + + r = r * span + (span - 1) * pinner; + return r; +} + +/** + * Get that height reduced by the top and bottom padding of the parent. + * @param obj pointer to an object + * @param div indicates how many rows are assumed. + * If 1 the height will be set the the parent's height + * If 2 only half parent height - inner padding of the parent + * If 3 only third parent height - 2 * inner padding of the parent + * @param span how many rows are combined + * @return the height according to the given parameters + */ +lv_coord_t lv_obj_get_height_grid(lv_obj_t * obj, uint8_t div, uint8_t span) +{ + lv_coord_t obj_h = lv_obj_get_height_fit(obj); + lv_style_int_t pinner = lv_obj_get_style_pad_inner(obj, LV_OBJ_PART_MAIN); + + lv_coord_t r = obj_h / div - (div - 1) * pinner; + + r = r * span + (span - 1) * pinner; + return r; +} + /** * Get the automatic realign property of the object. * @param obj pointer to an object diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 6088f8d5a..2e526bafe 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -426,6 +426,22 @@ void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w); */ void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h); +/** + * Set the width of an object by taking the left and right margin into account. + * The object heigwidthht will be `obj_w = w - margon_left - margin_right` + * @param obj pointer to an object + * @param w new height including margins + */ +void lv_obj_set_width_margin(lv_obj_t * obj, lv_coord_t w); + +/** + * Set the height of an object by taking the top and bottom margin into account. + * The object height will be `obj_h = h - margon_top - margin_bottom` + * @param obj pointer to an object + * @param h new height including margins + */ +void lv_obj_set_height_margin(lv_obj_t * obj, lv_coord_t h); + /** * Align an object to an other object. * @param obj pointer to an object to align @@ -958,6 +974,48 @@ lv_coord_t lv_obj_get_width_fit(const lv_obj_t * obj); */ lv_coord_t lv_obj_get_height_fit(const lv_obj_t * obj); +/** + * Get the height of an object by taking the top and bottom margin into account. + * The returned height will be `obj_h + margon_top + margin_bottom` + * @param obj pointer to an object + * @return the height including thee margins + */ +lv_coord_t lv_obj_get_height_margin(lv_obj_t * obj); + +/** + * Get the width of an object by taking the left and right margin into account. + * The returned width will be `obj_w + margon_left + margin_right` + * @param obj pointer to an object + * @return the height including thee margins + */ +lv_coord_t lv_obj_get_width_margin(lv_obj_t * obj); + +/** + * Divide the width of the object and get the width of a given number of columns. + * Take paddings into account. + * @param obj pointer to an object + * @param div indicates how many columns are assumed. + * If 1 the width will be set the the parent's width + * If 2 only half parent width - inner padding of the parent + * If 3 only third parent width - 2 * inner padding of the parent + * @param span how many columns are combined + * @return the width according to the given parameters + */ +lv_coord_t lv_obj_get_width_grid(lv_obj_t * obj, uint8_t div, uint8_t span); + +/** + * Divide the height of the object and get the width of a given number of columns. + * Take paddings into account. + * @param obj pointer to an object + * @param div indicates how many rows are assumed. + * If 1 the height will be set the the parent's height + * If 2 only half parent height - inner padding of the parent + * If 3 only third parent height - 2 * inner padding of the parent + * @param span how many rows are combined + * @return the height according to the given parameters + */ +lv_coord_t lv_obj_get_height_grid(lv_obj_t * obj, uint8_t div, uint8_t span); + /** * Get the automatic realign property of the object. * @param obj pointer to an object diff --git a/src/lv_core/lv_obj_style_dec.h b/src/lv_core/lv_obj_style_dec.h index 27ba8e6da..4849140cf 100644 --- a/src/lv_core/lv_obj_style_dec.h +++ b/src/lv_core/lv_obj_style_dec.h @@ -146,6 +146,10 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(PAD_BOTTOM, pad_bottom, lv_style_int_t, _int, scal _LV_OBJ_STYLE_SET_GET_DECLARE(PAD_LEFT, pad_left, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(PAD_RIGHT, pad_right, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(PAD_INNER, pad_inner, lv_style_int_t, _int, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(MARGIN_TOP, margin_top, lv_style_int_t, _int, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(MARGIN_BOTTOM, margin_bottom, lv_style_int_t, _int, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(MARGIN_LEFT, margin_left, lv_style_int_t, _int, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(MARGIN_RIGHT, margin_right, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BG_BLEND_MODE, bg_blend_mode, lv_blend_mode_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BG_MAIN_STOP, bg_main_stop, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BG_GRAD_STOP, bg_grad_stop, lv_style_int_t, _int, scalar) diff --git a/src/lv_core/lv_style.h b/src/lv_core/lv_style.h index b9dafa4bc..85adf35e0 100644 --- a/src/lv_core/lv_style.h +++ b/src/lv_core/lv_style.h @@ -89,9 +89,9 @@ typedef union { } lv_style_attr_t; -#define LV_STYLE_ID_VALUE 0x0 /*max 8 pcs*/ -#define LV_STYLE_ID_COLOR 0x8 /*max 3 pcs*/ -#define LV_STYLE_ID_OPA 0xB /*max 3 pcs*/ +#define LV_STYLE_ID_VALUE 0x0 /*max 9 pcs*/ +#define LV_STYLE_ID_COLOR 0x9 /*max 3 pcs*/ +#define LV_STYLE_ID_OPA 0xC /*max 2 pcs*/ #define LV_STYLE_ID_PTR 0xE /*max 2 pcs*/ enum { @@ -108,6 +108,10 @@ enum { LV_STYLE_PROP_INIT(LV_STYLE_PAD_LEFT, 0x1, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_PAD_RIGHT, 0x1, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_PAD_INNER, 0x1, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_TOP, 0x1, LV_STYLE_ID_VALUE + 5, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_BOTTOM, 0x1, LV_STYLE_ID_VALUE + 6, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_LEFT, 0x1, LV_STYLE_ID_VALUE + 7, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_RIGHT, 0x1, LV_STYLE_ID_VALUE + 8, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_BG_BLEND_MODE, 0x2, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_BG_MAIN_STOP, 0x2, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), diff --git a/src/lv_themes/lv_theme_material.c b/src/lv_themes/lv_theme_material.c index 22e9ccf8a..0e47f1ff5 100644 --- a/src/lv_themes/lv_theme_material.c +++ b/src/lv_themes/lv_theme_material.c @@ -27,13 +27,13 @@ #define COLOR_BTN_PR (IS_LIGHT ? lv_color_mix(theme.color_primary, COLOR_BTN, LV_OPA_10) : lv_color_mix(theme.color_primary, COLOR_BTN, LV_OPA_10)) #define COLOR_BTN_CHK (theme.color_primary) #define COLOR_BTN_CHK_PR (lv_color_darken(theme.color_primary, LV_OPA_30)) -#define COLOR_BTN_DIS (IS_LIGHT ? lv_color_hex3(0x888) : lv_color_hex3(0x888)) +#define COLOR_BTN_DIS (IS_LIGHT ? lv_color_hex3(0xccc) : lv_color_hex3(0x888)) #define COLOR_BTN_BORDER theme.color_primary #define COLOR_BTN_BORDER_PR theme.color_primary #define COLOR_BTN_BORDER_CHK theme.color_primary #define COLOR_BTN_BORDER_CHK_PR theme.color_primary -#define COLOR_BTN_BORDER_INA (IS_LIGHT ? lv_color_hex(0x606060) : lv_color_hex(0x404040)) +#define COLOR_BTN_BORDER_INA (IS_LIGHT ? lv_color_hex3(0x888) : lv_color_hex(0x404040)) /*BACKGROUND*/ #define COLOR_BG (IS_LIGHT ? lv_color_hex(0xffffff) : lv_color_hex(0x303439)) @@ -61,7 +61,7 @@ #define COLOR_BG_SEC_TEXT_DIS (IS_LIGHT ? lv_color_hex(0xaaaaaa) : lv_color_hex(0xa5a8ad)) #define TRANSITION_TIME 150 - +#define BORDER_WIDTH (LV_DPI / 60 > 0 ? LV_DPI / 60 : 1) #define IS_LIGHT (theme.flags & LV_THEME_MATERIAL_FLAG_LIGHT) /********************** @@ -149,7 +149,7 @@ static lv_style_t pad_small; #endif #if LV_USE_SLIDER - static lv_style_t slider_knob; + static lv_style_t slider_knob, slider_bg; #endif #if LV_USE_SPINBOX @@ -190,14 +190,13 @@ static void basic_init(void) lv_style_set_value_color(&scr, LV_STATE_DEFAULT, COLOR_SCR_TEXT); lv_style_set_border_post(&scr, LV_STATE_DEFAULT, true); - lv_style_init(&bg); lv_style_set_radius(&bg, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_bg_opa(&bg, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&bg, LV_STATE_DEFAULT, COLOR_BG); lv_style_set_border_color(&bg, LV_STATE_DEFAULT, COLOR_BG_BORDER); lv_style_set_border_color(&bg, LV_STATE_FOCUSED, theme.color_primary); - lv_style_set_border_width(&bg, LV_STATE_DEFAULT, (LV_DPI / 60 > 0 ? LV_DPI / 60 : 1)); + lv_style_set_border_width(&bg, LV_STATE_DEFAULT, BORDER_WIDTH); lv_style_set_border_post(&bg, LV_STATE_DEFAULT, true); lv_style_set_text_font(&bg, LV_STATE_DEFAULT, theme.font_normal); lv_style_set_text_color(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT); @@ -205,10 +204,10 @@ static void basic_init(void) lv_style_set_image_recolor(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT); lv_style_set_line_color(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT); lv_style_set_line_width(&bg, LV_STATE_DEFAULT, 1); - lv_style_set_pad_left(&bg, LV_STATE_DEFAULT, LV_DPI / 5); - lv_style_set_pad_right(&bg, LV_STATE_DEFAULT, LV_DPI / 5); - lv_style_set_pad_top(&bg, LV_STATE_DEFAULT, LV_DPI / 5); - lv_style_set_pad_bottom(&bg, LV_STATE_DEFAULT, LV_DPI / 5); + lv_style_set_pad_left(&bg, LV_STATE_DEFAULT, LV_DPI / 10 + BORDER_WIDTH); + lv_style_set_pad_right(&bg, LV_STATE_DEFAULT, LV_DPI / 10 + BORDER_WIDTH); + lv_style_set_pad_top(&bg, LV_STATE_DEFAULT, LV_DPI / 10 + BORDER_WIDTH); + lv_style_set_pad_bottom(&bg, LV_STATE_DEFAULT, LV_DPI / 10 + BORDER_WIDTH); lv_style_set_pad_inner(&bg, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_transition_time(&bg, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_6(&bg, LV_STATE_DEFAULT, LV_STYLE_BORDER_COLOR); @@ -250,12 +249,13 @@ static void basic_init(void) lv_style_set_bg_color(&btn, LV_STATE_PRESSED, COLOR_BTN_PR); lv_style_set_bg_color(&btn, LV_STATE_CHECKED, COLOR_BTN_CHK); lv_style_set_bg_color(&btn, LV_STATE_CHECKED | LV_STATE_PRESSED, COLOR_BTN_CHK_PR); - lv_style_set_bg_color(&btn, LV_STATE_DISABLED, COLOR_BTN_DIS); + lv_style_set_bg_color(&btn, LV_STATE_DISABLED, COLOR_BTN); + lv_style_set_bg_color(&btn, LV_STATE_DISABLED | LV_STATE_CHECKED, COLOR_BTN_DIS); lv_style_set_border_color(&btn, LV_STATE_DEFAULT, COLOR_BTN_BORDER); lv_style_set_border_color(&btn, LV_STATE_PRESSED, COLOR_BTN_BORDER_PR); lv_style_set_border_color(&btn, LV_STATE_DISABLED, COLOR_BTN_BORDER_INA); lv_style_set_border_width(&btn, LV_STATE_DEFAULT, (LV_DPI / 60 > 0 ? LV_DPI / 60 : 1)); - lv_style_set_border_width(&btn, LV_STATE_CHECKED, 0); + lv_style_set_border_opa(&btn, LV_STATE_CHECKED, LV_OPA_TRANSP); lv_style_set_text_color(&btn, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex(0xffffff)); lv_style_set_text_color(&btn, LV_STATE_PRESSED, IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex(0xffffff)); @@ -275,8 +275,8 @@ static void basic_init(void) lv_style_set_value_color(&btn, LV_STATE_CHECKED | LV_STATE_PRESSED, lv_color_hex(0xffffff)); lv_style_set_value_color(&btn, LV_STATE_DISABLED, IS_LIGHT ? lv_color_hex(0x888888) : lv_color_hex(0x888888)); - lv_style_set_pad_left(&btn, LV_STATE_DEFAULT, LV_DPI / 5); - lv_style_set_pad_right(&btn, LV_STATE_DEFAULT, LV_DPI / 5); + lv_style_set_pad_left(&btn, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_right(&btn, LV_STATE_DEFAULT, LV_DPI / 7); lv_style_set_pad_top(&btn, LV_STATE_DEFAULT, LV_DPI / 15); lv_style_set_pad_bottom(&btn, LV_STATE_DEFAULT, LV_DPI / 15); lv_style_set_pad_inner(&btn, LV_STATE_DEFAULT, LV_DPI / 10); @@ -285,6 +285,7 @@ static void basic_init(void) lv_style_set_outline_opa(&btn, LV_STATE_FOCUSED, LV_OPA_50); lv_style_set_outline_color(&btn, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_transition_time(&btn, LV_STATE_DEFAULT, TRANSITION_TIME); + lv_style_set_transition_prop_4(&btn, LV_STATE_DEFAULT, LV_STYLE_BORDER_OPA); lv_style_set_transition_prop_5(&btn, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); lv_style_set_transition_prop_6(&btn, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA); lv_style_set_transition_delay(&btn, LV_STATE_DEFAULT, TRANSITION_TIME); @@ -342,7 +343,7 @@ static void bar_init(void) lv_style_set_radius(&bar_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_bg_color(&bar_indic, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_bg_color(&bar_indic, LV_STATE_DISABLED, lv_color_hex3(0x888)); - lv_style_set_value_color(&bar_indic, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); + lv_style_set_value_color(&bar_indic, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x41404f) : LV_COLOR_WHITE); #endif } @@ -389,6 +390,12 @@ static void slider_init(void) lv_style_set_pad_top(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_pad_bottom(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_init(&slider_bg); + lv_style_set_margin_left(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_margin_right(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_margin_top(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_margin_bottom(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 20); + #endif } @@ -510,17 +517,17 @@ static void calendar_init(void) #if LV_USE_CALENDAR lv_style_init(&calendar_header); - lv_style_set_pad_top(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 9); - lv_style_set_pad_left(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 9); - lv_style_set_pad_right(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 9); - lv_style_set_pad_bottom(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 9); + lv_style_set_pad_top(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_left(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_right(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_bottom(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_text_color(&calendar_header, LV_STATE_PRESSED, IS_LIGHT ? lv_color_hex(0x888888) : LV_COLOR_WHITE); lv_style_init(&calendar_daynames); lv_style_set_text_color(&calendar_daynames, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex3(0xeee)); - lv_style_set_pad_left(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 9); - lv_style_set_pad_right(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 9); - lv_style_set_pad_bottom(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 9); + lv_style_set_pad_left(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_right(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_bottom(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_init(&calendar_date_nums); lv_style_set_radius(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 50); @@ -535,10 +542,10 @@ static void calendar_init(void) lv_style_set_border_width(&calendar_date_nums, LV_STATE_CHECKED, 2); lv_style_set_border_side(&calendar_date_nums, LV_STATE_CHECKED, LV_BORDER_SIDE_LEFT); lv_style_set_border_color(&calendar_date_nums, LV_STATE_CHECKED, theme.color_primary); - lv_style_set_pad_inner(&calendar_date_nums, LV_STATE_DEFAULT, LV_MATH_MAX(LV_DPI / 50, 1)); - lv_style_set_pad_left(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 9); - lv_style_set_pad_right(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 9); - lv_style_set_pad_bottom(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 9); + lv_style_set_pad_inner(&calendar_date_nums, LV_STATE_DEFAULT, LV_MATH_MAX(LV_DPI / 70, 1)); + lv_style_set_pad_left(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_right(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_bottom(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 10); #endif } @@ -586,9 +593,6 @@ static void checkbox_init(void) lv_style_set_pattern_image(&cb_bullet, LV_STATE_CHECKED, LV_SYMBOL_OK); lv_style_set_pattern_recolor(&cb_bullet, LV_STATE_CHECKED, LV_COLOR_WHITE); lv_style_set_text_font(&cb_bullet, LV_STATE_CHECKED, theme.font_small); - lv_style_set_transition_time(&cb_bullet, LV_STATE_DEFAULT, TRANSITION_TIME); - lv_style_set_transition_prop_5(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); - lv_style_set_transition_prop_6(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BORDER_COLOR); #endif } @@ -701,14 +705,19 @@ static void list_init(void) lv_style_set_pad_bottom(&list_btn, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_inner(&list_btn, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_margin_top(&list_btn, LV_STATE_CHECKED, LV_DPI / 10); + lv_style_set_margin_bottom(&list_btn, LV_STATE_CHECKED, LV_DPI / 10); + lv_style_set_transform_width(&list_btn, LV_STATE_DEFAULT, - LV_DPI / 10); lv_style_set_transform_width(&list_btn, LV_STATE_PRESSED, 0); lv_style_set_transform_width(&list_btn, LV_STATE_CHECKED, 0); lv_style_set_transform_width(&list_btn, LV_STATE_DISABLED, 0); lv_style_set_transition_time(&list_btn, LV_STATE_DEFAULT, TRANSITION_TIME); - lv_style_set_transition_prop_5(&list_btn, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); - lv_style_set_transition_prop_4(&list_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_WIDTH); + lv_style_set_transition_prop_6(&list_btn, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); + lv_style_set_transition_prop_5(&list_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_WIDTH); + lv_style_set_transition_prop_4(&list_btn, LV_STATE_DEFAULT, LV_STYLE_MARGIN_TOP); + lv_style_set_transition_prop_3(&list_btn, LV_STATE_DEFAULT, LV_STYLE_MARGIN_BOTTOM); #endif } @@ -771,13 +780,12 @@ static void tabview_init(void) lv_style_set_size(&tabview_indic, LV_STATE_DEFAULT, LV_DPI / 40 > 0 ? LV_DPI / 40 : 1); lv_style_set_radius(&tabview_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_init(&tabview_page_scrl); - lv_style_set_pad_top(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 5); - lv_style_set_pad_bottom(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 5); - lv_style_set_pad_left(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 3); - lv_style_set_pad_right(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 3); - lv_style_set_pad_inner(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 5); + lv_style_set_pad_top(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_bottom(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_left(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_right(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_inner(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 10); #endif } @@ -794,10 +802,10 @@ static void table_init(void) lv_style_set_border_color(&table_cell, LV_STATE_DEFAULT, COLOR_BG_BORDER); lv_style_set_border_width(&table_cell, LV_STATE_DEFAULT, 1); lv_style_set_border_side(&table_cell, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM); - lv_style_set_pad_left(&table_cell, LV_STATE_DEFAULT, LV_DPI / 8); - lv_style_set_pad_right(&table_cell, LV_STATE_DEFAULT, LV_DPI / 8); - lv_style_set_pad_top(&table_cell, LV_STATE_DEFAULT, LV_DPI / 8); - lv_style_set_pad_bottom(&table_cell, LV_STATE_DEFAULT, LV_DPI / 8); + lv_style_set_pad_left(&table_cell, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_right(&table_cell, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_top(&table_cell, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_bottom(&table_cell, LV_STATE_DEFAULT, LV_DPI / 10); #endif } @@ -1026,6 +1034,7 @@ void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name) lv_obj_clean_style_list(obj, LV_SLIDER_PART_BG); list = lv_obj_get_style_list(obj, LV_SLIDER_PART_BG); lv_style_list_add_style(list, &bar_bg); + lv_style_list_add_style(list, &slider_bg); lv_obj_clean_style_list(obj, LV_SLIDER_PART_INDIC); list = lv_obj_get_style_list(obj, LV_SLIDER_PART_INDIC); diff --git a/src/lv_widgets/lv_bar.c b/src/lv_widgets/lv_bar.c index 0b12889c8..e2af54291 100644 --- a/src/lv_widgets/lv_bar.c +++ b/src/lv_widgets/lv_bar.c @@ -384,6 +384,16 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area draw_dsc.pattern_opa = LV_OPA_TRANSP; draw_dsc.outline_opa = LV_OPA_TRANSP; lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_BG, &draw_dsc); +// lv_draw_rect(&bar->coords, clip_area, &draw_dsc); + + /*Finally draw the indicators value*/ + lv_draw_rect_dsc_init(&draw_dsc); + draw_dsc.bg_opa = LV_OPA_TRANSP; + draw_dsc.border_opa = LV_OPA_TRANSP; + draw_dsc.shadow_opa = LV_OPA_TRANSP; + draw_dsc.pattern_opa = LV_OPA_TRANSP; + draw_dsc.outline_opa = LV_OPA_TRANSP; + lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_INDIC, &draw_dsc); lv_draw_rect(&bar->coords, clip_area, &draw_dsc); } @@ -545,7 +555,6 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) (!hor && lv_area_get_height(&ext->indic_area) > bg_radius * 2)) { lv_opa_t bg_opa = draw_indic_dsc.bg_opa; lv_opa_t border_opa = draw_indic_dsc.border_opa; - lv_opa_t value_opa = draw_indic_dsc.border_opa; const void * pattern_src = draw_indic_dsc.pattern_image; draw_indic_dsc.bg_opa = LV_OPA_TRANSP; draw_indic_dsc.border_opa = LV_OPA_TRANSP; @@ -554,7 +563,6 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) lv_draw_rect(&ext->indic_area, clip_area, &draw_indic_dsc); draw_indic_dsc.bg_opa = bg_opa; draw_indic_dsc.border_opa = border_opa; - draw_indic_dsc.value_opa = value_opa; draw_indic_dsc.pattern_image = pattern_src; } diff --git a/src/lv_widgets/lv_cont.c b/src/lv_widgets/lv_cont.c index bd435a5da..788594318 100644 --- a/src/lv_widgets/lv_cont.c +++ b/src/lv_widgets/lv_cont.c @@ -378,9 +378,11 @@ static void lv_cont_layout_col(lv_obj_t * cont) lv_coord_t last_cord = top; LV_LL_READ_BACK(cont->child_ll, child) { if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; - - lv_obj_align(child, cont, align, hpad_corr, last_cord); - last_cord += lv_obj_get_height(child) + inner; + lv_style_int_t mtop = lv_obj_get_style_margin_top(child, LV_OBJ_PART_MAIN); + lv_style_int_t mbottom = lv_obj_get_style_margin_top(child, LV_OBJ_PART_MAIN); + lv_style_int_t mleft = lv_obj_get_style_margin_left(child, LV_OBJ_PART_MAIN); + lv_obj_align(child, cont, align, hpad_corr + mleft, last_cord + mtop); + last_cord += lv_obj_get_height(child) + inner + mtop + mbottom; } lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG); @@ -500,21 +502,24 @@ static void lv_cont_layout_pretty(lv_obj_t * cont) if(child_rs == NULL) return; /*Return if no child*/ lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG); - lv_coord_t left = lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN); - lv_coord_t right = lv_obj_get_style_pad_right(cont, LV_CONT_PART_MAIN); - lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN); + lv_coord_t pleft = lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN); + lv_coord_t pright = lv_obj_get_style_pad_right(cont, LV_CONT_PART_MAIN); + lv_coord_t pinner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN); child_rc = child_rs; /*Initially the the row starter and closer is the same*/ while(child_rs != NULL) { lv_coord_t h_row = 0; - lv_coord_t w_row = left + right; /*The width is at least the left+right pad*/ + lv_coord_t w_row = pleft + pright; /*The width is at least the left+right pad*/ uint32_t obj_num = 0; /*Find the row closer object and collect some data*/ do { if(lv_obj_get_hidden(child_rc) == false && lv_obj_is_protected(child_rc, LV_PROTECT_POS) == false) { /*If this object is already not fit then break*/ - if(w_row + lv_obj_get_width(child_rc) > w_obj) { + lv_coord_t w = lv_obj_get_width(child_rc); + w += lv_obj_get_style_margin_left(child_rc, LV_OBJ_PART_MAIN); + w += lv_obj_get_style_margin_right(child_rc, LV_OBJ_PART_MAIN); + if(w_row + w > w_obj) { /*Step back one child because the last already not fit, so the previous is the * closer*/ if(child_rc != NULL && obj_num != 0) { @@ -522,9 +527,13 @@ static void lv_cont_layout_pretty(lv_obj_t * cont) } break; } - w_row += lv_obj_get_width(child_rc) + inner; /*Add the object width + opad*/ + w_row += w + pinner; /*Add the object width + inner padding*/ lv_coord_t child_h = lv_obj_get_height(child_rc); - h_row = LV_MATH_MAX(h_row, child_h); /*Search the highest object*/ + + lv_coord_t h = lv_obj_get_height(child_rc); + h += lv_obj_get_style_margin_top(child_rc, LV_OBJ_PART_MAIN); + h += lv_obj_get_style_margin_bottom(child_rc, LV_OBJ_PART_MAIN); + h_row = LV_MATH_MAX(h_row, h); /*Search the highest object*/ obj_num++; if(lv_obj_is_protected(child_rc, LV_PROTECT_FOLLOW)) break; /*If can not be followed by an other object then break here*/ @@ -538,13 +547,19 @@ static void lv_cont_layout_pretty(lv_obj_t * cont) /*If the object is too long then align it to the middle*/ if(obj_num == 0) { if(child_rc != NULL) { - lv_obj_align(child_rc, cont, LV_ALIGN_IN_TOP_MID, 0, act_y); + lv_style_int_t mtop = lv_obj_get_style_margin_top(child_rc, LV_OBJ_PART_MAIN); + + lv_obj_align(child_rc, cont, LV_ALIGN_IN_TOP_MID, 0, act_y + mtop); h_row = lv_obj_get_height(child_rc); /*Not set previously because of the early break*/ + h_row += mtop; + h_row += lv_obj_get_style_margin_bottom(child_rc, LV_OBJ_PART_MAIN); } } /*If there is only one object in the row then align it to the middle*/ else if(obj_num == 1) { - lv_obj_align(child_rs, cont, LV_ALIGN_IN_TOP_MID, 0, act_y); + lv_obj_align(child_rs, cont, LV_ALIGN_IN_TOP_MID, + lv_obj_get_style_margin_left(child_rs, LV_OBJ_PART_MAIN), + act_y + lv_obj_get_style_margin_top(child_rs, LV_OBJ_PART_MAIN)); } /*If there are two object in the row then align them proportionally*/ else if(obj_num == 2) { @@ -552,18 +567,31 @@ static void lv_cont_layout_pretty(lv_obj_t * cont) lv_obj_t * obj2 = lv_ll_get_prev(&cont->child_ll, child_rs); w_row = lv_obj_get_width(obj1) + lv_obj_get_width(obj2); lv_coord_t pad = (w_obj - w_row) / 3; + switch(type) { case LV_LAYOUT_PRETTY_TOP: - lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, pad, act_y); - lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, -pad, act_y); + lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, + pad + lv_obj_get_style_margin_left(obj1, LV_OBJ_PART_MAIN), + act_y + lv_obj_get_style_margin_top(obj1, LV_OBJ_PART_MAIN)); + lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, + -pad - lv_obj_get_style_margin_right(obj2, LV_OBJ_PART_MAIN), + act_y + lv_obj_get_style_margin_top(obj2, LV_OBJ_PART_MAIN)); break; case LV_LAYOUT_PRETTY_MID: - lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, pad, act_y + (h_row - lv_obj_get_height(obj1)) / 2); - lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, -pad, act_y + (h_row - lv_obj_get_height(obj2)) / 2); + lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, + pad + lv_obj_get_style_margin_left(obj1, LV_OBJ_PART_MAIN), + act_y + (h_row - lv_obj_get_height(obj1)) / 2 + lv_obj_get_style_margin_top(obj1, LV_OBJ_PART_MAIN)); + lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, + -pad - lv_obj_get_style_margin_right(obj2, LV_OBJ_PART_MAIN), + act_y + (h_row - lv_obj_get_height(obj2)) / 2 + lv_obj_get_style_margin_top(obj2, LV_OBJ_PART_MAIN)); break; case LV_LAYOUT_PRETTY_BOTTOM: - lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, pad, act_y + h_row - lv_obj_get_height(obj1)); - lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, -pad, act_y + h_row - lv_obj_get_height(obj2)); + lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, + pad + lv_obj_get_style_margin_left(obj1, LV_OBJ_PART_MAIN), + act_y + h_row - lv_obj_get_height(obj1) - lv_obj_get_style_margin_bottom(obj1, LV_OBJ_PART_MAIN)); + lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, + -pad - lv_obj_get_style_margin_right(obj2, LV_OBJ_PART_MAIN), + act_y + h_row - lv_obj_get_height(obj2) - lv_obj_get_style_margin_bottom(obj2, LV_OBJ_PART_MAIN)); break; default: break; @@ -571,31 +599,36 @@ static void lv_cont_layout_pretty(lv_obj_t * cont) } /* Align the children (from child_rs to child_rc)*/ else { - w_row -= inner * obj_num; - lv_coord_t new_opad = (w_obj - w_row) / (obj_num - 1); - lv_coord_t act_x = left; /*x init*/ + w_row -= pinner * obj_num; + lv_coord_t new_pinner = (w_obj - w_row) / (obj_num - 1); + lv_coord_t act_x = pleft; /*x init*/ child_tmp = child_rs; while(child_tmp != NULL) { if(lv_obj_get_hidden(child_tmp) == false && lv_obj_is_protected(child_tmp, LV_PROTECT_POS) == false) { + lv_coord_t mleft = lv_obj_get_style_margin_left(child_tmp, LV_OBJ_PART_MAIN); + lv_coord_t mright = lv_obj_get_style_margin_right(child_tmp, LV_OBJ_PART_MAIN); switch(type) { case LV_LAYOUT_PRETTY_TOP: - lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, act_x, - act_y); + lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, + act_x + mleft, + act_y + lv_obj_get_style_margin_top(child_tmp, LV_OBJ_PART_MAIN)); break; case LV_LAYOUT_PRETTY_MID: - lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, act_x, + lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, + act_x + mleft, act_y + (h_row - lv_obj_get_height(child_tmp)) / 2); break; case LV_LAYOUT_PRETTY_BOTTOM: - lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, act_x, - act_y + h_row - lv_obj_get_height(child_tmp)); + lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, + act_x + mleft, + act_y + h_row - lv_obj_get_height(child_tmp) - lv_obj_get_style_margin_bottom(child_tmp, LV_OBJ_PART_MAIN)); break; default: break; } - act_x += lv_obj_get_width(child_tmp) + new_opad; + act_x += lv_obj_get_width(child_tmp) + new_pinner + mleft + mright; } if(child_tmp == child_rc) break; child_tmp = lv_ll_get_prev(&cont->child_ll, child_tmp); @@ -603,7 +636,7 @@ static void lv_cont_layout_pretty(lv_obj_t * cont) } if(child_rc == NULL) break; - act_y += inner + h_row; /*y increment*/ + act_y += pinner + h_row; /*y increment*/ child_rs = lv_ll_get_prev(&cont->child_ll, child_rc); /*Go to the next object*/ child_rc = child_rs; } @@ -681,12 +714,12 @@ static void lv_cont_refr_autofit(lv_obj_t * cont) lv_obj_t * child_i; lv_obj_t * par = lv_obj_get_parent(cont); - lv_area_t flood_area; - lv_area_copy(&flood_area, &par->coords); - flood_area.x1 += lv_obj_get_style_pad_left(par, LV_OBJ_PART_MAIN); - flood_area.x2 -= lv_obj_get_style_pad_right(par, LV_OBJ_PART_MAIN); - flood_area.y1 += lv_obj_get_style_pad_top(par, LV_OBJ_PART_MAIN); - flood_area.y2 -= lv_obj_get_style_pad_bottom(par, LV_OBJ_PART_MAIN); + lv_area_t parent_area; + lv_area_copy(&parent_area, &par->coords); + parent_area.x1 += lv_obj_get_style_pad_left(par, LV_OBJ_PART_MAIN); + parent_area.x2 -= lv_obj_get_style_pad_right(par, LV_OBJ_PART_MAIN); + parent_area.y1 += lv_obj_get_style_pad_top(par, LV_OBJ_PART_MAIN); + parent_area.y2 -= lv_obj_get_style_pad_bottom(par, LV_OBJ_PART_MAIN); /*Search the side coordinates of the children*/ lv_obj_get_coords(cont, &ori); @@ -702,10 +735,14 @@ static void lv_cont_refr_autofit(lv_obj_t * cont) LV_LL_READ(cont->child_ll, child_i) { if(lv_obj_get_hidden(child_i) != false) continue; - tight_area.x1 = LV_MATH_MIN(tight_area.x1, child_i->coords.x1); - tight_area.y1 = LV_MATH_MIN(tight_area.y1, child_i->coords.y1); - tight_area.x2 = LV_MATH_MAX(tight_area.x2, child_i->coords.x2); - tight_area.y2 = LV_MATH_MAX(tight_area.y2, child_i->coords.y2); + lv_style_int_t mleft = lv_obj_get_style_margin_left(child_i, LV_OBJ_PART_MAIN); + lv_style_int_t mright = lv_obj_get_style_margin_right(child_i, LV_OBJ_PART_MAIN); + lv_style_int_t mtop = lv_obj_get_style_margin_top(child_i, LV_OBJ_PART_MAIN); + lv_style_int_t mbottom = lv_obj_get_style_margin_bottom(child_i, LV_OBJ_PART_MAIN); + tight_area.x1 = LV_MATH_MIN(tight_area.x1, child_i->coords.x1 - mleft); + tight_area.y1 = LV_MATH_MIN(tight_area.y1, child_i->coords.y1 - mtop); + tight_area.x2 = LV_MATH_MAX(tight_area.x2, child_i->coords.x2 + mright); + tight_area.y2 = LV_MATH_MAX(tight_area.y2, child_i->coords.y2 + mbottom); } tight_area.x1 -= lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN); @@ -722,10 +759,10 @@ static void lv_cont_refr_autofit(lv_obj_t * cont) new_area.x1 = tight_area.x1; break; case LV_FIT_PARENT: - new_area.x1 = flood_area.x1; + new_area.x1 = parent_area.x1; break; case LV_FIT_MAX: - new_area.x1 = has_children ? LV_MATH_MIN(tight_area.x1, flood_area.x1) : flood_area.x1; + new_area.x1 = has_children ? LV_MATH_MIN(tight_area.x1, parent_area.x1) : parent_area.x1; break; default: break; @@ -736,10 +773,10 @@ static void lv_cont_refr_autofit(lv_obj_t * cont) new_area.x2 = tight_area.x2; break; case LV_FIT_PARENT: - new_area.x2 = flood_area.x2; + new_area.x2 = parent_area.x2; break; case LV_FIT_MAX: - new_area.x2 = has_children ? LV_MATH_MAX(tight_area.x2, flood_area.x2) : flood_area.x2; + new_area.x2 = has_children ? LV_MATH_MAX(tight_area.x2, parent_area.x2) : parent_area.x2; break; default: break; @@ -750,10 +787,10 @@ static void lv_cont_refr_autofit(lv_obj_t * cont) new_area.y1 = tight_area.y1; break; case LV_FIT_PARENT: - new_area.y1 = flood_area.y1; + new_area.y1 = parent_area.y1; break; case LV_FIT_MAX: - new_area.y1 = has_children ? LV_MATH_MIN(tight_area.y1, flood_area.y1) : flood_area.y1; + new_area.y1 = has_children ? LV_MATH_MIN(tight_area.y1, parent_area.y1) : parent_area.y1; break; default: break; @@ -764,10 +801,10 @@ static void lv_cont_refr_autofit(lv_obj_t * cont) new_area.y2 = tight_area.y2; break; case LV_FIT_PARENT: - new_area.y2 = flood_area.y2; + new_area.y2 = parent_area.y2; break; case LV_FIT_MAX: - new_area.y2 = has_children ? LV_MATH_MAX(tight_area.y2, flood_area.y2) : flood_area.y2; + new_area.y2 = has_children ? LV_MATH_MAX(tight_area.y2, parent_area.y2) : parent_area.y2; break; default: break; diff --git a/src/lv_widgets/lv_page.c b/src/lv_widgets/lv_page.c index 7a13f5ae5..0879a0765 100644 --- a/src/lv_widgets/lv_page.c +++ b/src/lv_widgets/lv_page.c @@ -344,7 +344,7 @@ bool lv_page_get_edge_flash(lv_obj_t * page) * @param page pointer to a page object * @return the width which still fits into the page */ -lv_coord_t lv_page_get_fit_width(lv_obj_t * page) +lv_coord_t lv_page_get_width_fit(lv_obj_t * page) { LV_ASSERT_OBJ(page, LV_OBJX_NAME); @@ -362,7 +362,7 @@ lv_coord_t lv_page_get_fit_width(lv_obj_t * page) * @param page pointer to a page object * @return the height which still fits into the page */ -lv_coord_t lv_page_get_fit_height(lv_obj_t * page) +lv_coord_t lv_page_get_height_fit(lv_obj_t * page) { LV_ASSERT_OBJ(page, LV_OBJX_NAME); @@ -376,6 +376,51 @@ lv_coord_t lv_page_get_fit_height(lv_obj_t * page) return lv_obj_get_height(page) - bg_top - bg_bottom - scrl_top - scrl_bottom; } +/** + * Divide the width of the object and get the width of a given number of columns. + * Take into account the paddings of the background and scrollbale too. + * @param page pointer to an object + * @param div indicates how many columns are assumed. + * If 1 the width will be set the the parent's width + * If 2 only half parent width - inner padding of the parent + * If 3 only third parent width - 2 * inner padding of the parent + * @param span how many columns are combined + * @return the width according to the given parameters + */ +lv_coord_t lv_page_get_width_grid(lv_obj_t * page, uint8_t div, uint8_t span) +{ + + lv_coord_t obj_w = lv_page_get_width_fit(page); + lv_style_int_t pinner = lv_obj_get_style_pad_inner(page, LV_PAGE_PART_SCRL); + + lv_coord_t r = obj_w / div - (div - 1) * pinner; + + r = r * span + (span - 1) * pinner; + return r; +} + +/** + * Divide the height of the object and get the width of a given number of columns. + * Take into account the paddings of the background and scrollbale too. + * @param obj pointer to an object + * @param div indicates how many rows are assumed. + * If 1 the height will be set the the parent's height + * If 2 only half parent height - inner padding of the parent + * If 3 only third parent height - 2 * inner padding of the parent + * @param span how many rows are combined + * @return the height according to the given parameters + */ +lv_coord_t lv_page_get_height_grid(lv_obj_t * page, uint8_t div, uint8_t span) +{ + lv_coord_t obj_h = lv_page_get_height_fit(page); + lv_style_int_t pinner = lv_obj_get_style_pad_inner(page, LV_PAGE_PART_SCRL); + + lv_coord_t r = obj_h / div - (div - 1) * pinner; + + r = r * span + (span - 1) * pinner; + return r; +} + /*===================== * Other functions *====================*/ diff --git a/src/lv_widgets/lv_page.h b/src/lv_widgets/lv_page.h index f46ace205..94f008643 100644 --- a/src/lv_widgets/lv_page.h +++ b/src/lv_widgets/lv_page.h @@ -258,14 +258,40 @@ bool lv_page_get_edge_flash(lv_obj_t * page); * @param page pointer to a page object * @return the width which still fits into the page */ -lv_coord_t lv_page_get_fit_width(lv_obj_t * page); +lv_coord_t lv_page_get_width_fit(lv_obj_t * page); /** * Get that height which can be set to the children to still not cause overflow (show scrollbars) * @param page pointer to a page object * @return the height which still fits into the page */ -lv_coord_t lv_page_get_fit_height(lv_obj_t * page); +lv_coord_t lv_page_get_height_fit(lv_obj_t * page); + +/** + * Divide the width of the object and get the width of a given number of columns. + * Take into account the paddings of the background and scrollbale too. + * @param page pointer to an object + * @param div indicates how many columns are assumed. + * If 1 the width will be set the the parent's width + * If 2 only half parent width - inner padding of the parent + * If 3 only third parent width - 2 * inner padding of the parent + * @param span how many columns are combined + * @return the width according to the given parameters + */ +lv_coord_t lv_page_get_width_grid(lv_obj_t * page, uint8_t div, uint8_t span); + +/** + * Divide the height of the object and get the width of a given number of columns. + * Take into account the paddings of the background and scrollbale too. + * @param page pointer to an object + * @param div indicates how many rows are assumed. + * If 1 the height will be set the the parent's height + * If 2 only half parent height - inner padding of the parent + * If 3 only third parent height - 2 * inner padding of the parent + * @param span how many rows are combined + * @return the height according to the given parameters + */ +lv_coord_t lv_page_get_height_grid(lv_obj_t * page, uint8_t div, uint8_t span); /** * Get width of the scrollable part of a page diff --git a/src/lv_widgets/lv_table.c b/src/lv_widgets/lv_table.c index 3cbd63dc8..42d043695 100644 --- a/src/lv_widgets/lv_table.c +++ b/src/lv_widgets/lv_table.c @@ -611,6 +611,77 @@ bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col) } } +/** + * Get the last pressed or being pressed cell + * @param table pointer to a table object + * @param row pointer to variable to store the pressed row + * @param col pointer to variable to store the pressed column + * @return LV_RES_OK: a valid pressed cell was found, LV_RES_INV: no valid cell is pressed + */ +lv_res_t lv_table_get_pressed_cell(lv_obj_t * table, uint16_t * row, uint16_t * col) +{ + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + + lv_indev_type_t type = lv_indev_get_type(lv_indev_get_act()); + if(type != LV_INDEV_TYPE_POINTER && type != LV_INDEV_TYPE_BUTTON) { + if(col) *col = 0xFFFF; + if(row) *row = 0xFFFF; + return LV_RES_INV; + } + + lv_point_t p; + lv_indev_get_point(lv_indev_get_act(), &p); + + lv_coord_t tmp; + if(col) { + lv_coord_t x = p.x; + x -= table->coords.x1; + x -= lv_obj_get_style_pad_left(table, LV_TABLE_PART_BG); + *col = 0; + tmp = 0; + for(*col = 0; *col < ext->col_cnt; (*col)++) { + tmp += ext->col_w[*col]; + if(x < tmp) break; + } + } + + if(row) { + lv_coord_t y = p.y; + y -= table->coords.y1; + y -= lv_obj_get_style_pad_top(table, LV_TABLE_PART_BG); + + *row = 0; + tmp = 0; + lv_style_int_t cell_left[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_right[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_top[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t cell_bottom[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t letter_space[LV_TABLE_CELL_STYLE_CNT]; + lv_style_int_t line_space[LV_TABLE_CELL_STYLE_CNT]; + const lv_font_t * font[LV_TABLE_CELL_STYLE_CNT]; + + uint16_t i; + for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) { + if((ext->cell_types & (1 << i)) == 0) continue; /*Skip unused cell types*/ + cell_left[i] = lv_obj_get_style_pad_left(table, LV_TABLE_PART_CELL1 + i); + cell_right[i] = lv_obj_get_style_pad_right(table, LV_TABLE_PART_CELL1 + i); + cell_top[i] = lv_obj_get_style_pad_top(table, LV_TABLE_PART_CELL1 + i); + cell_bottom[i] = lv_obj_get_style_pad_bottom(table, LV_TABLE_PART_CELL1 + i); + letter_space[i] = lv_obj_get_style_text_letter_space(table, LV_TABLE_PART_CELL1 + i); + line_space[i] = lv_obj_get_style_text_line_space(table, LV_TABLE_PART_CELL1 + i); + font[i] = lv_obj_get_style_text_font(table, LV_TABLE_PART_CELL1 + i); + } + + for(*row = 0; *row < ext->row_cnt; (*row)++) { + tmp += get_row_height(table, *row, font, letter_space, line_space, + cell_left, cell_right, cell_top, cell_bottom); + if(y < tmp) break; + } + } + + return LV_RES_OK; +} + /********************** * STATIC FUNCTIONS **********************/ @@ -737,10 +808,18 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ /*Expand the cell area with a half border to avoid drawing 2 borders next to each other*/ lv_area_t cell_area_border; lv_area_copy(&cell_area_border, &cell_area); - if(cell_area_border.x1 > table->coords.x1 + bg_left) cell_area_border.x1 -= rect_dsc[cell_type].border_width / 2; - if(cell_area_border.y1 > table->coords.y1 + bg_top) cell_area_border.y1 -= rect_dsc[cell_type].border_width / 2; - if(cell_area_border.x2 < table->coords.x2 - bg_right - 1) cell_area_border.x2 += rect_dsc[cell_type].border_width / 2 + (rect_dsc[cell_type].border_width & 0x1); - if(cell_area_border.y2 < table->coords.y2 - bg_bottom - 1) cell_area_border.y2 += rect_dsc[cell_type].border_width / 2 + (rect_dsc[cell_type].border_width & 0x1); + if((rect_dsc[cell_type].border_side & LV_BORDER_SIDE_LEFT) && cell_area_border.x1 > table->coords.x1 + bg_left) { + cell_area_border.x1 -= rect_dsc[cell_type].border_width / 2; + } + if((rect_dsc[cell_type].border_side & LV_BORDER_SIDE_TOP) && cell_area_border.y1 > table->coords.y1 + bg_top) { + cell_area_border.y1 -= rect_dsc[cell_type].border_width / 2; + } + if((rect_dsc[cell_type].border_side & LV_BORDER_SIDE_RIGHT) && cell_area_border.x2 < table->coords.x2 - bg_right - 1) { + cell_area_border.x2 += rect_dsc[cell_type].border_width / 2 + (rect_dsc[cell_type].border_width & 0x1); + } + if((rect_dsc[cell_type].border_side & LV_BORDER_SIDE_BOTTOM) && cell_area_border.y2 < table->coords.y2 - bg_bottom - 1) { + cell_area_border.y2 += rect_dsc[cell_type].border_width / 2 + (rect_dsc[cell_type].border_width & 0x1); + } lv_draw_rect(&cell_area_border, clip_area, &rect_dsc[cell_type]); @@ -767,7 +846,6 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ if(format.s.crop == 0) { txt_area.y1 = cell_area.y1 + h_row / 2 - txt_size.y / 2; txt_area.y2 = cell_area.y1 + h_row / 2 + txt_size.y / 2; - label_dsc[cell_type].flag |= LV_TXT_FLAG_FIT; } switch(format.s.align) { diff --git a/src/lv_widgets/lv_table.h b/src/lv_widgets/lv_table.h index 30d090d46..defb8a6fb 100644 --- a/src/lv_widgets/lv_table.h +++ b/src/lv_widgets/lv_table.h @@ -228,6 +228,15 @@ lv_label_align_t lv_table_get_cell_crop(lv_obj_t * table, uint16_t row, uint16_t */ bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col); +/** + * Get the last pressed or being pressed cell + * @param table pointer to a table object + * @param row pointer to variable to store the pressed row + * @param col pointer to variable to store the pressed column + * @return LV_RES_OK: a valid pressed cell was found, LV_RES_INV: no valid cell is pressed + */ +lv_res_t lv_table_get_pressed_cell(lv_obj_t * table, uint16_t * row, uint16_t * col); + /*===================== * Other functions *====================*/ diff --git a/src/lv_widgets/lv_textarea.c b/src/lv_widgets/lv_textarea.c index fbc0cd31d..3099e0fc2 100644 --- a/src/lv_widgets/lv_textarea.c +++ b/src/lv_widgets/lv_textarea.c @@ -791,7 +791,7 @@ void lv_textarea_set_text_align(lv_obj_t * ta, lv_label_align_t align) /*Else use fix label width equal to the Text area width*/ else { lv_label_set_long_mode(label, LV_LABEL_LONG_CROP); - lv_obj_set_width(label, lv_page_get_fit_width(ta)); + lv_obj_set_width(label, lv_page_get_width_fit(ta)); lv_label_set_align(label, align); lv_page_set_scrl_fit2(ta, LV_FIT_PARENT, LV_FIT_PARENT); } @@ -1324,6 +1324,8 @@ static lv_design_res_t lv_textarea_scrollable_design(lv_obj_t * scrl, const lv_a break; } + if(ext->one_line) ph_dsc.flag |= LV_TXT_FLAG_EXPAND; + lv_draw_label(&scrl->coords, clip_area, &ph_dsc, ext->placeholder_txt, NULL); } @@ -1420,7 +1422,7 @@ static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param } else { /*In not one line mode refresh the Label width because 'hpad' can modify it*/ - lv_obj_set_width(ext->label, lv_page_get_fit_width(ta)); + lv_obj_set_width(ext->label, lv_page_get_width_fit(ta)); lv_obj_set_pos(ext->label, 0, 0); /*Be sure the Label is in the correct position*/ } @@ -1432,7 +1434,7 @@ static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param /*Set the label width according to the text area width*/ if(ext->label) { if(lv_obj_get_width(ta) != lv_area_get_width(param) || lv_obj_get_height(ta) != lv_area_get_height(param)) { - lv_obj_set_width(ext->label, lv_page_get_fit_width(ta)); + lv_obj_set_width(ext->label, lv_page_get_width_fit(ta)); lv_obj_set_pos(ext->label, 0, 0); lv_label_set_text(ext->label, NULL); /*Refresh the label*/ @@ -1506,7 +1508,7 @@ static lv_res_t lv_textarea_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, if(lv_obj_get_width(scrl) != lv_area_get_width(param) || lv_obj_get_height(scrl) != lv_area_get_height(param)) { - lv_obj_set_width(ext->label, lv_page_get_fit_width(ta)); + lv_obj_set_width(ext->label, lv_page_get_width_fit(ta)); lv_obj_set_pos(ext->label, 0, 0); lv_label_set_text(ext->label, NULL); /*Refresh the label*/ From 1ddf83a73c46aac4326f8affb5f5baf680cead02 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 8 Apr 2020 20:54:02 +0200 Subject: [PATCH 2/2] minor fixes --- src/lv_core/lv_obj.c | 4 +- src/lv_themes/lv_theme_material.c | 21 ++-- src/lv_widgets/lv_bar.c | 13 +-- src/lv_widgets/lv_chart.c | 11 ++ src/lv_widgets/lv_cont.c | 4 +- src/lv_widgets/lv_dropdown.c | 188 +++++++++--------------------- src/lv_widgets/lv_dropdown.h | 20 +--- src/lv_widgets/lv_page.c | 4 +- 8 files changed, 86 insertions(+), 179 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 7855198c8..250b1287d 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -2173,7 +2173,7 @@ lv_coord_t lv_obj_get_width_grid(lv_obj_t * obj, uint8_t div, uint8_t span) lv_coord_t obj_w = lv_obj_get_width_fit(obj); lv_style_int_t pinner = lv_obj_get_style_pad_inner(obj, LV_OBJ_PART_MAIN); - lv_coord_t r = obj_w / div - (div - 1) * pinner; + lv_coord_t r = (obj_w - (div - 1) * pinner) / div; r = r * span + (span - 1) * pinner; return r; @@ -2194,7 +2194,7 @@ lv_coord_t lv_obj_get_height_grid(lv_obj_t * obj, uint8_t div, uint8_t span) lv_coord_t obj_h = lv_obj_get_height_fit(obj); lv_style_int_t pinner = lv_obj_get_style_pad_inner(obj, LV_OBJ_PART_MAIN); - lv_coord_t r = obj_h / div - (div - 1) * pinner; + lv_coord_t r = (obj_h - (div - 1) * pinner) / div; r = r * span + (span - 1) * pinner; return r; diff --git a/src/lv_themes/lv_theme_material.c b/src/lv_themes/lv_theme_material.c index 0e47f1ff5..37786645e 100644 --- a/src/lv_themes/lv_theme_material.c +++ b/src/lv_themes/lv_theme_material.c @@ -42,11 +42,11 @@ #define COLOR_BG_PR_CHK lv_color_darken(theme.color_primary, LV_OPA_20) #define COLOR_BG_DIS COLOR_BG -#define COLOR_BG_BORDER (IS_LIGHT ? lv_color_hex(0xdfe7ed) : lv_color_hex(0x404040)) +#define COLOR_BG_BORDER (IS_LIGHT ? lv_color_hex(0xd6dde3) : lv_color_hex(0x404040)) /*dfe7ed*/ #define COLOR_BG_BORDER_PR (IS_LIGHT ? lv_color_hex3(0xccc) : lv_color_hex(0x404040)) #define COLOR_BG_BORDER_CHK (IS_LIGHT ? lv_color_hex(0x3b3e42) : lv_color_hex(0x404040)) #define COLOR_BG_BORDER_CHK_PR (IS_LIGHT ? lv_color_hex(0x3b3e42) : lv_color_hex(0x404040)) -#define COLOR_BG_BORDER_DIS (IS_LIGHT ? lv_color_hex(0xdfe7ed) : lv_color_hex(0x404040)) +#define COLOR_BG_BORDER_DIS (IS_LIGHT ? lv_color_hex(0xd6dde3) : lv_color_hex(0x404040)) #define COLOR_BG_TEXT (IS_LIGHT ? lv_color_hex(0x3b3e42) : lv_color_hex(0xffffff)) #define COLOR_BG_TEXT_PR (IS_LIGHT ? lv_color_hex(0x3b3e42) : lv_color_hex(0xffffff)) @@ -275,8 +275,8 @@ static void basic_init(void) lv_style_set_value_color(&btn, LV_STATE_CHECKED | LV_STATE_PRESSED, lv_color_hex(0xffffff)); lv_style_set_value_color(&btn, LV_STATE_DISABLED, IS_LIGHT ? lv_color_hex(0x888888) : lv_color_hex(0x888888)); - lv_style_set_pad_left(&btn, LV_STATE_DEFAULT, LV_DPI / 7); - lv_style_set_pad_right(&btn, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_left(&btn, LV_STATE_DEFAULT, LV_DPI / 5); + lv_style_set_pad_right(&btn, LV_STATE_DEFAULT, LV_DPI / 5); lv_style_set_pad_top(&btn, LV_STATE_DEFAULT, LV_DPI / 15); lv_style_set_pad_bottom(&btn, LV_STATE_DEFAULT, LV_DPI / 15); lv_style_set_pad_inner(&btn, LV_STATE_DEFAULT, LV_DPI / 10); @@ -391,8 +391,8 @@ static void slider_init(void) lv_style_set_pad_bottom(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_init(&slider_bg); - lv_style_set_margin_left(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 20); - lv_style_set_margin_right(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_margin_left(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 12); + lv_style_set_margin_right(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 12); lv_style_set_margin_top(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_margin_bottom(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 20); @@ -460,12 +460,12 @@ static void gauge_init(void) lv_style_init(&gauge_needle); lv_style_set_line_color(&gauge_needle, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x464b5b) : LV_COLOR_WHITE); - lv_style_set_line_width(&gauge_needle, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_line_width(&gauge_needle, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_bg_opa(&gauge_needle, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&gauge_needle, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x464b5b) : LV_COLOR_WHITE); lv_style_set_radius(&gauge_needle, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_size(&gauge_needle, LV_STATE_DEFAULT, LV_DPI / 7); - lv_style_set_pad_inner(&gauge_needle, LV_STATE_DEFAULT, LV_DPI / 10); + lv_style_set_pad_inner(&gauge_needle, LV_STATE_DEFAULT, LV_DPI / 20); #endif } @@ -605,8 +605,9 @@ static void keyboard_init(void) #if LV_USE_KEYBOARD lv_style_init(&kb_bg); lv_style_set_radius(&kb_bg, LV_STATE_DEFAULT, 0); - lv_style_set_border_width(&kb_bg, LV_STATE_DEFAULT, (LV_DPI / 40 > 0 ? LV_DPI / 40 : 1)); + lv_style_set_border_width(&kb_bg, LV_STATE_DEFAULT, (LV_DPI / 50 > 0 ? LV_DPI / 50 : 1)); lv_style_set_border_side(&kb_bg, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP); + lv_style_set_border_color(&kb_bg, LV_STATE_DEFAULT, COLOR_BG_TEXT); lv_style_set_pad_left(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_pad_right(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_pad_top(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20); @@ -733,6 +734,7 @@ static void ddlist_init(void) lv_style_set_bg_color(&ddlist_sel, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_text_color(&ddlist_sel, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex3(0xfff) : lv_color_hex3(0xfff)); lv_style_set_bg_color(&ddlist_sel, LV_STATE_PRESSED, COLOR_BG_PR); + lv_style_set_text_color(&ddlist_sel, LV_STATE_PRESSED, COLOR_BG_TEXT_PR); #endif } @@ -1009,6 +1011,7 @@ void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name) case LV_THEME_ARC: lv_obj_clean_style_list(obj, LV_ARC_PART_BG); list = lv_obj_get_style_list(obj, LV_ARC_PART_BG); + lv_style_list_add_style(list, &bg); lv_style_list_add_style(list, &arc_bg); lv_obj_clean_style_list(obj, LV_ARC_PART_INDIC); diff --git a/src/lv_widgets/lv_bar.c b/src/lv_widgets/lv_bar.c index e2af54291..e0890e212 100644 --- a/src/lv_widgets/lv_bar.c +++ b/src/lv_widgets/lv_bar.c @@ -384,18 +384,7 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area draw_dsc.pattern_opa = LV_OPA_TRANSP; draw_dsc.outline_opa = LV_OPA_TRANSP; lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_BG, &draw_dsc); -// lv_draw_rect(&bar->coords, clip_area, &draw_dsc); - - /*Finally draw the indicators value*/ - lv_draw_rect_dsc_init(&draw_dsc); - draw_dsc.bg_opa = LV_OPA_TRANSP; - draw_dsc.border_opa = LV_OPA_TRANSP; - draw_dsc.shadow_opa = LV_OPA_TRANSP; - draw_dsc.pattern_opa = LV_OPA_TRANSP; - draw_dsc.outline_opa = LV_OPA_TRANSP; - lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_INDIC, &draw_dsc); lv_draw_rect(&bar->coords, clip_area, &draw_dsc); - } else if(mode == LV_DESIGN_DRAW_POST) { @@ -555,6 +544,7 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) (!hor && lv_area_get_height(&ext->indic_area) > bg_radius * 2)) { lv_opa_t bg_opa = draw_indic_dsc.bg_opa; lv_opa_t border_opa = draw_indic_dsc.border_opa; + lv_opa_t value_opa = draw_indic_dsc.value_opa; const void * pattern_src = draw_indic_dsc.pattern_image; draw_indic_dsc.bg_opa = LV_OPA_TRANSP; draw_indic_dsc.border_opa = LV_OPA_TRANSP; @@ -563,6 +553,7 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) lv_draw_rect(&ext->indic_area, clip_area, &draw_indic_dsc); draw_indic_dsc.bg_opa = bg_opa; draw_indic_dsc.border_opa = border_opa; + draw_indic_dsc.value_opa = value_opa; draw_indic_dsc.pattern_image = pattern_src; } diff --git a/src/lv_widgets/lv_chart.c b/src/lv_widgets/lv_chart.c index d2a761f77..e20e39423 100644 --- a/src/lv_widgets/lv_chart.c +++ b/src/lv_widgets/lv_chart.c @@ -1301,6 +1301,17 @@ static void draw_x_ticks(lv_obj_t * chart, const lv_area_t * series_area, const lv_coord_t y_ofs = series_area->y1; lv_coord_t h = lv_area_get_height(series_area); lv_coord_t w = lv_area_get_width(series_area); + + /* The columns don't start at the most right position + * so change the width and offset accordingly. */ + if(ext->type == LV_CHART_TYPE_COLUMN) { + uint32_t ser_num = lv_ll_get_len(&ext->series_ll); + lv_coord_t col_w = w / ((ser_num + 1) * ext->point_cnt); /* Suppose + 1 series as separator*/ + x_ofs += col_w / 2 + (col_w * (ser_num) / 2); + w -= col_w * ser_num + col_w; + } + + char buf[LV_CHART_AXIS_TICK_LABEL_MAX_LEN + 1]; /* up to N symbols per label + null terminator */ /* calculate the size of tick marks */ diff --git a/src/lv_widgets/lv_cont.c b/src/lv_widgets/lv_cont.c index 788594318..9b91edd32 100644 --- a/src/lv_widgets/lv_cont.c +++ b/src/lv_widgets/lv_cont.c @@ -558,11 +558,11 @@ static void lv_cont_layout_pretty(lv_obj_t * cont) /*If there is only one object in the row then align it to the middle*/ else if(obj_num == 1) { lv_obj_align(child_rs, cont, LV_ALIGN_IN_TOP_MID, - lv_obj_get_style_margin_left(child_rs, LV_OBJ_PART_MAIN), + 0, act_y + lv_obj_get_style_margin_top(child_rs, LV_OBJ_PART_MAIN)); } /*If there are two object in the row then align them proportionally*/ - else if(obj_num == 2) { + else if(obj_num == 2 && 0) { lv_obj_t * obj1 = child_rs; lv_obj_t * obj2 = lv_ll_get_prev(&cont->child_ll, child_rs); w_row = lv_obj_get_width(obj1) + lv_obj_get_width(obj2); diff --git a/src/lv_widgets/lv_dropdown.c b/src/lv_widgets/lv_dropdown.c index 7bd96eebb..a2f434189 100644 --- a/src/lv_widgets/lv_dropdown.c +++ b/src/lv_widgets/lv_dropdown.c @@ -53,12 +53,8 @@ static void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint1 static lv_res_t page_release_handler(lv_obj_t * page); static void page_press_handler(lv_obj_t * page); static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y); -static void pos_selected(lv_obj_t * ddlist); +static void position_to_selected(lv_obj_t * ddlist); static lv_obj_t * get_label(const lv_obj_t * ddlist); -#if LV_USE_ANIMATION - static void list_anim(void * p, lv_anim_value_t v); - static void close_anim_ready(lv_anim_t * a); -#endif /********************** * STATIC VARIABLES @@ -117,7 +113,6 @@ lv_obj_t * lv_dropdown_create(lv_obj_t * par, const lv_obj_t * copy) ext->option_cnt = 0; ext->dir = LV_DROPDOWN_DIR_DOWN; ext->max_height = (3 * lv_disp_get_ver_res(NULL)) / 4; - ext->anim_time = LV_DROPDOWN_DEF_ANIM_TIME; lv_style_list_init(&ext->style_page); lv_style_list_init(&ext->style_scrlbar); lv_style_list_init(&ext->style_selected); @@ -143,7 +138,6 @@ lv_obj_t * lv_dropdown_create(lv_obj_t * par, const lv_obj_t * copy) ext->sel_opt_id_orig = copy_ext->sel_opt_id; ext->symbol = copy_ext->symbol; ext->max_height = copy_ext->max_height; - ext->anim_time = copy_ext->anim_time; ext->text = copy_ext->text; ext->dir = copy_ext->dir; ext->show_selected = copy_ext->show_selected; @@ -429,20 +423,6 @@ void lv_dropdown_set_show_selected(lv_obj_t * ddlist, bool show) lv_obj_invalidate(ddlist); } -/** - * Set the open/close animation time. - * @param ddlist pointer to a drop down list - * @param anim_time: open/close animation time [ms] - */ -void lv_dropdown_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time) -{ - LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); - - lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); - ext->anim_time = anim_time; -} - - /*===================== * Getter functions *====================*/ @@ -589,20 +569,6 @@ bool lv_dropdown_get_show_selected(lv_obj_t * ddlist) } -/** - * Get the open/close animation time. - * @param ddlist pointer to a drop down list - * @return open/close animation time [ms] - */ -uint16_t lv_dropdown_get_anim_time(const lv_obj_t * ddlist) -{ - LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); - - lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); - - return ext->anim_time; -} - /*===================== * Other functions *====================*/ @@ -610,13 +576,9 @@ uint16_t lv_dropdown_get_anim_time(const lv_obj_t * ddlist) /** * Open the drop down list with or without animation * @param ddlist pointer to drop down list object - * @param anim_en LV_ANIM_EN: use animation; LV_ANIM_OFF: not use animations */ -void lv_dropdown_open(lv_obj_t * ddlist, lv_anim_enable_t anim) +void lv_dropdown_open(lv_obj_t * ddlist) { -#if LV_USE_ANIMATION == 0 - (void) anim; /*Unused*/ -#endif lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); if(ext->page) return; @@ -660,87 +622,60 @@ void lv_dropdown_open(lv_obj_t * ddlist, lv_anim_enable_t anim) if(list_h > ext->max_height) list_h = ext->max_height; + lv_dropdown_dir_t dir = ext->dir; + /*No place on the bottom? See if top is better.*/ + if(ext->dir == LV_DROPDOWN_DIR_DOWN) { + if(ddlist->coords.y2 + list_h > LV_VER_RES) { + if(ddlist->coords.y1 > LV_VER_RES - ddlist->coords.y2) { + /*There is more space on the top, so make it drop up*/ + dir = LV_DROPDOWN_DIR_UP; + list_h = ddlist->coords.y1; + } else { + list_h = LV_VER_RES - ddlist->coords.y2; + } + } + } + /*No place on the top? See if bottom is better.*/ + else if(ext->dir == LV_DROPDOWN_DIR_UP) { + if(ddlist->coords.y1 - list_h < 0) { + if(ddlist->coords.y1 < LV_VER_RES - ddlist->coords.y2) { + /*There is more space on the top, so make it drop up*/ + dir = LV_DROPDOWN_DIR_DOWN; + list_h = LV_VER_RES - ddlist->coords.y2; + } else { + list_h = ddlist->coords.y1; + } + } + } + lv_obj_set_height(ext->page, list_h); - pos_selected(ddlist); + position_to_selected(ddlist); - if(ext->dir == LV_DROPDOWN_DIR_DOWN) lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); - else if(ext->dir == LV_DROPDOWN_DIR_UP) lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_TOP_LEFT, 0, 0); - else if(ext->dir == LV_DROPDOWN_DIR_LEFT) lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_LEFT_TOP, 0, 0); - else if(ext->dir == LV_DROPDOWN_DIR_RIGHT)lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_RIGHT_TOP, 0, 0); + if(dir == LV_DROPDOWN_DIR_DOWN) lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + else if(dir == LV_DROPDOWN_DIR_UP) lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_TOP_LEFT, 0, 0); + else if(dir == LV_DROPDOWN_DIR_LEFT) lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_LEFT_TOP, 0, 0); + else if(dir == LV_DROPDOWN_DIR_RIGHT)lv_obj_align(ext->page, ddlist, LV_ALIGN_OUT_RIGHT_TOP, 0, 0); - lv_obj_t * scr = lv_scr_act(); - bool moved = false; - if(ext->dir != LV_DROPDOWN_DIR_UP) { - if(ext->page->coords.y2 > scr->coords.y2) { - lv_obj_set_y(ext->page, lv_obj_get_y(ext->page) - (ext->page->coords.y2 - scr->coords.y2)); - moved = true; + if(ext->dir == LV_DROPDOWN_DIR_LEFT || ext->dir == LV_DROPDOWN_DIR_RIGHT) { + if(ext->page->coords.y2 > LV_VER_RES) { + lv_obj_set_y(ext->page, lv_obj_get_y(ext->page) - (ext->page->coords.y2 - LV_VER_RES)); } } - else { - if(ext->page->coords.y1 < 0) { - lv_obj_set_y(ext->page, 0); - moved = true; - } - } - -#if LV_USE_ANIMATION - if(anim == LV_ANIM_ON && ext->dir != LV_DROPDOWN_DIR_UP && !moved) { - lv_anim_t a; - lv_anim_init(&a); - lv_anim_set_var(&a, ddlist); - lv_anim_set_exec_cb(&a, list_anim); - lv_anim_set_values(&a, 0, lv_obj_get_height(ext->page)); - lv_anim_set_time(&a, ext->anim_time); - lv_anim_start(&a); - } -#else - (void)moved; /*Unused*/ -#endif } /** * Close (Collapse) the drop down list * @param ddlist pointer to drop down list object - * @param anim_en LV_ANIM_ON: use animation; LV_ANIM_OFF: not use animations */ -void lv_dropdown_close(lv_obj_t * ddlist, lv_anim_enable_t anim) +void lv_dropdown_close(lv_obj_t * ddlist) { -#if LV_USE_ANIMATION == 0 - anim = false; -#endif lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); if(ext->page == NULL) return; ext->pr_opt_id = LV_DROPDOWN_PR_NONE; - - if(ext->anim_time == 0 || anim == LV_ANIM_OFF) { -#if LV_USE_ANIMATION - lv_anim_del(ddlist, list_anim); -#endif - lv_obj_del(ext->page); - ext->page = NULL; - } - else { -#if LV_USE_ANIMATION - if(ext->dir != LV_DROPDOWN_DIR_UP) { - lv_anim_t a; - lv_anim_init(&a); - lv_anim_set_var(&a, ddlist); - lv_anim_set_exec_cb(&a, list_anim); - lv_anim_set_values(&a, lv_obj_get_height(ext->page), 0); - lv_anim_set_time(&a, ext->anim_time); - lv_anim_set_ready_cb(&a, close_anim_ready); - lv_anim_start(&a); - } - else { - lv_anim_del(ddlist, list_anim); - lv_obj_del(ext->page); - ext->page = NULL; - } -#endif - } - + lv_obj_del(ext->page); + ext->page = NULL; } /********************** @@ -934,7 +869,7 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p } } else if(sign == LV_SIGNAL_CLEANUP) { - lv_dropdown_close(ddlist, LV_ANIM_OFF); + lv_dropdown_close(ddlist); if(ext->static_txt == 0) { lv_mem_free(ext->options); ext->options = NULL; @@ -956,27 +891,27 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p /*Encoders need special handling*/ if(indev_type == LV_INDEV_TYPE_ENCODER) { /*Open the list if editing*/ - if(editing) lv_dropdown_open(ddlist, LV_ANIM_ON); + if(editing) lv_dropdown_open(ddlist); /*Close the list if navigating*/ else - lv_dropdown_close(ddlist, LV_ANIM_ON); + lv_dropdown_close(ddlist); } #endif } else if(sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_LEAVE) { - lv_dropdown_close(ddlist, LV_ANIM_ON); + lv_dropdown_close(ddlist); } else if(sign == LV_SIGNAL_RELEASED) { if(lv_indev_is_dragging(lv_indev_get_act()) == false) { if(ext->page) { - lv_dropdown_close(ddlist, LV_ANIM_ON); + lv_dropdown_close(ddlist); if(ext->sel_opt_id_orig != ext->sel_opt_id) { ext->sel_opt_id_orig = ext->sel_opt_id; lv_obj_invalidate(ddlist); } } else { - lv_dropdown_open(ddlist, LV_ANIM_ON); + lv_dropdown_open(ddlist); } } else { @@ -985,7 +920,7 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p } } else if(sign == LV_SIGNAL_COORD_CHG) { - if(ext->page) lv_dropdown_close(ddlist, LV_ANIM_OFF); + if(ext->page) lv_dropdown_close(ddlist); } else if(sign == LV_SIGNAL_STYLE_CHG) { lv_style_int_t top = lv_obj_get_style_pad_top(ddlist, LV_DROPDOWN_PART_MAIN); @@ -999,26 +934,26 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p char c = *((char *)param); if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN) { if(ext->page == NULL) { - lv_dropdown_open(ddlist, LV_ANIM_ON); + lv_dropdown_open(ddlist); } else if(ext->sel_opt_id + 1 < ext->option_cnt) { ext->sel_opt_id++; - pos_selected(ddlist); + position_to_selected(ddlist); } } else if(c == LV_KEY_LEFT || c == LV_KEY_UP) { if(ext->page == NULL) { - lv_dropdown_open(ddlist, LV_ANIM_ON); + lv_dropdown_open(ddlist); } else if(ext->sel_opt_id > 0) { ext->sel_opt_id--; - pos_selected(ddlist); + position_to_selected(ddlist); } } else if(c == LV_KEY_ESC) { ext->sel_opt_id = ext->sel_opt_id_orig; - lv_dropdown_close(ddlist, LV_ANIM_ON); + lv_dropdown_close(ddlist); } } else if(sign == LV_SIGNAL_GET_EDITABLE) { @@ -1262,7 +1197,7 @@ static lv_res_t page_release_handler(lv_obj_t * page) ext->sel_opt_id_orig = ext->sel_opt_id; } - lv_dropdown_close(ddlist, LV_ANIM_ON); + lv_dropdown_close(ddlist); /*Invalidate to refresh the text*/ if(ext->show_selected) lv_obj_invalidate(ddlist); @@ -1322,7 +1257,7 @@ static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y) * Set the position of list when it is closed to show the selected item * @param ddlist pointer to a drop down list */ -static void pos_selected(lv_obj_t * ddlist) +static void position_to_selected(lv_obj_t * ddlist) { lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); @@ -1351,21 +1286,4 @@ static lv_obj_t * get_label(const lv_obj_t * ddlist) return lv_obj_get_child(lv_page_get_scrl(ext->page), NULL); } -#if LV_USE_ANIMATION -static void list_anim(void * p, lv_anim_value_t v) -{ - lv_obj_t * ddlist = p; - lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); - lv_obj_set_height(ext->page, v); -} - -static void close_anim_ready(lv_anim_t * a) -{ - lv_obj_t * ddlist = a->var; - lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); - lv_obj_del(ext->page); - ext->page = NULL; -} -#endif - #endif diff --git a/src/lv_widgets/lv_dropdown.h b/src/lv_widgets/lv_dropdown.h index 51cd1d9f2..f88dd72bd 100644 --- a/src/lv_widgets/lv_dropdown.h +++ b/src/lv_widgets/lv_dropdown.h @@ -62,7 +62,6 @@ typedef struct { uint16_t sel_opt_id; /*Index of the currently selected option*/ uint16_t sel_opt_id_orig; /*Store the original index on focus*/ uint16_t pr_opt_id; /*Index of the currently pressed option*/ - uint16_t anim_time; lv_dropdown_dir_t dir : 2; uint8_t show_selected : 1; uint8_t static_txt : 1; @@ -164,13 +163,6 @@ void lv_dropdown_set_symbol(lv_obj_t * ddlist, const char * symbol); */ void lv_dropdown_set_show_selected(lv_obj_t * ddlist, bool show); -/** - * Set the open/close animation time. - * @param ddlist pointer to a drop down list - * @param anim_time: open/close animation time [ms] - */ -void lv_dropdown_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time); - /*===================== * Getter functions *====================*/ @@ -239,13 +231,6 @@ lv_dropdown_dir_t lv_dropdown_get_dir(const lv_obj_t * ddlist); */ bool lv_dropdown_get_show_selected(lv_obj_t * ddlist); -/** - * Get the open/close animation time. - * @param ddlist pointer to a drop down list - * @return open/close animation time [ms] - */ -uint16_t lv_dropdown_get_anim_time(const lv_obj_t * ddlist); - /*===================== * Other functions *====================*/ @@ -253,16 +238,15 @@ uint16_t lv_dropdown_get_anim_time(const lv_obj_t * ddlist); /** * Open the drop down list with or without animation * @param ddlist pointer to drop down list object - * @param anim_en LV_ANIM_ON: use animation; LV_ANOM_OFF: not use animations */ -void lv_dropdown_open(lv_obj_t * ddlist, lv_anim_enable_t anim); +void lv_dropdown_open(lv_obj_t * ddlist); /** * Close (Collapse) the drop down list * @param ddlist pointer to drop down list object * @param anim_en LV_ANIM_ON: use animation; LV_ANOM_OFF: not use animations */ -void lv_dropdown_close(lv_obj_t * ddlist, lv_anim_enable_t anim); +void lv_dropdown_close(lv_obj_t * ddlist); /********************** * MACROS diff --git a/src/lv_widgets/lv_page.c b/src/lv_widgets/lv_page.c index 0879a0765..7b6e85a1a 100644 --- a/src/lv_widgets/lv_page.c +++ b/src/lv_widgets/lv_page.c @@ -393,7 +393,7 @@ lv_coord_t lv_page_get_width_grid(lv_obj_t * page, uint8_t div, uint8_t span) lv_coord_t obj_w = lv_page_get_width_fit(page); lv_style_int_t pinner = lv_obj_get_style_pad_inner(page, LV_PAGE_PART_SCRL); - lv_coord_t r = obj_w / div - (div - 1) * pinner; + lv_coord_t r = (obj_w - (div - 1) * pinner) / div; r = r * span + (span - 1) * pinner; return r; @@ -415,7 +415,7 @@ lv_coord_t lv_page_get_height_grid(lv_obj_t * page, uint8_t div, uint8_t span) lv_coord_t obj_h = lv_page_get_height_fit(page); lv_style_int_t pinner = lv_obj_get_style_pad_inner(page, LV_PAGE_PART_SCRL); - lv_coord_t r = obj_h / div - (div - 1) * pinner; + lv_coord_t r = (obj_h - (div - 1) * pinner) / div; r = r * span + (span - 1) * pinner; return r;