fix(bar): fix bar indicator length error (#8200)
@@ -398,6 +398,12 @@ static void draw_indic(lv_event_t * e)
|
||||
bool hor_need_reversed = hor && base_dir == LV_BASE_DIR_RTL;
|
||||
bool reversed = bar->val_reversed ^ hor_need_reversed;
|
||||
|
||||
/* An area with width 0 is {x1 = 0 x2 = -1} so subtracting 1 from `anim_cur_value_x` causes...
|
||||
* anim_start_value_x = 0 anim_cur_value_x = 0 to be {x1 = 0 x2 = -1 } which is width 0
|
||||
* anim_start_value_x = 0 anim_cur_value_x = 300 to be {x1 = 0 x2 = 299} which is width 300
|
||||
*/
|
||||
anim_cur_value_x -= 1;
|
||||
|
||||
if(reversed) {
|
||||
/*Swap axes*/
|
||||
int32_t * tmp;
|
||||
@@ -414,7 +420,7 @@ static void draw_indic(lv_event_t * e)
|
||||
*axis1 += anim_start_value_x;
|
||||
}
|
||||
else {
|
||||
*axis1 = *axis2 - anim_cur_value_x + 1;
|
||||
*axis1 = *axis2 - anim_cur_value_x;
|
||||
*axis2 -= anim_start_value_x;
|
||||
}
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 119 KiB |
|
Before Width: | Height: | Size: 117 KiB After Width: | Height: | Size: 117 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 124 KiB After Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 127 KiB |
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 128 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
@@ -73,8 +73,6 @@ void test_bar_should_update_indicator_right_coordinate_based_on_bar_value(void)
|
||||
int32_t indicator_part_width = lv_obj_get_content_width(g_bar);
|
||||
|
||||
int32_t expected_coord = (bar_value * indicator_part_width) / bar_max_value;
|
||||
/* NOTE: Add 1 to calculation because the coordinates start at 0 */
|
||||
expected_coord += 1;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(expected_coord, actual_coord);
|
||||
}
|
||||
@@ -129,7 +127,6 @@ void test_bar_rtl_should_update_indicator_left_coordinate_based_on_bar_value(voi
|
||||
int32_t indicator_width = (bar_value * indicator_part_width) / bar_max_value;
|
||||
|
||||
int32_t expected_coord = (bar_width - right_padding) - indicator_width;
|
||||
expected_coord -= 1;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(expected_coord, actual_coord);
|
||||
}
|
||||
@@ -201,9 +198,136 @@ void test_bar_normal(void)
|
||||
lv_bar_set_value(test_bar, 30, LV_ANIM_OFF);
|
||||
lv_obj_set_size(test_bar, h, w);
|
||||
lv_obj_align(test_bar, LV_ALIGN_TOP_LEFT, x, y);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/bar_1.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as test_bar_normal, but with min and max values set.
|
||||
*/
|
||||
void test_bar_normal_empty_and_full(void)
|
||||
{
|
||||
int32_t w = 300;
|
||||
int32_t h = 40;
|
||||
int32_t h_gap = 20;
|
||||
int32_t w_gap = 20;
|
||||
int32_t y = h_gap;
|
||||
int32_t x = w_gap;
|
||||
lv_color_t bg_color = lv_color_black();
|
||||
lv_color_t indic_color = lv_color_hex(0x0000FF);
|
||||
|
||||
lv_obj_t * screen = lv_obj_create(lv_screen_active());
|
||||
lv_obj_remove_style_all(screen);
|
||||
lv_obj_set_size(screen, 800, 480);
|
||||
lv_obj_center(screen);
|
||||
lv_obj_set_style_bg_color(screen, lv_color_white(), 0);
|
||||
lv_obj_set_style_bg_opa(screen, LV_OPA_100, 0);
|
||||
lv_obj_set_style_pad_all(screen, 0, 0);
|
||||
|
||||
lv_obj_t * test_bar = lv_bar_create(screen);
|
||||
lv_obj_set_style_radius(test_bar, 100, 0);
|
||||
lv_obj_set_style_radius(test_bar, 100, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(test_bar, LV_OPA_30, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, bg_color, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, indic_color, LV_PART_INDICATOR);
|
||||
lv_bar_set_range(test_bar, 0, 100);
|
||||
lv_bar_set_value(test_bar, 0, LV_ANIM_OFF);
|
||||
lv_obj_set_size(test_bar, w, h);
|
||||
lv_obj_align(test_bar, LV_ALIGN_TOP_LEFT, x, y);
|
||||
y += h + h_gap;
|
||||
|
||||
test_bar = lv_bar_create(screen);
|
||||
lv_obj_set_style_radius(test_bar, 100, 0);
|
||||
lv_obj_set_style_radius(test_bar, 100, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(test_bar, LV_OPA_30, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, bg_color, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, indic_color, LV_PART_INDICATOR);
|
||||
lv_bar_set_range(test_bar, 0, 100);
|
||||
lv_bar_set_value(test_bar, 0, LV_ANIM_OFF);
|
||||
lv_obj_set_size(test_bar, w, h);
|
||||
lv_obj_align(test_bar, LV_ALIGN_TOP_LEFT, x, y);
|
||||
lv_obj_set_style_base_dir(test_bar, LV_BASE_DIR_RTL, 0);
|
||||
y += h + h_gap;
|
||||
|
||||
x = 150;
|
||||
test_bar = lv_bar_create(screen);
|
||||
lv_obj_set_style_radius(test_bar, 100, 0);
|
||||
lv_obj_set_style_radius(test_bar, 100, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(test_bar, LV_OPA_30, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, bg_color, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, indic_color, LV_PART_INDICATOR);
|
||||
lv_bar_set_range(test_bar, 0, 100);
|
||||
lv_bar_set_value(test_bar, 0, LV_ANIM_OFF);
|
||||
lv_obj_set_size(test_bar, h, w);
|
||||
lv_obj_align(test_bar, LV_ALIGN_TOP_LEFT, x, y);
|
||||
x += h + w_gap;
|
||||
|
||||
test_bar = lv_bar_create(screen);
|
||||
lv_obj_set_style_radius(test_bar, 100, 0);
|
||||
lv_obj_set_style_radius(test_bar, 100, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(test_bar, LV_OPA_30, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, bg_color, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, indic_color, LV_PART_INDICATOR);
|
||||
lv_bar_set_range(test_bar, 100, 0);
|
||||
lv_bar_set_value(test_bar, 0, LV_ANIM_OFF);
|
||||
lv_obj_set_size(test_bar, h, w);
|
||||
lv_obj_align(test_bar, LV_ALIGN_TOP_LEFT, x, y);
|
||||
|
||||
y = h_gap;
|
||||
x = w_gap + 400;
|
||||
|
||||
test_bar = lv_bar_create(screen);
|
||||
lv_obj_set_style_radius(test_bar, 100, 0);
|
||||
lv_obj_set_style_radius(test_bar, 100, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(test_bar, LV_OPA_30, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, bg_color, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, indic_color, LV_PART_INDICATOR);
|
||||
lv_bar_set_range(test_bar, 0, 100);
|
||||
lv_bar_set_value(test_bar, 100, LV_ANIM_OFF);
|
||||
lv_obj_set_size(test_bar, w, h);
|
||||
lv_obj_align(test_bar, LV_ALIGN_TOP_LEFT, x, y);
|
||||
y += h + h_gap;
|
||||
|
||||
test_bar = lv_bar_create(screen);
|
||||
lv_obj_set_style_radius(test_bar, 100, 0);
|
||||
lv_obj_set_style_radius(test_bar, 100, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(test_bar, LV_OPA_30, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, bg_color, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, indic_color, LV_PART_INDICATOR);
|
||||
lv_bar_set_range(test_bar, 0, 100);
|
||||
lv_bar_set_value(test_bar, 100, LV_ANIM_OFF);
|
||||
lv_obj_set_size(test_bar, w, h);
|
||||
lv_obj_align(test_bar, LV_ALIGN_TOP_LEFT, x, y);
|
||||
lv_obj_set_style_base_dir(test_bar, LV_BASE_DIR_RTL, 0);
|
||||
y += h + h_gap;
|
||||
|
||||
x += 150;
|
||||
test_bar = lv_bar_create(screen);
|
||||
lv_obj_set_style_radius(test_bar, 100, 0);
|
||||
lv_obj_set_style_radius(test_bar, 100, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(test_bar, LV_OPA_30, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, bg_color, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, indic_color, LV_PART_INDICATOR);
|
||||
lv_bar_set_range(test_bar, 0, 100);
|
||||
lv_bar_set_value(test_bar, 100, LV_ANIM_OFF);
|
||||
lv_obj_set_size(test_bar, h, w);
|
||||
lv_obj_align(test_bar, LV_ALIGN_TOP_LEFT, x, y);
|
||||
x += h + w_gap;
|
||||
|
||||
test_bar = lv_bar_create(screen);
|
||||
lv_obj_set_style_radius(test_bar, 100, 0);
|
||||
lv_obj_set_style_radius(test_bar, 100, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(test_bar, LV_OPA_30, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, bg_color, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_color(test_bar, indic_color, LV_PART_INDICATOR);
|
||||
lv_bar_set_range(test_bar, 100, 0);
|
||||
lv_bar_set_value(test_bar, 100, LV_ANIM_OFF);
|
||||
lv_obj_set_size(test_bar, h, w);
|
||||
lv_obj_align(test_bar, LV_ALIGN_TOP_LEFT, x, y);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/bar_3.png");
|
||||
}
|
||||
|
||||
void test_bar_indicator_area_should_get_smaller_when_padding_is_increased(void)
|
||||
{
|
||||
lv_bar_t * bar_ptr = (lv_bar_t *) g_bar;
|
||||
|
||||