diff --git a/examples/widgets/tabview/lv_example_tabview_1.c b/examples/widgets/tabview/lv_example_tabview_1.c index 17fc82e484..9e679a19eb 100644 --- a/examples/widgets/tabview/lv_example_tabview_1.c +++ b/examples/widgets/tabview/lv_example_tabview_1.c @@ -14,10 +14,13 @@ 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" + lv_label_set_text(label, "This the first tab\n" + "\n" + "\n" + "\n" "If the content\n" "of a tab\n" - "becomes too\n" + "becomes\n" "longer\n" "than the\n" "container\n" @@ -28,7 +31,17 @@ void lv_example_tabview_1(void) "\n" "\n" "\n" - "Can you see it?"); + "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?"); label = lv_label_create(tab2); lv_label_set_text(label, "Second tab"); diff --git a/src/core/lv_obj_pos.c b/src/core/lv_obj_pos.c index 11dcac65f3..239b13a8c0 100644 --- a/src/core/lv_obj_pos.c +++ b/src/core/lv_obj_pos.c @@ -609,8 +609,12 @@ 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_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); + 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; if(parent == NULL) { lv_obj_move_to(obj, x, y); return; diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index ed736e8272..c897479536 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -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, 400); + lv_style_set_transform_zoom(&styles->grow, 5); #endif style_init_reset(&styles->knob); @@ -915,6 +915,7 @@ 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 diff --git a/src/misc/lv_area.c b/src/misc/lv_area.c index 2ddddfe116..4aa8afa3d9 100644 --- a/src/misc/lv_area.c +++ b/src/misc/lv_area.c @@ -90,22 +90,25 @@ 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 == 256) { + if(zoom == 0) { lv_area_copy(area_out, area_in); return; } else { - /* 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_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; + } lv_area_copy(area_out, area_in); lv_area_increase(area_out, w_extra, h_extra); - } } diff --git a/src/misc/lv_style.c b/src/misc/lv_style.c index c4d779b91a..a8ba340198 100644 --- a/src/misc/lv_style.c +++ b/src/misc/lv_style.c @@ -211,9 +211,6 @@ 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; diff --git a/src/widgets/lv_img.c b/src/widgets/lv_img.c index 6df402f113..61c2f814bd 100644 --- a/src/widgets/lv_img.c +++ b/src/widgets/lv_img.c @@ -32,6 +32,8 @@ 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 @@ -188,15 +190,14 @@ 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 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 zoom_final = get_zoom_final(obj); + lv_coord_t angle_final = get_angle_final(obj); 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, transf_angle + img->angle, transf_zoom, &img->pivot); + + _lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot); a.x1 += obj->coords.x1; a.y1 += obj->coords.y1; a.x2 += obj->coords.x1; @@ -206,7 +207,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, transf_angle + img->angle, transf_zoom, &img->pivot); + _lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot); a.x1 += obj->coords.x1; a.y1 += obj->coords.y1; a.x2 += obj->coords.x1; @@ -219,16 +220,13 @@ 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 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 zoom_final = get_zoom_final(obj); + lv_coord_t angle_final = get_angle_final(obj); 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, transf_angle, transf_zoom, &img->pivot); + _lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot); a.x1 += obj->coords.x1; a.y1 += obj->coords.y1; a.x2 += obj->coords.x1; @@ -239,7 +237,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, transf_angle, transf_zoom, &img->pivot); + _lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot); a.x1 += obj->coords.x1; a.y1 += obj->coords.y1; a.x2 += obj->coords.x1; @@ -254,15 +252,13 @@ void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom) if(zoom == 0) zoom = 1; - 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 zoom_final = get_zoom_final(obj); + lv_coord_t angle_final = get_angle_final(obj); 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, transf_angle, (transf_zoom * img->zoom) >> 8, &img->pivot); + _lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot); a.x1 += obj->coords.x1 - 1; a.y1 += obj->coords.y1 - 1; a.x2 += obj->coords.x1 + 1; @@ -272,7 +268,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, transf_angle, (transf_zoom * img->zoom) >> 8, &img->pivot); + _lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot); a.x1 += obj->coords.x1 - 1; a.y1 += obj->coords.y1 - 1; a.x2 += obj->coords.x1 + 1; @@ -420,18 +416,16 @@ 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 transf_angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN); - transf_angle += img->angle; + lv_coord_t zoom_final = get_zoom_final(obj); + lv_coord_t angle_final = get_angle_final(obj); /*If the image has angle provide enough room for the rotated corners*/ - if(transf_angle || transf_zoom != LV_IMG_ZOOM_NONE) { + if(angle_final || zoom_final != 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, transf_angle, transf_zoom, &img->pivot); + _lv_img_buf_get_transformed_area(&a, w, h, angle_final, zoom_final, &img->pivot); lv_coord_t pad_ori = *s; *s = LV_MAX(*s, pad_ori - a.x1); *s = LV_MAX(*s, pad_ori - a.y1); @@ -441,21 +435,19 @@ 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 angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN); - angle += img->angle; + lv_coord_t zoom_final = get_zoom_final(obj); + lv_coord_t angle_final = get_angle_final(obj); /*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 != LV_IMG_ZOOM_NONE || angle != 0 || img->pivot.x != img->w / 2 || img->pivot.y != img->h / 2)) { + (zoom_final != LV_IMG_ZOOM_NONE || angle_final != 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, zoom, &img->pivot); + _lv_img_buf_get_transformed_area(&coords, w, h, angle_final, zoom_final, &img->pivot); coords.x1 += obj->coords.x1; coords.y1 += obj->coords.y1; coords.x2 += obj->coords.x1; @@ -504,17 +496,14 @@ 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; } - 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); const lv_area_t * clip_area = lv_event_get_param(e); if(zoom_final == LV_IMG_ZOOM_NONE) { @@ -539,11 +528,9 @@ 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; - int32_t angle_final = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN); - angle_final += img->angle; + lv_coord_t zoom_final = get_zoom_final(obj); + lv_coord_t angle_final = get_angle_final(obj); lv_coord_t obj_w = lv_obj_get_width(obj); lv_coord_t obj_h = lv_obj_get_height(obj); @@ -638,4 +625,23 @@ 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