add initials version of margin (style property)

This commit is contained in:
Gabor Kiss-Vamosi
2020-04-08 11:12:06 +02:00
parent 5ab7222bd9
commit d04d5ab4d4
12 changed files with 501 additions and 108 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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),

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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
*====================*/

View File

@@ -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

View File

@@ -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) {

View File

@@ -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
*====================*/

View File

@@ -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*/