mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(style) add transform_x/y
This commit is contained in:
parent
e4345bd7f5
commit
9787d38781
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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' },
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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 = {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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 = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user