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

fix(scale): fix tick count and example issues

This commit is contained in:
Gabor Kiss-Vamosi 2023-10-19 15:02:28 +02:00
parent aa0e82ca43
commit 195c3f72d2
8 changed files with 20 additions and 19 deletions

View File

@ -544,7 +544,7 @@ static lv_obj_t * create_chart_with_scales(lv_obj_t * parent, const char * title
lv_obj_t * scale_ver = lv_scale_create(parent); lv_obj_t * scale_ver = lv_scale_create(parent);
lv_scale_set_mode(scale_ver, LV_SCALE_MODE_VERTICAL_LEFT); lv_scale_set_mode(scale_ver, LV_SCALE_MODE_VERTICAL_LEFT);
lv_obj_set_grid_cell(scale_ver, LV_GRID_ALIGN_END, 0, 1, LV_GRID_ALIGN_STRETCH, 1, 1); lv_obj_set_grid_cell(scale_ver, LV_GRID_ALIGN_END, 0, 1, LV_GRID_ALIGN_STRETCH, 1, 1);
lv_scale_set_total_tick_count(scale_ver, 10); lv_scale_set_total_tick_count(scale_ver, 11);
lv_scale_set_major_tick_every(scale_ver, 2); lv_scale_set_major_tick_every(scale_ver, 2);
lv_scale_set_range(scale_ver, 0, 100); lv_scale_set_range(scale_ver, 0, 100);
@ -568,7 +568,7 @@ static lv_obj_t * create_chart_with_scales(lv_obj_t * parent, const char * title
lv_obj_t * scale_hor = lv_scale_create(wrapper); lv_obj_t * scale_hor = lv_scale_create(wrapper);
lv_scale_set_mode(scale_hor, LV_SCALE_MODE_HORIZONTAL_BOTTOM); lv_scale_set_mode(scale_hor, LV_SCALE_MODE_HORIZONTAL_BOTTOM);
lv_obj_set_grid_cell(scale_hor, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 1, 1); lv_obj_set_grid_cell(scale_hor, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 1, 1);
lv_scale_set_total_tick_count(scale_hor, 11); lv_scale_set_total_tick_count(scale_hor, 12);
lv_scale_set_major_tick_every(scale_hor, 1); lv_scale_set_major_tick_every(scale_hor, 1);
lv_scale_set_text_src(scale_hor, hor_text); lv_scale_set_text_src(scale_hor, hor_text);
lv_obj_set_width(scale_hor, lv_pct(200)); lv_obj_set_width(scale_hor, lv_pct(200));
@ -699,7 +699,6 @@ static void analytics_create(lv_obj_t * parent)
/*Scale 2*/ /*Scale 2*/
lv_scale_set_round_props(scale2, 330, 0); lv_scale_set_round_props(scale2, 330, 0);
lv_scale_set_total_tick_count(scale2, 10);
lv_scale_set_major_tick_length(scale2, 30); lv_scale_set_major_tick_length(scale2, 30);
lv_scale_set_major_tick_every(scale2, 1); lv_scale_set_major_tick_every(scale2, 1);
arc = lv_arc_create(scale2); arc = lv_arc_create(scale2);
@ -739,7 +738,7 @@ static void analytics_create(lv_obj_t * parent)
/*Scale 3*/ /*Scale 3*/
lv_scale_set_range(scale3, 10, 60); lv_scale_set_range(scale3, 10, 60);
lv_scale_set_total_tick_count(scale3, 20); lv_scale_set_total_tick_count(scale3, 21);
lv_scale_set_major_tick_every(scale3, 4); lv_scale_set_major_tick_every(scale3, 4);
lv_scale_set_minor_tick_length(scale3, 10); lv_scale_set_minor_tick_length(scale3, 10);
lv_scale_set_major_tick_length(scale3, 20); lv_scale_set_major_tick_length(scale3, 20);

View File

@ -13,7 +13,7 @@ void lv_example_scale_1(void)
lv_scale_set_label_show(scale, true); lv_scale_set_label_show(scale, true);
lv_scale_set_total_tick_count(scale, 30); lv_scale_set_total_tick_count(scale, 31);
lv_scale_set_major_tick_every(scale, 5); lv_scale_set_major_tick_every(scale, 5);
lv_scale_set_major_tick_length(scale, 10); lv_scale_set_major_tick_length(scale, 10);

View File

@ -12,7 +12,7 @@ void lv_example_scale_2(void)
lv_scale_set_mode(scale, LV_SCALE_MODE_VERTICAL_RIGHT); lv_scale_set_mode(scale, LV_SCALE_MODE_VERTICAL_RIGHT);
lv_obj_center(scale); lv_obj_center(scale);
lv_scale_set_total_tick_count(scale, 20); lv_scale_set_total_tick_count(scale, 21);
lv_scale_set_major_tick_every(scale, 5); lv_scale_set_major_tick_every(scale, 5);
lv_scale_set_major_tick_length(scale, 10); lv_scale_set_major_tick_length(scale, 10);
@ -74,13 +74,15 @@ void lv_example_scale_2(void)
/* Configure section styles */ /* Configure section styles */
lv_scale_section_t * section = lv_scale_add_section(scale); lv_scale_section_t * section = lv_scale_add_section(scale);
lv_scale_section_set_range(section, 80, 100); lv_scale_section_set_range(section, 75, 100);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &section_label_style); lv_scale_section_set_style(section, LV_PART_INDICATOR, &section_label_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &section_minor_tick_style); lv_scale_section_set_style(section, LV_PART_ITEMS, &section_minor_tick_style);
lv_scale_section_set_style(section, LV_PART_MAIN, &section_main_line_style); lv_scale_section_set_style(section, LV_PART_MAIN, &section_main_line_style);
lv_obj_set_style_bg_color(scale, lv_palette_main(LV_PALETTE_BLUE_GREY), 0);
lv_obj_set_style_bg_opa(scale, 40, 0); lv_obj_set_style_bg_opa(scale, LV_OPA_50, 0);
lv_obj_set_style_pad_left(scale, 8, 0);
lv_obj_set_style_radius(scale, 8, 0);
lv_obj_set_style_pad_ver(scale, 20, 0); lv_obj_set_style_pad_ver(scale, 20, 0);
} }

View File

@ -16,7 +16,7 @@ void lv_example_scale_3(void)
lv_scale_set_label_show(scale, true); lv_scale_set_label_show(scale, true);
lv_scale_set_total_tick_count(scale, 30); lv_scale_set_total_tick_count(scale, 11);
lv_scale_set_major_tick_every(scale, 5); lv_scale_set_major_tick_every(scale, 5);
lv_scale_set_major_tick_length(scale, 10); lv_scale_set_major_tick_length(scale, 10);

View File

@ -12,7 +12,7 @@ void lv_example_scale_4(void)
lv_scale_set_mode(scale, LV_SCALE_MODE_ROUND_OUTER); lv_scale_set_mode(scale, LV_SCALE_MODE_ROUND_OUTER);
lv_obj_center(scale); lv_obj_center(scale);
lv_scale_set_total_tick_count(scale, 20); lv_scale_set_total_tick_count(scale, 21);
lv_scale_set_major_tick_every(scale, 5); lv_scale_set_major_tick_every(scale, 5);
lv_scale_set_major_tick_length(scale, 10); lv_scale_set_major_tick_length(scale, 10);
@ -74,7 +74,7 @@ void lv_example_scale_4(void)
/* Configure section styles */ /* Configure section styles */
lv_scale_section_t * section = lv_scale_add_section(scale); lv_scale_section_t * section = lv_scale_add_section(scale);
lv_scale_section_set_range(section, 80, 100); lv_scale_section_set_range(section, 75, 100);
lv_scale_section_set_style(section, LV_PART_INDICATOR, &section_label_style); lv_scale_section_set_style(section, LV_PART_INDICATOR, &section_label_style);
lv_scale_section_set_style(section, LV_PART_ITEMS, &section_minor_tick_style); lv_scale_section_set_style(section, LV_PART_ITEMS, &section_minor_tick_style);
lv_scale_section_set_style(section, LV_PART_MAIN, &section_main_line_style); lv_scale_section_set_style(section, LV_PART_MAIN, &section_main_line_style);

View File

@ -647,9 +647,9 @@ static void style_init(struct _my_theme_t * theme)
#if LV_USE_SCALE #if LV_USE_SCALE
style_init_reset(&theme->styles.scale); style_init_reset(&theme->styles.scale);
lv_style_set_line_color(&theme->styles.scale, theme->color_grey); lv_style_set_line_color(&theme->styles.scale, theme->color_text);
lv_style_set_line_width(&theme->styles.scale, LV_DPX(2)); lv_style_set_line_width(&theme->styles.scale, LV_DPX(2));
lv_style_set_arc_color(&theme->styles.scale, theme->color_grey); lv_style_set_arc_color(&theme->styles.scale, theme->color_text);
lv_style_set_arc_width(&theme->styles.scale, LV_DPX(2)); lv_style_set_arc_width(&theme->styles.scale, LV_DPX(2));
#endif #endif
} }

View File

@ -394,7 +394,7 @@ static void scale_draw_indicator(lv_obj_t * obj, lv_event_t * event)
if(tick_idx % scale->major_tick_every == 0) is_major_tick = true; if(tick_idx % scale->major_tick_every == 0) is_major_tick = true;
if(is_major_tick) major_tick_idx++; if(is_major_tick) major_tick_idx++;
const int32_t tick_value = lv_map(tick_idx, 0U, total_tick_count, scale->range_min, scale->range_max); const int32_t tick_value = lv_map(tick_idx, 0U, total_tick_count - 1, scale->range_min, scale->range_max);
/* Overwrite label and tick properties if tick value is within section range */ /* Overwrite label and tick properties if tick value is within section range */
lv_scale_section_t * section; lv_scale_section_t * section;
@ -483,7 +483,7 @@ static void scale_draw_indicator(lv_obj_t * obj, lv_event_t * event)
if(tick_idx % scale->major_tick_every == 0) is_major_tick = true; if(tick_idx % scale->major_tick_every == 0) is_major_tick = true;
if(is_major_tick) major_tick_idx++; if(is_major_tick) major_tick_idx++;
const int32_t tick_value = lv_map(tick_idx, 0U, scale->total_tick_count, scale->range_min, scale->range_max); const int32_t tick_value = lv_map(tick_idx, 0U, scale->total_tick_count - 1, scale->range_min, scale->range_max);
/* Overwrite label and tick properties if tick value is within section range */ /* Overwrite label and tick properties if tick value is within section range */
lv_scale_section_t * section; lv_scale_section_t * section;
@ -887,7 +887,7 @@ static void scale_get_tick_points(lv_obj_t * obj, const uint32_t tick_idx, bool
center_point.x = scale_area.x1 + radius_edge; center_point.x = scale_area.x1 + radius_edge;
center_point.y = scale_area.y1 + radius_edge; center_point.y = scale_area.y1 + radius_edge;
int32_t angle_upscale = ((tick_idx * scale->angle_range) * 10U) / (scale->total_tick_count); int32_t angle_upscale = ((tick_idx * scale->angle_range) * 10U) / (scale->total_tick_count - 1);
angle_upscale += scale->rotation * 10U; angle_upscale += scale->rotation * 10U;
/* Draw a little bit longer lines to be sure the mask will clip them correctly /* Draw a little bit longer lines to be sure the mask will clip them correctly
@ -1145,7 +1145,7 @@ static void scale_find_section_tick_idx(lv_obj_t * obj)
bool is_major_tick = false; bool is_major_tick = false;
if(tick_idx % scale->major_tick_every == 0) is_major_tick = true; if(tick_idx % scale->major_tick_every == 0) is_major_tick = true;
const int32_t tick_value = lv_map(tick_idx, 0U, total_tick_count, min_out, max_out); const int32_t tick_value = lv_map(tick_idx, 0U, total_tick_count - 1, min_out, max_out);
lv_scale_section_t * section; lv_scale_section_t * section;
_LV_LL_READ_BACK(&scale->section_ll, section) { _LV_LL_READ_BACK(&scale->section_ll, section) {

View File

@ -24,7 +24,7 @@ extern "C" {
*********************/ *********************/
/**Default value of total minor ticks. */ /**Default value of total minor ticks. */
#define LV_SCALE_TOTAL_TICK_COUNT_DEFAULT (10U) #define LV_SCALE_TOTAL_TICK_COUNT_DEFAULT (11U)
LV_EXPORT_CONST_INT(LV_SCALE_TOTAL_TICK_COUNT_DEFAULT); LV_EXPORT_CONST_INT(LV_SCALE_TOTAL_TICK_COUNT_DEFAULT);
/**Default value of major tick every nth ticks. */ /**Default value of major tick every nth ticks. */