refactor(obj): remove LV_PART_TICKS and use LV_PART_ITEMS in lv_scale

This commit is contained in:
Gabor Kiss-Vamosi
2023-10-12 21:50:43 +02:00
parent d3aee1d7f6
commit bccbde0cef
13 changed files with 22 additions and 36 deletions

View File

@@ -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);

View File

@@ -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.

View File

@@ -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.

View File

@@ -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

View File

@@ -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`.

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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*/

View File

@@ -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

View File

@@ -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
}

View File

@@ -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);
}

View File

@@ -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);
}
}