mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
fix(bar): fix the clipping of the indicator in some corner cases (#5229)
This commit is contained in:
parent
c6c9e75f27
commit
4699f2f556
@ -87,6 +87,7 @@ lv_draw_task_t * lv_draw_add_task(lv_layer_t * layer, const lv_area_t * coords)
|
||||
lv_draw_task_t * new_task = lv_malloc_zeroed(sizeof(lv_draw_task_t));
|
||||
|
||||
new_task->area = *coords;
|
||||
new_task->_real_area = *coords;
|
||||
new_task->clip_area = layer->_clip_area;
|
||||
new_task->state = LV_DRAW_TASK_STATE_QUEUED;
|
||||
|
||||
@ -285,17 +286,17 @@ lv_draw_task_t * lv_draw_get_next_available_task(lv_layer_t * layer, lv_draw_tas
|
||||
{
|
||||
LV_PROFILER_BEGIN;
|
||||
/*If the first task is screen sized, there cannot be independent areas*/
|
||||
// if(layer->draw_task_head) {
|
||||
// int32_t hor_res = lv_display_get_horizontal_resolution(_lv_refr_get_disp_refreshing());
|
||||
// int32_t ver_res = lv_display_get_vertical_resolution(_lv_refr_get_disp_refreshing());
|
||||
// lv_draw_task_t * t = layer->draw_task_head;
|
||||
// if(t->state != LV_DRAW_TASK_STATE_QUEUED &&
|
||||
// t->area.x1 <= 0 && t->area.x2 >= hor_res - 1 &&
|
||||
// t->area.y1 <= 0 && t->area.y2 >= ver_res - 1) {
|
||||
// LV_PROFILER_END;
|
||||
// return NULL;
|
||||
// }
|
||||
// }
|
||||
if(layer->draw_task_head) {
|
||||
int32_t hor_res = lv_display_get_horizontal_resolution(_lv_refr_get_disp_refreshing());
|
||||
int32_t ver_res = lv_display_get_vertical_resolution(_lv_refr_get_disp_refreshing());
|
||||
lv_draw_task_t * t = layer->draw_task_head;
|
||||
if(t->state != LV_DRAW_TASK_STATE_QUEUED &&
|
||||
t->area.x1 <= 0 && t->area.x2 >= hor_res - 1 &&
|
||||
t->area.y1 <= 0 && t->area.y2 >= ver_res - 1) {
|
||||
LV_PROFILER_END;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
lv_draw_task_t * t = t_prev ? t_prev->next : layer->draw_task_head;
|
||||
while(t) {
|
||||
@ -427,7 +428,7 @@ static bool is_independent(lv_layer_t * layer, lv_draw_task_t * t_check)
|
||||
while(t && t != t_check) {
|
||||
if(t->state != LV_DRAW_TASK_STATE_READY) {
|
||||
lv_area_t a;
|
||||
if(_lv_area_intersect(&a, &t->area, &t_check->area)) {
|
||||
if(_lv_area_intersect(&a, &t->_real_area, &t_check->_real_area)) {
|
||||
LV_PROFILER_END;
|
||||
return false;
|
||||
}
|
||||
|
@ -60,10 +60,15 @@ struct _lv_draw_task_t {
|
||||
lv_draw_task_type_t type;
|
||||
|
||||
/**
|
||||
* The bounding box of the thing to draw
|
||||
* The area where to draw
|
||||
*/
|
||||
lv_area_t area;
|
||||
|
||||
/**
|
||||
* The real draw area. E.g. for shadow, outline, or transformed images it's different from `area`
|
||||
*/
|
||||
lv_area_t _real_area;
|
||||
|
||||
/** The original area which is updated*/
|
||||
lv_area_t clip_area_original;
|
||||
|
||||
|
@ -87,6 +87,8 @@ void lv_draw_buf_invalidate_cache(void * buf, uint32_t stride, lv_color_format_t
|
||||
void lv_draw_buf_clear(void * buf, uint32_t w, uint32_t h, lv_color_format_t color_format, const lv_area_t * a)
|
||||
{
|
||||
LV_UNUSED(h);
|
||||
if(lv_area_get_width(a) < 0) return;
|
||||
if(lv_area_get_height(a) < 0) return;
|
||||
|
||||
uint8_t px_size = lv_color_format_get_size(color_format);
|
||||
uint32_t stride = lv_draw_buf_width_to_stride(w, color_format);
|
||||
|
@ -54,6 +54,14 @@ void lv_draw_image_dsc_init(lv_draw_image_dsc_t * dsc)
|
||||
dsc->base.dsc_size = sizeof(lv_draw_image_dsc_t);
|
||||
}
|
||||
|
||||
void layer_transform(lv_layer_t * layer, lv_area_t * a_out)
|
||||
{
|
||||
if(layer->parent) {
|
||||
layer_transform(layer->parent, a_out);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void lv_draw_layer(lv_layer_t * layer, const lv_draw_image_dsc_t * dsc, const lv_area_t * coords)
|
||||
{
|
||||
lv_draw_task_t * t = lv_draw_add_task(layer, coords);
|
||||
@ -63,6 +71,10 @@ void lv_draw_layer(lv_layer_t * layer, const lv_draw_image_dsc_t * dsc, const lv
|
||||
t->type = LV_DRAW_TASK_TYPE_LAYER;
|
||||
t->state = LV_DRAW_TASK_STATE_WAITING;
|
||||
|
||||
_lv_image_buf_get_transformed_area(&t->_real_area, lv_area_get_width(coords), lv_area_get_height(coords),
|
||||
dsc->rotation, dsc->scale_x, dsc->scale_y, &dsc->pivot);
|
||||
lv_area_move(&t->_real_area, coords->x1, coords->y1);
|
||||
|
||||
lv_layer_t * layer_to_draw = (lv_layer_t *)dsc->src;
|
||||
layer_to_draw->all_tasks_added = true;
|
||||
|
||||
@ -92,6 +104,10 @@ void lv_draw_image(lv_layer_t * layer, const lv_draw_image_dsc_t * dsc, const lv
|
||||
t->draw_dsc = new_image_dsc;
|
||||
t->type = LV_DRAW_TASK_TYPE_IMAGE;
|
||||
|
||||
_lv_image_buf_get_transformed_area(&t->_real_area, lv_area_get_width(coords), lv_area_get_height(coords),
|
||||
dsc->rotation, dsc->scale_x, dsc->scale_y, &dsc->pivot);
|
||||
lv_area_move(&t->_real_area, coords->x1, coords->y1);
|
||||
|
||||
lv_draw_finalize_task_creation(layer, t);
|
||||
LV_PROFILER_END;
|
||||
}
|
||||
|
@ -129,6 +129,9 @@ void lv_draw_rect(lv_layer_t * layer, const lv_draw_rect_dsc_t * dsc, const lv_a
|
||||
t = lv_draw_add_task(layer, coords);
|
||||
lv_draw_box_shadow_dsc_t * shadow_dsc = lv_malloc(sizeof(lv_draw_box_shadow_dsc_t));
|
||||
t->draw_dsc = shadow_dsc;
|
||||
lv_area_increase(&t->_real_area, dsc->shadow_spread, dsc->shadow_spread);
|
||||
lv_area_increase(&t->_real_area, dsc->shadow_width, dsc->shadow_width);
|
||||
lv_area_move(&t->_real_area, dsc->shadow_offset_x, dsc->shadow_offset_y);
|
||||
shadow_dsc->base = dsc->base;
|
||||
shadow_dsc->base.dsc_size = sizeof(lv_draw_box_shadow_dsc_t);
|
||||
shadow_dsc->radius = dsc->radius;
|
||||
@ -255,6 +258,8 @@ void lv_draw_rect(lv_layer_t * layer, const lv_draw_rect_dsc_t * dsc, const lv_a
|
||||
t = lv_draw_add_task(layer, &outline_coords);
|
||||
lv_draw_border_dsc_t * outline_dsc = lv_malloc(sizeof(lv_draw_border_dsc_t));
|
||||
t->draw_dsc = outline_dsc;
|
||||
lv_area_increase(&t->_real_area, dsc->outline_width, dsc->outline_width);
|
||||
lv_area_increase(&t->_real_area, dsc->outline_pad, dsc->outline_pad);
|
||||
outline_dsc->base = dsc->base;
|
||||
outline_dsc->base.dsc_size = sizeof(lv_draw_border_dsc_t);
|
||||
outline_dsc->radius = dsc->radius == LV_RADIUS_CIRCLE ? LV_RADIUS_CIRCLE : dsc->radius + dsc->outline_width +
|
||||
|
@ -50,6 +50,34 @@ void lv_draw_sw_mask_rect(lv_draw_unit_t * draw_unit, const lv_draw_mask_rect_ds
|
||||
return;
|
||||
}
|
||||
|
||||
lv_layer_t * target_layer = draw_unit->target_layer;
|
||||
|
||||
int32_t buf_w = lv_area_get_width(&target_layer->buf_area);
|
||||
int32_t buf_h = lv_area_get_height(&target_layer->buf_area);
|
||||
lv_area_t clear_area;
|
||||
|
||||
/*Clear the top part*/
|
||||
lv_area_set(&clear_area, draw_unit->clip_area->x1, draw_unit->clip_area->y1, draw_unit->clip_area->x2,
|
||||
dsc->area.y1 - 1);
|
||||
lv_area_move(&clear_area, -target_layer->buf_area.x1, -target_layer->buf_area.y1);
|
||||
lv_draw_buf_clear(target_layer->buf, buf_w, buf_h, target_layer->color_format, &clear_area);
|
||||
|
||||
/*Clear the bottom part*/
|
||||
lv_area_set(&clear_area, draw_unit->clip_area->x1, dsc->area.y2 + 1, draw_unit->clip_area->x2,
|
||||
draw_unit->clip_area->y2);
|
||||
lv_area_move(&clear_area, -target_layer->buf_area.x1, -target_layer->buf_area.y1);
|
||||
lv_draw_buf_clear(target_layer->buf, buf_w, buf_h, target_layer->color_format, &clear_area);
|
||||
|
||||
/*Clear the left part*/
|
||||
lv_area_set(&clear_area, draw_unit->clip_area->x1, dsc->area.y1, dsc->area.x1 - 1, dsc->area.y2);
|
||||
lv_area_move(&clear_area, -target_layer->buf_area.x1, -target_layer->buf_area.y1);
|
||||
lv_draw_buf_clear(target_layer->buf, buf_w, buf_h, target_layer->color_format, &clear_area);
|
||||
|
||||
/*Clear the right part*/
|
||||
lv_area_set(&clear_area, dsc->area.x2 + 1, dsc->area.y1, draw_unit->clip_area->x2, dsc->area.y2);
|
||||
lv_area_move(&clear_area, -target_layer->buf_area.x1, -target_layer->buf_area.y1);
|
||||
lv_draw_buf_clear(target_layer->buf, buf_w, buf_h, target_layer->color_format, &clear_area);
|
||||
|
||||
lv_draw_sw_mask_radius_param_t param;
|
||||
lv_draw_sw_mask_radius_init(¶m, &dsc->area, dsc->radius, false);
|
||||
|
||||
@ -65,7 +93,6 @@ void lv_draw_sw_mask_rect(lv_draw_unit_t * draw_unit, const lv_draw_mask_rect_ds
|
||||
lv_draw_sw_mask_res_t res = lv_draw_sw_mask_apply(masks, mask_buf, draw_area.x1, y, area_w);
|
||||
if(res == LV_DRAW_SW_MASK_RES_FULL_COVER) continue;
|
||||
|
||||
lv_layer_t * target_layer = draw_unit->target_layer;
|
||||
lv_color32_t * c32_buf = lv_draw_layer_go_to_xy(target_layer, draw_area.x1 - target_layer->buf_area.x1,
|
||||
y - target_layer->buf_area.y1);
|
||||
|
||||
|
@ -288,6 +288,7 @@ static void draw_indic(lv_event_t * e)
|
||||
int32_t bg_right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
int32_t bg_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
int32_t bg_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
|
||||
/*Respect padding and minimum width/height too*/
|
||||
lv_area_copy(&bar->indic_area, &bar_coords);
|
||||
bar->indic_area.x1 += bg_left;
|
||||
@ -304,11 +305,11 @@ static void draw_indic(lv_event_t * e)
|
||||
bar->indic_area.x2 = bar->indic_area.x1 + LV_BAR_SIZE_MIN;
|
||||
}
|
||||
|
||||
int32_t indicw = lv_area_get_width(&bar->indic_area);
|
||||
int32_t indich = lv_area_get_height(&bar->indic_area);
|
||||
int32_t indic_max_w = lv_area_get_width(&bar->indic_area);
|
||||
int32_t indic_max_h = lv_area_get_height(&bar->indic_area);
|
||||
|
||||
/*Calculate the indicator length*/
|
||||
int32_t anim_length = hor ? indicw : indich;
|
||||
int32_t anim_length = hor ? indic_max_w : indic_max_h;
|
||||
|
||||
int32_t anim_cur_value_x, anim_start_value_x;
|
||||
|
||||
@ -356,7 +357,7 @@ static void draw_indic(lv_event_t * e)
|
||||
}
|
||||
|
||||
/**
|
||||
* The drawing drection of the bar can be reversed only when one of the two conditions(value inversion
|
||||
* The drawing direction of the bar can be reversed only when one of the two conditions(value inversion
|
||||
* or horizontal direction base dir is LV_BASE_DIR_RTL) is met.
|
||||
*/
|
||||
lv_base_dir_t base_dir = lv_obj_get_style_base_dir(obj, LV_PART_MAIN);
|
||||
@ -441,34 +442,107 @@ static void draw_indic(lv_event_t * e)
|
||||
if(bg_radius > short_side >> 1) bg_radius = short_side >> 1;
|
||||
|
||||
int32_t indic_radius = draw_rect_dsc.radius;
|
||||
short_side = LV_MIN(indicw, indich);
|
||||
short_side = LV_MIN(lv_area_get_width(&bar->indic_area), lv_area_get_height(&bar->indic_area));
|
||||
if(indic_radius > short_side >> 1) indic_radius = short_side >> 1;
|
||||
|
||||
/*TODO handle clipping from gradient*/
|
||||
/*The radius of the bg and the indicator can make a strange shape where
|
||||
*it'd be very difficult to draw shadow.
|
||||
*Draw this strange shape as a layer without shadow*/
|
||||
if(((hor && lv_area_get_width(&bar->indic_area) < indic_radius * 2) ||
|
||||
(!hor && lv_area_get_height(&bar->indic_area) < indic_radius * 2))) {
|
||||
draw_rect_dsc.shadow_width = 0;
|
||||
/*Cases:
|
||||
* Simple:
|
||||
* - indicator area is the same or smaller then the bg
|
||||
* - indicator has the same or larger radius than the bg
|
||||
* - what to do? just draw the indicator
|
||||
* Radius issue:
|
||||
* - indicator area is the same or smaller then bg
|
||||
* - indicator has smaller radius than the bg and the indicator overflows on the corners
|
||||
* - what to do? draw the indicator on a layer and clip to bg radius
|
||||
* Larger indicator:
|
||||
* - indicator area is the larger then the bg
|
||||
* - radius doesn't matter
|
||||
* - shadow doesn't matter
|
||||
* - what to do? just draw the indicator
|
||||
* Shadow:
|
||||
* - indicator area is the same or smaller then the bg
|
||||
* - indicator has the same or larger radius than the bg (shadow needs to be drawn on strange clipped shape)
|
||||
* - what to do? don't draw the shadow if the indicator is too small has strange shape
|
||||
* Gradient:
|
||||
* - the indicator has a gradient
|
||||
* - what to do? draw it on a bg sized layer clip the indicator are from the gradient
|
||||
*
|
||||
*/
|
||||
|
||||
lv_area_t indic_clip_area;
|
||||
if(_lv_area_intersect(&indic_clip_area, &indic_area, &layer->_clip_area)) {
|
||||
lv_layer_t * layer_indic = lv_draw_layer_create(layer, LV_COLOR_FORMAT_ARGB8888, &indic_area);
|
||||
bool gradient = false;
|
||||
if(hor && draw_rect_dsc.bg_grad.dir == LV_GRAD_DIR_HOR) gradient = true;
|
||||
else if(!hor && draw_rect_dsc.bg_grad.dir == LV_GRAD_DIR_VER) gradient = true;
|
||||
|
||||
lv_draw_rect(layer_indic, &draw_rect_dsc, &indic_area);
|
||||
bool radius_issue = true;
|
||||
/*The indicator is fully drawn if it's larger than the bg*/
|
||||
if((bg_left < 0 || bg_right < 0 || bg_top < 0 || bg_bottom < 0)) radius_issue = false;
|
||||
else if(indic_radius >= bg_radius) radius_issue = false;
|
||||
else if(_lv_area_is_in(&indic_area, &bar_coords, bg_radius)) radius_issue = false;
|
||||
|
||||
lv_draw_mask_rect_dsc_t mask_dsc;
|
||||
lv_draw_mask_rect_dsc_init(&mask_dsc);
|
||||
mask_dsc.area = obj->coords;
|
||||
if(radius_issue || gradient) {
|
||||
if(!radius_issue) {
|
||||
/*Draw only the shadow*/
|
||||
lv_draw_rect_dsc_t draw_tmp_dsc = draw_rect_dsc;
|
||||
draw_tmp_dsc.border_opa = 0;
|
||||
draw_tmp_dsc.outline_opa = 0;
|
||||
draw_tmp_dsc.bg_opa = 0;
|
||||
draw_tmp_dsc.bg_image_opa = 0;
|
||||
lv_draw_rect(layer, &draw_tmp_dsc, &indic_area);
|
||||
}
|
||||
else {
|
||||
draw_rect_dsc.border_opa = 0;
|
||||
draw_rect_dsc.outline_opa = 0;
|
||||
}
|
||||
draw_rect_dsc.shadow_opa = 0;
|
||||
|
||||
/*If clipped for any reason can the border, outline, and shadow
|
||||
*would be clipped and looked ugly so don't draw them*/
|
||||
lv_draw_rect_dsc_t draw_tmp_dsc = draw_rect_dsc;
|
||||
draw_tmp_dsc.border_opa = 0;
|
||||
draw_tmp_dsc.outline_opa = 0;
|
||||
draw_tmp_dsc.shadow_opa = 0;
|
||||
lv_area_t indic_draw_area = indic_area;
|
||||
if(gradient) {
|
||||
if(hor) {
|
||||
indic_draw_area.x1 = bar_coords.x1 + bg_left;
|
||||
indic_draw_area.x2 = bar_coords.x2 - bg_right;
|
||||
}
|
||||
else {
|
||||
indic_draw_area.y1 = bar_coords.y1 + bg_top;
|
||||
indic_draw_area.y2 = bar_coords.y2 - bg_bottom;
|
||||
}
|
||||
draw_tmp_dsc.radius = 0;
|
||||
}
|
||||
|
||||
lv_layer_t * layer_indic = lv_draw_layer_create(layer, LV_COLOR_FORMAT_ARGB8888, &indic_draw_area);
|
||||
|
||||
lv_draw_rect(layer_indic, &draw_tmp_dsc, &indic_draw_area);
|
||||
|
||||
lv_draw_mask_rect_dsc_t mask_dsc;
|
||||
lv_draw_mask_rect_dsc_init(&mask_dsc);
|
||||
if(radius_issue) {
|
||||
mask_dsc.area = bar_coords;
|
||||
mask_dsc.radius = bg_radius;
|
||||
lv_draw_mask_rect(layer_indic, &mask_dsc);
|
||||
|
||||
lv_draw_image_dsc_t layer_draw_dsc;
|
||||
lv_draw_image_dsc_init(&layer_draw_dsc);
|
||||
layer_draw_dsc.src = layer_indic;
|
||||
lv_draw_layer(layer, &layer_draw_dsc, &indic_area);
|
||||
}
|
||||
|
||||
if(gradient) {
|
||||
mask_dsc.area = indic_area;
|
||||
mask_dsc.radius = indic_radius;
|
||||
lv_draw_mask_rect(layer_indic, &mask_dsc);
|
||||
}
|
||||
|
||||
lv_draw_image_dsc_t layer_draw_dsc;
|
||||
lv_draw_image_dsc_init(&layer_draw_dsc);
|
||||
layer_draw_dsc.src = layer_indic;
|
||||
lv_draw_layer(layer, &layer_draw_dsc, &indic_draw_area);
|
||||
|
||||
/*Add the border, outline, and shadow only to the indicator area.
|
||||
*They might have disabled if there is a radius_issue*/
|
||||
draw_tmp_dsc = draw_rect_dsc;
|
||||
draw_tmp_dsc.bg_opa = 0;
|
||||
draw_tmp_dsc.bg_image_opa = 0;
|
||||
lv_draw_rect(layer, &draw_tmp_dsc, &indic_area);
|
||||
}
|
||||
else {
|
||||
lv_draw_rect(layer, &draw_rect_dsc, &indic_area);
|
||||
@ -504,7 +578,7 @@ static void lv_bar_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
|
||||
int32_t pad = LV_MIN4(bg_left, bg_right, bg_top, bg_bottom);
|
||||
if(pad < 0) {
|
||||
*s = LV_MAX(*s, -pad);
|
||||
*s = *s - pad;
|
||||
}
|
||||
}
|
||||
else if(code == LV_EVENT_PRESSED || code == LV_EVENT_RELEASED) {
|
||||
|
BIN
tests/ref_imgs/widgets/bar_corner_1.png
Normal file
BIN
tests/ref_imgs/widgets/bar_corner_1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 110 KiB |
BIN
tests/ref_imgs/widgets/bar_corner_2.png
Normal file
BIN
tests/ref_imgs/widgets/bar_corner_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 120 KiB |
BIN
tests/ref_imgs/widgets/bar_corner_3.png
Normal file
BIN
tests/ref_imgs/widgets/bar_corner_3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 117 KiB |
BIN
tests/ref_imgs/widgets/bar_corner_4.png
Normal file
BIN
tests/ref_imgs/widgets/bar_corner_4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 63 KiB |
BIN
tests/ref_imgs/widgets/bar_corner_5.png
Normal file
BIN
tests/ref_imgs/widgets/bar_corner_5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 64 KiB |
BIN
tests/ref_imgs/widgets/bar_corner_6.png
Normal file
BIN
tests/ref_imgs/widgets/bar_corner_6.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
@ -1,4 +1,4 @@
|
||||
#if LV_BUILD_TEST
|
||||
#if LV_BUILD_TEST || 1
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
@ -318,4 +318,85 @@ void test_bar_indicator_should_be_drawn_towards_the_min_range_side_after_setting
|
||||
TEST_ASSERT_LESS_THAN(original_pos, final_pos);
|
||||
}
|
||||
|
||||
static lv_obj_t * styled_bar_create(bool ver, int32_t start_value, int32_t end_value, lv_grad_dir_t grad_dir,
|
||||
int32_t bg_radius, int32_t indic_radius, int32_t bg_pad)
|
||||
{
|
||||
lv_obj_t * bar = lv_bar_create(lv_screen_active());
|
||||
if(ver) lv_obj_set_size(bar, 20, 100);
|
||||
else lv_obj_set_size(bar, 100, 20);
|
||||
lv_bar_set_range(bar, 0, 100);
|
||||
lv_bar_set_mode(bar, LV_BAR_MODE_RANGE);
|
||||
lv_bar_set_value(bar, end_value, LV_ANIM_OFF);
|
||||
lv_bar_set_start_value(bar, start_value, LV_ANIM_OFF);
|
||||
|
||||
lv_obj_set_style_bg_opa(bar, 255, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(bar, lv_color_hex3(0x0ff), LV_PART_MAIN);
|
||||
lv_obj_set_style_radius(bar, bg_radius, LV_PART_MAIN);
|
||||
lv_obj_set_style_pad_all(bar, bg_pad, LV_PART_MAIN);
|
||||
|
||||
lv_obj_set_style_bg_opa(bar, LV_OPA_70, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_bg_color(bar, lv_color_hex3(0xf0f), LV_PART_INDICATOR);
|
||||
lv_obj_set_style_bg_grad_color(bar, lv_color_hex3(0x8f8), LV_PART_INDICATOR);
|
||||
lv_obj_set_style_bg_grad_dir(bar, grad_dir, LV_PART_INDICATOR);
|
||||
|
||||
lv_obj_set_style_border_width(bar, 2, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_border_color(bar, lv_color_hex3(0x0f0), LV_PART_INDICATOR);
|
||||
lv_obj_set_style_border_opa(bar, LV_OPA_70, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_outline_width(bar, 2, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_outline_pad(bar, 4, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_outline_color(bar, lv_color_hex3(0xff0), LV_PART_INDICATOR);
|
||||
lv_obj_set_style_outline_opa(bar, LV_OPA_70, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_shadow_width(bar, 20, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_shadow_spread(bar, 5, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_shadow_color(bar, lv_color_hex3(0xf00), LV_PART_INDICATOR);
|
||||
lv_obj_set_style_shadow_opa(bar, LV_OPA_70, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_radius(bar, indic_radius, LV_PART_INDICATOR);
|
||||
|
||||
return bar;
|
||||
}
|
||||
|
||||
static void render_test_screen_create(bool ver, lv_grad_dir_t grad_dir, const char * ref_img_path)
|
||||
{
|
||||
lv_obj_t * active_screen = lv_screen_active();
|
||||
lv_obj_clean(active_screen);
|
||||
|
||||
lv_obj_set_flex_flow(active_screen, ver ? LV_FLEX_FLOW_ROW_WRAP : LV_FLEX_FLOW_COLUMN_WRAP);
|
||||
lv_obj_set_flex_align(active_screen, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_SPACE_EVENLY);
|
||||
lv_obj_set_style_pad_row(active_screen, 17, 0);
|
||||
lv_obj_set_style_pad_column(active_screen, 12, 0);
|
||||
lv_obj_set_style_pad_all(active_screen, 15, 0);
|
||||
|
||||
int32_t bar_values[6][2] = {{0, 5}, {0, 50}, {0, 95}, {5, 100}, {95, 100}, {20, 90}};
|
||||
int32_t bg_radius[2] = {0, 15};
|
||||
int32_t indic_radius[2] = {0, 15};
|
||||
int32_t bg_pad[3] = {-5, 0, 5};
|
||||
|
||||
uint32_t pad;
|
||||
for(pad = 0; pad < 3; pad++) {
|
||||
uint32_t indic_r;
|
||||
for(indic_r = 0; indic_r < 2; indic_r++) {
|
||||
uint32_t bg_r;
|
||||
for(bg_r = 0; bg_r < 2; bg_r++) {
|
||||
uint32_t v;
|
||||
for(v = 0; v < 6; v++) {
|
||||
styled_bar_create(ver, bar_values[v][0], bar_values[v][1], grad_dir, bg_radius[bg_r], indic_radius[indic_r],
|
||||
bg_pad[pad]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT(ref_img_path);
|
||||
}
|
||||
|
||||
void test_bar_render_corner(void)
|
||||
{
|
||||
render_test_screen_create(false, LV_GRAD_DIR_NONE, "widgets/bar_corner_1.png");
|
||||
render_test_screen_create(false, LV_GRAD_DIR_HOR, "widgets/bar_corner_2.png");
|
||||
render_test_screen_create(false, LV_GRAD_DIR_VER, "widgets/bar_corner_3.png");
|
||||
render_test_screen_create(true, LV_GRAD_DIR_NONE, "widgets/bar_corner_4.png");
|
||||
render_test_screen_create(true, LV_GRAD_DIR_HOR, "widgets/bar_corner_5.png");
|
||||
render_test_screen_create(true, LV_GRAD_DIR_VER, "widgets/bar_corner_6.png");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user