1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

Revert "feat(style) make transform_zoom use pixel or percentage value"

This reverts commit 5b4e9fc6f35b2be5cd8687d84012d245b5f971e1.
This commit is contained in:
Gabor Kiss-Vamosi 2021-04-18 19:31:38 +02:00
parent 5b4e9fc6f3
commit 32bd067778
6 changed files with 59 additions and 83 deletions

View File

@ -14,13 +14,10 @@ void lv_example_tabview_1(void)
/*Add content to the tabs*/
lv_obj_t * label = lv_label_create(tab1);
lv_label_set_text(label, "This the first tab\n"
"\n"
"\n"
"\n"
lv_label_set_text(label, "This the first tab\n\n"
"If the content\n"
"of a tab\n"
"becomes\n"
"becomes too\n"
"longer\n"
"than the\n"
"container\n"
@ -31,17 +28,7 @@ void lv_example_tabview_1(void)
"\n"
"\n"
"\n"
"Here a couple\n"
"of more extra\n"
"line to sure\n"
"the label is long\n"
"enough even on\n"
"large screens.\n"
"\n"
"\n"
"\n"
"Can you see the\n"
"scrollbars?");
"Can you see it?");
label = lv_label_create(tab2);
lv_label_set_text(label, "Second tab");

View File

@ -609,12 +609,8 @@ 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 tr_x = lv_obj_get_style_transform_x(obj, LV_PART_MAIN);
lv_coord_t tr_y = lv_obj_get_style_transform_y(obj, LV_PART_MAIN);
if(LV_COORD_IS_PCT(tr_x)) tr_x = (lv_obj_get_width(obj) * LV_COORD_GET_PCT(tr_x)) / 100;
if(LV_COORD_IS_PCT(tr_y)) tr_y = (lv_obj_get_height(obj) * LV_COORD_GET_PCT(tr_y)) / 100;
lv_coord_t x = lv_obj_get_style_x(obj, LV_PART_MAIN) + tr_x;
lv_coord_t y = lv_obj_get_style_y(obj, LV_PART_MAIN) + tr_y;
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;

View File

@ -363,7 +363,7 @@ static void style_init(void)
#if LV_THEME_DEFAULT_GROW
style_init_reset(&styles->grow);
lv_style_set_transform_zoom(&styles->grow, 5);
lv_style_set_transform_zoom(&styles->grow, 400);
#endif
style_init_reset(&styles->knob);
@ -915,7 +915,6 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
#if LV_USE_TABVIEW
if(lv_obj_check_type(obj, &lv_tabview_class)) {
lv_obj_add_style(obj, &styles->scr, 0);
lv_obj_add_style(obj, &styles->pad_zero, 0);
return;
}
#endif

View File

@ -90,25 +90,22 @@ uint32_t lv_area_get_size(const lv_area_t * area_p)
void lv_area_zoom(int32_t zoom, const lv_area_t * area_in, lv_area_t * area_out)
{
if(zoom == 0) {
if(zoom == 256) {
lv_area_copy(area_out, area_in);
return;
} else {
lv_coord_t w_extra;
lv_coord_t h_extra;
if(LV_COORD_IS_PCT(zoom)) {
lv_coord_t w = lv_area_get_width(area_in);
lv_coord_t h = lv_area_get_height(area_in);
w_extra = (w * zoom) / 100;
h_extra = (h * zoom) / 100;
} else {
w_extra = zoom;
h_extra = zoom;
}
/* Zoom symmetrically
* extra_width_on_left = (((w * zoom) >> 8) - w) / 2
* extra_width_on_left = (w * (zoom >> 8) - 1) / 2
* extra_width_on_left = (w * (zoom - 256) >> 8) / 2 */
lv_coord_t w = lv_area_get_width(area_in);
lv_coord_t h = lv_area_get_height(area_in);
lv_coord_t w_extra = (w * (zoom - 256) >> 8) / 2;
lv_coord_t h_extra = (h * (zoom - 256) >> 8) / 2;
lv_area_copy(area_out, area_in);
lv_area_increase(area_out, w_extra, h_extra);
}
}

View File

@ -211,6 +211,9 @@ lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop)
{
lv_style_value_t value;
switch(prop) {
case LV_STYLE_TRANSFORM_ZOOM:
value.num = LV_IMG_ZOOM_NONE;
break;
case LV_STYLE_BG_COLOR:
value.color = lv_color_white();
break;

View File

@ -32,8 +32,6 @@ static void lv_img_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
static void lv_img_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj);
static void lv_img_event(lv_event_t * e);
static void draw_img(lv_event_t * e);
static lv_coord_t get_zoom_final(lv_obj_t * obj);
static lv_coord_t get_angle_final(lv_obj_t * obj);
/**********************
* STATIC VARIABLES
@ -190,14 +188,15 @@ void lv_img_set_angle(lv_obj_t * obj, int16_t angle)
lv_img_t * img = (lv_img_t *)obj;
if(angle == img->angle) return;
lv_coord_t zoom_final = get_zoom_final(obj);
lv_coord_t angle_final = get_angle_final(obj);
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
transf_zoom = (transf_zoom * img->zoom) >> 8;
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
lv_area_t a;
_lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle + img->angle, transf_zoom, &img->pivot);
a.x1 += obj->coords.x1;
a.y1 += obj->coords.y1;
a.x2 += obj->coords.x1;
@ -207,7 +206,7 @@ void lv_img_set_angle(lv_obj_t * obj, int16_t angle)
img->angle = angle;
lv_obj_refresh_ext_draw_size(obj);
_lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle + img->angle, transf_zoom, &img->pivot);
a.x1 += obj->coords.x1;
a.y1 += obj->coords.y1;
a.x2 += obj->coords.x1;
@ -220,13 +219,16 @@ void lv_img_set_pivot(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
lv_img_t * img = (lv_img_t *)obj;
if(img->pivot.x == x && img->pivot.y == y) return;
lv_coord_t zoom_final = get_zoom_final(obj);
lv_coord_t angle_final = get_angle_final(obj);
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
transf_zoom = (transf_zoom * img->zoom) >> 8;
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
transf_angle += img->angle;
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
lv_area_t a;
_lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, transf_zoom, &img->pivot);
a.x1 += obj->coords.x1;
a.y1 += obj->coords.y1;
a.x2 += obj->coords.x1;
@ -237,7 +239,7 @@ void lv_img_set_pivot(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
img->pivot.y = y;
lv_obj_refresh_ext_draw_size(obj);
_lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, transf_zoom, &img->pivot);
a.x1 += obj->coords.x1;
a.y1 += obj->coords.y1;
a.x2 += obj->coords.x1;
@ -252,13 +254,15 @@ void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom)
if(zoom == 0) zoom = 1;
lv_coord_t zoom_final = get_zoom_final(obj);
lv_coord_t angle_final = get_angle_final(obj);
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
transf_angle += img->angle;
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
lv_area_t a;
_lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, (transf_zoom * img->zoom) >> 8, &img->pivot);
a.x1 += obj->coords.x1 - 1;
a.y1 += obj->coords.y1 - 1;
a.x2 += obj->coords.x1 + 1;
@ -268,7 +272,7 @@ void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom)
img->zoom = zoom;
lv_obj_refresh_ext_draw_size(obj);
_lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, (transf_zoom * img->zoom) >> 8, &img->pivot);
a.x1 += obj->coords.x1 - 1;
a.y1 += obj->coords.y1 - 1;
a.x2 += obj->coords.x1 + 1;
@ -416,16 +420,18 @@ static void lv_img_event(lv_event_t * e)
else if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) {
lv_coord_t * s = lv_event_get_param(e);
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
transf_zoom = (transf_zoom * img->zoom) >> 8;
lv_coord_t zoom_final = get_zoom_final(obj);
lv_coord_t angle_final = get_angle_final(obj);
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
transf_angle += img->angle;
/*If the image has angle provide enough room for the rotated corners*/
if(angle_final || zoom_final != LV_IMG_ZOOM_NONE) {
if(transf_angle || transf_zoom != LV_IMG_ZOOM_NONE) {
lv_area_t a;
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
_lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot);
_lv_img_buf_get_transformed_area(&a, w, h, transf_angle, transf_zoom, &img->pivot);
lv_coord_t pad_ori = *s;
*s = LV_MAX(*s, pad_ori - a.x1);
*s = LV_MAX(*s, pad_ori - a.y1);
@ -435,19 +441,21 @@ static void lv_img_event(lv_event_t * e)
}
else if(code == LV_EVENT_HIT_TEST) {
lv_hit_test_info_t * info = lv_event_get_param(e);
lv_coord_t zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
zoom = (zoom * img->zoom) >> 8;
lv_coord_t zoom_final = get_zoom_final(obj);
lv_coord_t angle_final = get_angle_final(obj);
lv_coord_t angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
angle += img->angle;
/*If the object is exactly image sized (not cropped, not mosaic) and transformed
*perform hit test on it's transformed area*/
if(img->w == lv_obj_get_width(obj) && img->h == lv_obj_get_height(obj) &&
(zoom_final != LV_IMG_ZOOM_NONE || angle_final != 0 || img->pivot.x != img->w / 2 || img->pivot.y != img->h / 2)) {
(zoom != LV_IMG_ZOOM_NONE || angle != 0 || img->pivot.x != img->w / 2 || img->pivot.y != img->h / 2)) {
lv_coord_t w = lv_obj_get_width(obj);
lv_coord_t h = lv_obj_get_height(obj);
lv_area_t coords;
_lv_img_buf_get_transformed_area(&coords, w, h, angle_final, zoom_final, &img->pivot);
_lv_img_buf_get_transformed_area(&coords, w, h, angle, zoom, &img->pivot);
coords.x1 += obj->coords.x1;
coords.y1 += obj->coords.y1;
coords.x2 += obj->coords.x1;
@ -496,14 +504,17 @@ static void draw_img(lv_event_t * e)
return;
}
int32_t angle_final = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
angle_final += img->angle;
lv_coord_t angle_final = get_angle_final(obj);
if(angle_final != 0) {
info->res = LV_DRAW_RES_NOT_COVER;
return;
}
lv_coord_t zoom_final = get_zoom_final(obj);
int32_t zoom_final = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
zoom_final = (zoom_final * img->zoom) >> 8;
const lv_area_t * clip_area = lv_event_get_param(e);
if(zoom_final == LV_IMG_ZOOM_NONE) {
@ -528,9 +539,11 @@ static void draw_img(lv_event_t * e)
}
else if(code == LV_EVENT_DRAW_MAIN || code == LV_EVENT_DRAW_POST) {
int32_t zoom_final = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
zoom_final = (zoom_final * img->zoom) >> 8;
lv_coord_t zoom_final = get_zoom_final(obj);
lv_coord_t angle_final = get_angle_final(obj);
int32_t angle_final = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
angle_final += img->angle;
lv_coord_t obj_w = lv_obj_get_width(obj);
lv_coord_t obj_h = lv_obj_get_height(obj);
@ -625,23 +638,4 @@ static void draw_img(lv_event_t * e)
}
}
static lv_coord_t get_zoom_final(lv_obj_t * obj)
{
lv_img_t * img = (lv_img_t *)obj;
lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
if(LV_COORD_IS_PCT(transf_zoom)) {
transf_zoom = (LV_COORD_GET_PCT(transf_zoom) * LV_IMG_ZOOM_NONE) / 100;
return (img->zoom * transf_zoom) >> 8;
} else {
return img->zoom;
}
}
static lv_coord_t get_angle_final(lv_obj_t * obj)
{
lv_img_t * img = (lv_img_t *)obj;
lv_coord_t transf_angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
return transf_angle + img->angle;
}
#endif