From bccbde0cef4ed0a621663f9745cac6851737baac Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 12 Oct 2023 21:50:43 +0200 Subject: [PATCH] refactor(obj): remove LV_PART_TICKS and use LV_PART_ITEMS in lv_scale --- demos/widgets/lv_demo_widgets.c | 2 +- docs/overview/obj.rst | 1 - docs/overview/style.rst | 1 - docs/widgets/chart.rst | 4 +--- docs/widgets/scale.rst | 4 ++-- examples/widgets/scale/lv_example_scale_2.c | 2 +- examples/widgets/scale/lv_example_scale_4.c | 2 +- examples/widgets/scale/lv_example_scale_5.c | 2 +- src/core/lv_obj.h | 3 +-- src/themes/basic/lv_theme_basic.c | 1 - src/themes/default/lv_theme_default.c | 11 ++-------- src/themes/mono/lv_theme_mono.c | 1 - src/widgets/scale/lv_scale.c | 24 ++++++++++----------- 13 files changed, 22 insertions(+), 36 deletions(-) diff --git a/demos/widgets/lv_demo_widgets.c b/demos/widgets/lv_demo_widgets.c index 2417c0232..07e0e3079 100644 --- a/demos/widgets/lv_demo_widgets.c +++ b/demos/widgets/lv_demo_widgets.c @@ -766,7 +766,7 @@ static void analytics_create(lv_obj_t * parent) lv_scale_section_set_range(section, 0, 20); lv_scale_section_set_style(section, LV_PART_MAIN, &scale3_section1_main_style); lv_scale_section_set_style(section, LV_PART_INDICATOR, &scale3_section1_indicator_style); - lv_scale_section_set_style(section, LV_PART_TICKS, &scale3_section1_tick_style); + lv_scale_section_set_style(section, LV_PART_ITEMS, &scale3_section1_tick_style); LV_IMG_DECLARE(img_demo_widgets_needle); lv_obj_t * needle = lv_image_create(scale3); diff --git a/docs/overview/obj.rst b/docs/overview/obj.rst index 0ed72b6ea..cfd60c398 100644 --- a/docs/overview/obj.rst +++ b/docs/overview/obj.rst @@ -260,7 +260,6 @@ The following predefined parts exist in LVGL: - :cpp:enumerator:`LV_PART_KNOB`: Like a handle to grab to adjust the value - :cpp:enumerator:`LV_PART_SELECTED`: Indicate the currently selected option or section - :cpp:enumerator:`LV_PART_ITEMS`: Used if the widget has multiple similar elements (e.g. table cells) -- :cpp:enumerator:`LV_PART_TICKS`: Ticks on scales e.g. for a chart or meter - :cpp:enumerator:`LV_PART_CURSOR`: Mark a specific place e.g. text area's or chart's cursor - :cpp:enumerator:`LV_PART_CUSTOM_FIRST`: Custom parts can be added from here. diff --git a/docs/overview/style.rst b/docs/overview/style.rst index f37be6d9b..89b61d229 100644 --- a/docs/overview/style.rst +++ b/docs/overview/style.rst @@ -183,7 +183,6 @@ The following predefined parts exist in LVGL: - :cpp:enumerator:`LV_PART_KNOB`: Like a handle to grab to adjust a value - :cpp:enumerator:`LV_PART_SELECTED`: Indicate the currently selected option or section - :cpp:enumerator:`LV_PART_ITEMS`: Used if the widget has multiple similar elements (e.g. table cells) -- :cpp:enumerator:`LV_PART_TICKS`: Ticks on scales e.g. for a chart or meter - :cpp:enumerator:`LV_PART_CURSOR`: Mark a specific place e.g. text area's or chart's cursor - :cpp:enumerator:`LV_PART_CUSTOM_FIRST`: Custom part identifiers can be added starting from here. diff --git a/docs/widgets/chart.rst b/docs/widgets/chart.rst index 9027c407e..454d8747f 100644 --- a/docs/widgets/chart.rst +++ b/docs/widgets/chart.rst @@ -35,8 +35,6 @@ Parts and Styles - :cpp:enumerator:`LV_PART_CURSOR` *Line* properties are used to style the cursors. ``width``, ``height``, ``bg_color`` and ``radius`` are used to set the appearance of points. -- :cpp:enumerator:`LV_PART_TICKS` *Line* and *Text* style properties are used to - style the ticks Usage ***** @@ -263,7 +261,7 @@ Events - :cpp:enumerator:`LV_CHART_DRAW_PART_TICK_LABEL` Used on tick lines and labels. - - ``part``: :cpp:enumerator:`LV_PART_TICKS` + - ``part``: :cpp:enumerator:`LV_PART_ITEMS` - ``id``: axis - ``value``: value of the tick - ``text``: ``value`` converted to decimal or ``NULL`` for minor diff --git a/docs/widgets/scale.rst b/docs/widgets/scale.rst index 8f6234d01..69d8470be 100644 --- a/docs/widgets/scale.rst +++ b/docs/widgets/scale.rst @@ -12,7 +12,7 @@ Parts and Styles The scale widget is divided in the following three parts: - :cpp:enumerator: `LV_PART_MAIN` Main line. See blue line in the example image. -- :cpp:enumerator: `LV_PART_TICKS` Minor ticks. See red minor ticks in the example image. +- :cpp:enumerator: `LV_PART_ITEMS` Minor ticks. See red minor ticks in the example image. - :cpp:enumerator: `LV_PART_INDICATOR` Major ticks and its labels (if enabled). See pink labels and green major ticks in the example image. ![](/misc/scale.png "Scale example") @@ -37,7 +37,7 @@ Sections A section is the space between a minor and a major range. They can be created with :cpp:expr: `lv_scale_add_section(scale)` and it handles back an :cpp:expr: `lv_scale_section_t` pointer. -The range of the section is configured with :cpp:expr: `lv_scale_section_set_range(section, minor_range, major_range)`. The style of each of the three parts of the scale section can be set with :cpp:expr: `lv_scale_section_set_style(section, PART, style_pointer)`, where `PART` can be :cpp:enumarator: `LV_PART_MAIN`, :cpp:enumarator: `LV_PART_TICKS` or :cpp:enumarator: `LV_PART_INDICATOR`, :cpp:expr: `style_pointer` should point to a global or static :cpp:expr: `lv_style_t` variable. +The range of the section is configured with :cpp:expr: `lv_scale_section_set_range(section, minor_range, major_range)`. The style of each of the three parts of the scale section can be set with :cpp:expr: `lv_scale_section_set_style(section, PART, style_pointer)`, where `PART` can be :cpp:enumarator: `LV_PART_MAIN`, :cpp:enumarator: `LV_PART_ITEMS` or :cpp:enumarator: `LV_PART_INDICATOR`, :cpp:expr: `style_pointer` should point to a global or static :cpp:expr: `lv_style_t` variable. For labels the following properties can be configured: :cpp:expr: `lv_style_set_text_font`, :cpp:expr: `lv_style_set_text_color`, :cpp:expr: `lv_style_set_text_letter_space`, :cpp:expr: `lv_style_set_text_opa`. diff --git a/examples/widgets/scale/lv_example_scale_2.c b/examples/widgets/scale/lv_example_scale_2.c index 4ffc6b116..004f97825 100644 --- a/examples/widgets/scale/lv_example_scale_2.c +++ b/examples/widgets/scale/lv_example_scale_2.c @@ -40,7 +40,7 @@ void lv_example_scale_2(void) lv_style_set_line_color(&minor_ticks_style, lv_palette_lighten(LV_PALETTE_BLUE, 2)); lv_style_set_width(&minor_ticks_style, 5U); /*Tick length*/ lv_style_set_line_width(&minor_ticks_style, 2U); /*Tick width*/ - lv_obj_add_style(scale, &minor_ticks_style, LV_PART_TICKS); + lv_obj_add_style(scale, &minor_ticks_style, LV_PART_ITEMS); static lv_style_t main_line_style; lv_style_init(&main_line_style); diff --git a/examples/widgets/scale/lv_example_scale_4.c b/examples/widgets/scale/lv_example_scale_4.c index 0364d7bdb..3aed5431e 100644 --- a/examples/widgets/scale/lv_example_scale_4.c +++ b/examples/widgets/scale/lv_example_scale_4.c @@ -40,7 +40,7 @@ void lv_example_scale_4(void) lv_style_set_line_color(&minor_ticks_style, lv_palette_lighten(LV_PALETTE_BLUE, 2)); lv_style_set_width(&minor_ticks_style, 5U); /*Tick length*/ lv_style_set_line_width(&minor_ticks_style, 2U); /*Tick width*/ - lv_obj_add_style(scale, &minor_ticks_style, LV_PART_TICKS); + lv_obj_add_style(scale, &minor_ticks_style, LV_PART_ITEMS); static lv_style_t main_line_style; lv_style_init(&main_line_style); diff --git a/examples/widgets/scale/lv_example_scale_5.c b/examples/widgets/scale/lv_example_scale_5.c index d07a7ff93..1ff37b246 100644 --- a/examples/widgets/scale/lv_example_scale_5.c +++ b/examples/widgets/scale/lv_example_scale_5.c @@ -36,7 +36,7 @@ void lv_example_scale_5(void) lv_style_set_line_color(&minor_ticks_style, lv_color_hex(0xff0000)); lv_style_set_width(&minor_ticks_style, 5U); // Tick length lv_style_set_line_width(&minor_ticks_style, 2U); // Tick width - lv_obj_add_style(scale, &minor_ticks_style, LV_PART_TICKS); + lv_obj_add_style(scale, &minor_ticks_style, LV_PART_ITEMS); static lv_style_t main_line_style; lv_style_init(&main_line_style); diff --git a/src/core/lv_obj.h b/src/core/lv_obj.h index d55178c8c..63b43f5b9 100644 --- a/src/core/lv_obj.h +++ b/src/core/lv_obj.h @@ -76,8 +76,7 @@ enum _lv_part_t { LV_PART_KNOB = 0x030000, /**< Like handle to grab to adjust the value*/ LV_PART_SELECTED = 0x040000, /**< Indicate the currently selected option or section*/ LV_PART_ITEMS = 0x050000, /**< Used if the widget has multiple similar elements (e.g. table cells)*/ - LV_PART_TICKS = 0x060000, /**< Ticks on scale e.g. for a chart or meter*/ - LV_PART_CURSOR = 0x070000, /**< Mark a specific place e.g. for text area's cursor or on a chart*/ + LV_PART_CURSOR = 0x060000, /**< Mark a specific place e.g. for text area's cursor or on a chart*/ LV_PART_CUSTOM_FIRST = 0x080000, /**< Extension point for custom widgets*/ diff --git a/src/themes/basic/lv_theme_basic.c b/src/themes/basic/lv_theme_basic.c index f183c11eb..a73c22a09 100644 --- a/src/themes/basic/lv_theme_basic.c +++ b/src/themes/basic/lv_theme_basic.c @@ -294,7 +294,6 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, &theme->styles.white, 0); lv_obj_add_style(obj, &theme->styles.scrollbar, LV_PART_SCROLLBAR); lv_obj_add_style(obj, &theme->styles.light, LV_PART_ITEMS); - lv_obj_add_style(obj, &theme->styles.dark, LV_PART_TICKS); lv_obj_add_style(obj, &theme->styles.dark, LV_PART_CURSOR); } #endif diff --git a/src/themes/default/lv_theme_default.c b/src/themes/default/lv_theme_default.c index b6e619736..835871a74 100644 --- a/src/themes/default/lv_theme_default.c +++ b/src/themes/default/lv_theme_default.c @@ -89,7 +89,7 @@ typedef struct { #endif #if LV_USE_CHART - lv_style_t chart_series, chart_indic, chart_ticks, chart_bg; + lv_style_t chart_series, chart_indic, chart_bg; #endif #if LV_USE_DROPDOWN @@ -466,12 +466,6 @@ static void style_init(struct _my_theme_t * theme) lv_style_set_size(&theme->styles.chart_indic, chart_size, chart_size); lv_style_set_bg_color(&theme->styles.chart_indic, theme->base.color_primary); lv_style_set_bg_opa(&theme->styles.chart_indic, LV_OPA_COVER); - - style_init_reset(&theme->styles.chart_ticks); - lv_style_set_line_width(&theme->styles.chart_ticks, _LV_DPX_CALC(theme->disp_dpi, 1)); - lv_style_set_line_color(&theme->styles.chart_ticks, theme->color_text); - lv_style_set_pad_all(&theme->styles.chart_ticks, _LV_DPX_CALC(theme->disp_dpi, 2)); - lv_style_set_text_color(&theme->styles.chart_ticks, lv_palette_main(LV_PALETTE_GREY)); #endif #if LV_USE_MENU @@ -978,7 +972,6 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, &theme->styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); lv_obj_add_style(obj, &theme->styles.chart_series, LV_PART_ITEMS); lv_obj_add_style(obj, &theme->styles.chart_indic, LV_PART_INDICATOR); - lv_obj_add_style(obj, &theme->styles.chart_ticks, LV_PART_TICKS); lv_obj_add_style(obj, &theme->styles.chart_series, LV_PART_CURSOR); } #endif @@ -1209,7 +1202,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) else if(lv_obj_check_type(obj, &lv_scale_class)) { lv_obj_add_style(obj, &theme->styles.scale, LV_PART_MAIN); lv_obj_add_style(obj, &theme->styles.scale, LV_PART_INDICATOR); - lv_obj_add_style(obj, &theme->styles.scale, LV_PART_TICKS); + lv_obj_add_style(obj, &theme->styles.scale, LV_PART_ITEMS); } #endif } diff --git a/src/themes/mono/lv_theme_mono.c b/src/themes/mono/lv_theme_mono.c index 7528de51b..0e0f803e3 100644 --- a/src/themes/mono/lv_theme_mono.c +++ b/src/themes/mono/lv_theme_mono.c @@ -379,7 +379,6 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, &theme->styles.scrollbar, LV_PART_SCROLLBAR); lv_obj_add_style(obj, &theme->styles.chart_indic, LV_PART_INDICATOR); lv_obj_add_style(obj, &theme->styles.card, LV_PART_ITEMS); - lv_obj_add_style(obj, &theme->styles.card, LV_PART_TICKS); lv_obj_add_style(obj, &theme->styles.card, LV_PART_CURSOR); lv_obj_add_style(obj, &theme->styles.focus, LV_STATE_FOCUS_KEY); } diff --git a/src/widgets/scale/lv_scale.c b/src/widgets/scale/lv_scale.c index d853f0d48..d02ab77af 100644 --- a/src/widgets/scale/lv_scale.c +++ b/src/widgets/scale/lv_scale.c @@ -253,7 +253,7 @@ void lv_scale_section_set_style(lv_scale_section_t * section, uint32_t part, lv_ case LV_PART_INDICATOR: section->indicator_style = section_part_style; break; - case LV_PART_TICKS: + case LV_PART_ITEMS: section->items_style = section_part_style; break; default: @@ -375,7 +375,7 @@ static void scale_draw_indicator(lv_obj_t * obj, lv_event_t * event) /* Configure line draw descriptor for the minor tick drawing */ lv_draw_line_dsc_t minor_tick_dsc; lv_draw_line_dsc_init(&minor_tick_dsc); - lv_obj_init_draw_line_dsc(obj, LV_PART_TICKS, &minor_tick_dsc); + lv_obj_init_draw_line_dsc(obj, LV_PART_ITEMS, &minor_tick_dsc); /* Main line style */ lv_draw_line_dsc_t main_line_dsc; @@ -405,14 +405,14 @@ static void scale_draw_indicator(lv_obj_t * obj, lv_event_t * event) scale_set_line_properties(obj, &major_tick_dsc, section->indicator_style, LV_PART_INDICATOR); } else { - scale_set_line_properties(obj, &minor_tick_dsc, section->items_style, LV_PART_TICKS); + scale_set_line_properties(obj, &minor_tick_dsc, section->items_style, LV_PART_ITEMS); } } else { /* Tick is not in section, get the proper styles */ lv_obj_init_draw_label_dsc(obj, LV_PART_INDICATOR, &label_dsc); lv_obj_init_draw_line_dsc(obj, LV_PART_INDICATOR, &major_tick_dsc); - lv_obj_init_draw_line_dsc(obj, LV_PART_TICKS, &minor_tick_dsc); + lv_obj_init_draw_line_dsc(obj, LV_PART_ITEMS, &minor_tick_dsc); } } @@ -493,14 +493,14 @@ static void scale_draw_indicator(lv_obj_t * obj, lv_event_t * event) scale_set_line_properties(obj, &major_tick_dsc, section->indicator_style, LV_PART_INDICATOR); } else { - scale_set_line_properties(obj, &minor_tick_dsc, section->items_style, LV_PART_TICKS); + scale_set_line_properties(obj, &minor_tick_dsc, section->items_style, LV_PART_ITEMS); } } else { /* Tick is not in section, get the proper styles */ lv_obj_init_draw_label_dsc(obj, LV_PART_INDICATOR, &label_dsc); lv_obj_init_draw_line_dsc(obj, LV_PART_INDICATOR, &major_tick_dsc); - lv_obj_init_draw_line_dsc(obj, LV_PART_TICKS, &minor_tick_dsc); + lv_obj_init_draw_line_dsc(obj, LV_PART_ITEMS, &minor_tick_dsc); } } @@ -792,10 +792,10 @@ static void scale_get_tick_points(lv_obj_t * obj, const uint32_t tick_idx, bool const lv_coord_t pad_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN) + border_width; const lv_coord_t pad_right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN) + border_width; const lv_coord_t pad_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN) + border_width; - const lv_coord_t tick_pad_right = lv_obj_get_style_pad_right(obj, LV_PART_TICKS); - const lv_coord_t tick_pad_left = lv_obj_get_style_pad_left(obj, LV_PART_TICKS); - const lv_coord_t tick_pad_top = lv_obj_get_style_pad_top(obj, LV_PART_TICKS); - const lv_coord_t tick_pad_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_TICKS); + const lv_coord_t tick_pad_right = lv_obj_get_style_pad_right(obj, LV_PART_ITEMS); + const lv_coord_t tick_pad_left = lv_obj_get_style_pad_left(obj, LV_PART_ITEMS); + const lv_coord_t tick_pad_top = lv_obj_get_style_pad_top(obj, LV_PART_ITEMS); + const lv_coord_t tick_pad_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_ITEMS); lv_coord_t x_ofs = 0U; lv_coord_t y_ofs = 0U; @@ -974,7 +974,7 @@ static void scale_get_label_coords(lv_obj_t * obj, lv_draw_label_dsc_t * label_d * @param obj pointer to a scale object * @param line_dsc pointer to line descriptor * @param items_section_style pointer to indicator section style - * @param part line part, example: LV_PART_INDICATOR, LV_PART_TICKS, LV_PART_MAIN + * @param part line part, example: LV_PART_INDICATOR, LV_PART_ITEMS, LV_PART_MAIN */ static void scale_set_line_properties(lv_obj_t * obj, lv_draw_line_dsc_t * line_dsc, lv_style_t * section_style, uint32_t part) @@ -1259,7 +1259,7 @@ static void scale_store_section_line_tick_width_compensation(lv_obj_t * obj, con scale_set_line_properties(obj, major_tick_dsc, section->indicator_style, LV_PART_INDICATOR); } else { - scale_set_line_properties(obj, minor_tick_dsc, section->items_style, LV_PART_TICKS); + scale_set_line_properties(obj, minor_tick_dsc, section->items_style, LV_PART_ITEMS); } }