From 9787d38781ff1dca134565b1567afdb1dbcea922 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 15 Apr 2021 18:31:50 +0200 Subject: [PATCH] feat(style) add transform_x/y --- examples/layouts/flex/lv_example_flex_1.c | 4 +-- examples/layouts/grid/lv_example_grid_1.c | 2 +- scripts/style_api_gen.py | 2 ++ src/core/lv_obj_pos.c | 12 ++++----- src/core/lv_obj_style.c | 8 +++++- src/core/lv_obj_style_gen.h | 28 ++++++++++++++++++++ src/extra/layouts/flex/lv_flex.c | 4 +-- src/extra/layouts/grid/lv_grid.c | 4 +++ src/extra/themes/default/lv_theme_default.c | 1 + src/misc/lv_style.h | 29 ++++++++++++--------- src/misc/lv_style_gen.h | 16 ++++++++++++ 11 files changed, 85 insertions(+), 25 deletions(-) diff --git a/examples/layouts/flex/lv_example_flex_1.c b/examples/layouts/flex/lv_example_flex_1.c index 60c157e56..7e6f1e971 100644 --- a/examples/layouts/flex/lv_example_flex_1.c +++ b/examples/layouts/flex/lv_example_flex_1.c @@ -24,7 +24,7 @@ void lv_example_flex_1(void) lv_obj_t * label; /*Add items to the row*/ - obj= lv_obj_create(cont_row); + obj= lv_btn_create(cont_row); lv_obj_set_size(obj, 100, LV_SIZE_PCT(100)); label = lv_label_create(obj); @@ -32,7 +32,7 @@ void lv_example_flex_1(void) lv_obj_center(label); /*Add items to the column*/ - obj = lv_obj_create(cont_col); + obj = lv_btn_create(cont_col); lv_obj_set_size(obj, LV_SIZE_PCT(100), LV_SIZE_CONTENT); label = lv_label_create(obj); diff --git a/examples/layouts/grid/lv_example_grid_1.c b/examples/layouts/grid/lv_example_grid_1.c index 05ddcb4af..fbf0251b9 100644 --- a/examples/layouts/grid/lv_example_grid_1.c +++ b/examples/layouts/grid/lv_example_grid_1.c @@ -25,7 +25,7 @@ void lv_example_grid_1(void) uint8_t col = i % 3; uint8_t row = i / 3; - obj = lv_obj_create(cont); + obj = lv_btn_create(cont); /*Stretch the cell horizontally and vertically too *Set span to 1 to make the cell 1 column/row sized*/ lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1, diff --git a/scripts/style_api_gen.py b/scripts/style_api_gen.py index 0bb883180..32b3f68ed 100755 --- a/scripts/style_api_gen.py +++ b/scripts/style_api_gen.py @@ -7,6 +7,8 @@ props = [ {'name': 'CLIP_CORNER', 'style_type': 'num', 'var_type': 'bool' }, {'name': 'TRANSFORM_WIDTH', 'style_type': 'num', 'var_type': 'lv_coord_t' }, {'name': 'TRANSFORM_HEIGHT', 'style_type': 'num', 'var_type': 'lv_coord_t' }, +{'name': 'TRANSFORM_X', 'style_type': 'num', 'var_type': 'lv_coord_t' }, +{'name': 'TRANSFORM_Y', 'style_type': 'num', 'var_type': 'lv_coord_t' }, {'name': 'TRANSFORM_ZOOM', 'style_type': 'num', 'var_type': 'lv_coord_t' }, {'name': 'TRANSFORM_ANGLE', 'style_type': 'num', 'var_type': 'lv_coord_t' }, {'name': 'OPA', 'style_type': 'num', 'var_type': 'lv_opa_t' }, diff --git a/src/core/lv_obj_pos.c b/src/core/lv_obj_pos.c index 4d57c3bd1..4695e6aaf 100644 --- a/src/core/lv_obj_pos.c +++ b/src/core/lv_obj_pos.c @@ -589,9 +589,11 @@ bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj) void lv_obj_refr_pos(lv_obj_t * obj) { + if(lv_obj_is_layout_positioned(obj)) return; + lv_obj_t * parent = lv_obj_get_parent(obj); - lv_coord_t x = lv_obj_get_style_x(obj, LV_PART_MAIN); - lv_coord_t y = lv_obj_get_style_y(obj, LV_PART_MAIN); + lv_coord_t x = lv_obj_get_style_x(obj, LV_PART_MAIN) + lv_obj_get_style_transform_x(obj, LV_PART_MAIN); + lv_coord_t y = lv_obj_get_style_y(obj, LV_PART_MAIN) + lv_obj_get_style_transform_y(obj, LV_PART_MAIN); if(parent == NULL) { lv_obj_move_to(obj, x, y); return; @@ -645,8 +647,6 @@ void lv_obj_refr_pos(lv_obj_t * obj) void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) { - if(lv_obj_is_layout_positioned(obj)) return; - /*Convert x and y to absolute coordinates*/ lv_obj_t * parent = obj->parent; @@ -924,13 +924,13 @@ static void layout_update_core(lv_obj_t * obj) /*Be sure the left side is not remains scrolled in*/ if(sr < 0 && sl > 0) { sr = LV_MIN(sl, -sr); - lv_obj_scroll_by(obj, 0, sr, LV_ANIM_OFF); + lv_obj_scroll_by(obj, sr, 0, LV_ANIM_OFF); } } else { /*Be sure the right side is not remains scrolled in*/ if(sl < 0 && sr > 0) { sr = LV_MIN(sr, -sl); - lv_obj_scroll_by(obj, 0, sl, LV_ANIM_OFF); + lv_obj_scroll_by(obj, sl, 0, LV_ANIM_OFF); } } diff --git a/src/core/lv_obj_style.c b/src/core/lv_obj_style.c index a91f472e8..7062d46cc 100644 --- a/src/core/lv_obj_style.c +++ b/src/core/lv_obj_style.c @@ -174,7 +174,13 @@ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_selector_t selector, lv_style if((part == LV_PART_ANY || part == LV_PART_MAIN) && (prop == LV_STYLE_PROP_ALL || (prop & LV_STYLE_PROP_LAYOUT_REFR))) { lv_event_send(obj, LV_EVENT_STYLE_CHANGED, NULL); /*To update layout*/ - } else if(prop & LV_STYLE_PROP_EXT_DRAW) { + if(obj->parent) obj->parent->layout_inv = 1; + } + if((part == LV_PART_ANY || part == LV_PART_MAIN) && (prop == LV_STYLE_PROP_ALL || (prop & LV_STYLE_PROP_PARENT_LAYOUT_REFR))) { + lv_obj_t * parent = lv_obj_get_parent(obj); + if(parent) lv_obj_mark_layout_as_dirty(parent); + } + else if(prop & LV_STYLE_PROP_EXT_DRAW) { lv_obj_refresh_ext_draw_size(obj); } lv_obj_invalidate(obj); diff --git a/src/core/lv_obj_style_gen.h b/src/core/lv_obj_style_gen.h index 3bd67450d..888a7a48e 100644 --- a/src/core/lv_obj_style_gen.h +++ b/src/core/lv_obj_style_gen.h @@ -22,6 +22,18 @@ static inline lv_coord_t lv_obj_get_style_transform_height(const struct _lv_obj_ return (lv_coord_t)v.num; } +static inline lv_coord_t lv_obj_get_style_transform_x(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_X); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_y(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_Y); + return (lv_coord_t)v.num; +} + static inline lv_coord_t lv_obj_get_style_transform_zoom(const struct _lv_obj_t * obj, uint32_t part) { lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_ZOOM); @@ -546,6 +558,22 @@ static inline void lv_obj_set_style_transform_height(struct _lv_obj_t * obj, lv_ lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSFORM_HEIGHT, v, selector); } +static inline void lv_obj_set_style_transform_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSFORM_X, v, selector); +} + +static inline void lv_obj_set_style_transform_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_obj_set_local_style_prop(obj, LV_STYLE_TRANSFORM_Y, v, selector); +} + static inline void lv_obj_set_style_transform_zoom(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) { lv_style_value_t v = { diff --git a/src/extra/layouts/flex/lv_flex.c b/src/extra/layouts/flex/lv_flex.c index da4a42849..ce41dfb17 100644 --- a/src/extra/layouts/flex/lv_flex.c +++ b/src/extra/layouts/flex/lv_flex.c @@ -399,8 +399,8 @@ static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, i if(f->row && rtl) main_pos -= area_get_main_size(&item->coords); - lv_coord_t diff_x = abs_x - item->coords.x1; - lv_coord_t diff_y = abs_y - item->coords.y1; + lv_coord_t diff_x = abs_x - item->coords.x1 + lv_obj_get_style_transform_x(item, 0); + lv_coord_t diff_y = abs_y - item->coords.y1 + lv_obj_get_style_transform_y(item, 0); diff_x += f->row ? main_pos : cross_pos; diff_y += f->row ? cross_pos : main_pos; diff --git a/src/extra/layouts/grid/lv_grid.c b/src/extra/layouts/grid/lv_grid.c index 171b3144d..ed7f5e300 100644 --- a/src/extra/layouts/grid/lv_grid.c +++ b/src/extra/layouts/grid/lv_grid.c @@ -444,6 +444,10 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * lv_event_send(lv_obj_get_parent(item), LV_EVENT_CHILD_CHANGED, item); } + + x += lv_obj_get_style_transform_x(item, LV_PART_MAIN); + y += lv_obj_get_style_transform_y(item, LV_PART_MAIN); + lv_coord_t diff_x = hint->grid_abs.x + x - item->coords.x1; lv_coord_t diff_y = hint->grid_abs.y + y - item->coords.y1; if(diff_x || diff_y) { diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index c37fb398f..e692f029a 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -193,6 +193,7 @@ static void style_init(void) static const lv_style_prop_t trans_props[] = { LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR, LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_TRANSFORM_HEIGHT, + LV_STYLE_TRANSFORM_Y, LV_STYLE_TRANSFORM_X, LV_STYLE_TRANSFORM_ZOOM, LV_STYLE_TRANSFORM_ANGLE, LV_STYLE_COLOR_FILTER_OPA, LV_STYLE_COLOR_FILTER_DSC, 0 diff --git a/src/misc/lv_style.h b/src/misc/lv_style.h index 87225e6b6..d2bf25400 100644 --- a/src/misc/lv_style.h +++ b/src/misc/lv_style.h @@ -31,10 +31,11 @@ extern "C" { /** * Flags for style properties */ -#define LV_STYLE_PROP_INHERIT (1 << 10) /*Inherited*/ -#define LV_STYLE_PROP_EXT_DRAW (1 << 11) /*Requires ext. draw size update when changed*/ -#define LV_STYLE_PROP_LAYOUT_REFR (1 << 12) /*Requires layout update when changed*/ -#define LV_STYLE_PROP_FILTER (1 << 13) /*Apply color filter*/ +#define LV_STYLE_PROP_INHERIT (1 << 10) /*Inherited*/ +#define LV_STYLE_PROP_EXT_DRAW (1 << 11) /*Requires ext. draw size update when changed*/ +#define LV_STYLE_PROP_LAYOUT_REFR (1 << 12) /*Requires layout update when changed*/ +#define LV_STYLE_PROP_PARENT_LAYOUT_REFR (1 << 13) /*Requires layout update on parent when changed*/ +#define LV_STYLE_PROP_FILTER (1 << 14) /*Apply color filter*/ /** * Other constants @@ -115,16 +116,18 @@ typedef enum { LV_STYLE_CLIP_CORNER = 2, LV_STYLE_TRANSFORM_WIDTH = 3 | LV_STYLE_PROP_EXT_DRAW, LV_STYLE_TRANSFORM_HEIGHT = 4 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_TRANSFORM_ZOOM = 5 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_TRANSFORM_ANGLE = 6 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_OPA = 7 | LV_STYLE_PROP_INHERIT, + LV_STYLE_TRANSFORM_X = 5 | LV_STYLE_PROP_PARENT_LAYOUT_REFR, + LV_STYLE_TRANSFORM_Y = 6 | LV_STYLE_PROP_PARENT_LAYOUT_REFR, + LV_STYLE_TRANSFORM_ZOOM = 7 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_TRANSFORM_ANGLE = 8 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_OPA = 9 | LV_STYLE_PROP_INHERIT, - LV_STYLE_COLOR_FILTER_DSC = 8, - LV_STYLE_COLOR_FILTER_OPA = 9, - LV_STYLE_ANIM_TIME = 10, - LV_STYLE_TRANSITION = 11, - LV_STYLE_SIZE = 12, - LV_STYLE_BLEND_MODE = 13, + LV_STYLE_COLOR_FILTER_DSC = 10, + LV_STYLE_COLOR_FILTER_OPA = 11, + LV_STYLE_ANIM_TIME = 12, + LV_STYLE_TRANSITION = 13, + LV_STYLE_SIZE = 14, + LV_STYLE_BLEND_MODE = 15, /*Group 1*/ LV_STYLE_PAD_TOP = 16 | LV_STYLE_PROP_LAYOUT_REFR, diff --git a/src/misc/lv_style_gen.h b/src/misc/lv_style_gen.h index b75a98eb8..11cdb6823 100644 --- a/src/misc/lv_style_gen.h +++ b/src/misc/lv_style_gen.h @@ -30,6 +30,22 @@ static inline void lv_style_set_transform_height(lv_style_t * style, lv_coord_t lv_style_set_prop(style, LV_STYLE_TRANSFORM_HEIGHT, v); } +static inline void lv_style_set_transform_x(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_TRANSFORM_X, v); +} + +static inline void lv_style_set_transform_y(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_TRANSFORM_Y, v); +} + static inline void lv_style_set_transform_zoom(lv_style_t * style, lv_coord_t value) { lv_style_value_t v = {