diff --git a/docs/widgets/core/arc.md b/docs/widgets/core/arc.md index b61976e32..afca25890 100644 --- a/docs/widgets/core/arc.md +++ b/docs/widgets/core/arc.md @@ -60,12 +60,24 @@ lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE); ## Events - `LV_EVENT_VALUE_CHANGED` sent when the arc is pressed/dragged to set a new value. -- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for the background rectangle, the background arc, the foreground arc and the knob to allow hooking the drawing. -For more detail on the backround rectangle part see the [Base object](/widgets/obj#events)'s documentation. The fields of `lv_obj_draw_dsc_t` are set as follows: - - For both arcs: `clip_area`, `p1` (center of the arc), `radius`, `arc_dsc`, `part`. - - For the knob: `clip_area`, `draw_area`, `rect_dsc`, `part`. - - +- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent with the following types: + - `LV_ARC_DRAW_PART_BACKGROUND` The background arc. + - `part`: `LV_PART_MAIN` + - `p1`: center of the arc + - `radius`: radius of the arc + - `arc_dsc` + - `LV_ARC_DRAW_PART_FOREGROUND` The foreground arc. + - `part`: `LV_PART_INDICATOR` + - `p1`: center of the arc + - `radius`: radius of the arc + - `arc_dsc` + - LV_ARC_DRAW_PART_KNOB The knob + - `part`: `LV_PART_KNOB` + - `draw_area`: the arae of the knob + - `rect_dsc`: + +See the events of the [Base object](/widgets/obj) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/core/bar.md b/docs/widgets/core/bar.md index ad1178a7d..e4c36cfc9 100644 --- a/docs/widgets/core/bar.md +++ b/docs/widgets/core/bar.md @@ -33,8 +33,13 @@ The bar can be one the following modes: - `LV_BAR_RANGE` Allows setting the start value too by `lv_bar_set_start_value(bar, new_value, LV_ANIM_ON/OFF)`. The start value always has to be smaller than the end value. ## Events -- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for both main and indicator parts to allow hooking the drawing. For more detail on the main part see the [Base object](/widgets/obj#events)'s documentation. -For the indicator the following fields are used: `clip_area`, `draw_area`, `rect_dsc`, `part`. +- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for the following parts: + - `LV_BAR_DRAW_PART_INDICATOR` The indicator of the bar + - `part`: `LV_PART_INDICATOR` + - `draw_area`: area of the indicator + - `rect_dsc` + +See the events of the [Base object](/widgets/obj) too. Learn more about [Events](/overview/event). diff --git a/docs/widgets/core/btn.md b/docs/widgets/core/btn.md index 3add1bdcb..fd47dbdb8 100644 --- a/docs/widgets/core/btn.md +++ b/docs/widgets/core/btn.md @@ -27,10 +27,10 @@ There are no new features compared to [Base object](/widgets/obj). Learn more about [Events](/overview/event). ## Keys -If `LV_OBJ_FLAG_CHECKABLE` is enabled `LV_KEY_RIGHT` and `LV_KEY_UP` make the object checked, and `LV_KEY_LEFT` and `LV_KEY_DOWN` make it unchecked. - Note that the state of `LV_KEY_ENTER` is translated to `LV_EVENT_PRESSED/PRESSING/RELEASED` etc. +See the events of the [Base object](/widgets/obj) too. + Learn more about [Keys](/overview/indev). ## Example diff --git a/docs/widgets/core/btnmatrix.md b/docs/widgets/core/btnmatrix.md index 75f93cbaa..ca336ef93 100644 --- a/docs/widgets/core/btnmatrix.md +++ b/docs/widgets/core/btnmatrix.md @@ -59,9 +59,14 @@ The "One check" feature can be enabled with `lv_btnmatrix_set_one_check(btnm, tr ## Events - `LV_EVENT_VALUE_CHANGED` Sent when a button is pressed/released or repeated after long press. The event parameter is set to the ID of the pressed/released button. -- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for both the main and the items (buttons) parts to allow hooking the drawing. -For more detail on the main part see the [Base object](/widgets/obj#events)'s documentation. -For the buttons the following fields are used: `clip_area`, `draw_area`, `rect_dsc`, `rect_dsc`, `part`, `id` (index of the button being drawn). +- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for the following types: + - `LV_BTNMATRIX_DRAW_PART_BTN` The individual buttons. + - `part`: `LV_PART_ITEMS` + - `id`:index of the button being drawn + - `draw_area`: the area of teh button + - `rect_dsc` + +See the events of the [Base object](/widgets/obj) too. `lv_btnmatrix_get_selected_btn(btnm)` returns the index of the most recently released or focused button or `LV_BTNMATRIX_BTN_NONE` if no such button. diff --git a/docs/widgets/core/canvas.md b/docs/widgets/core/canvas.md index bdeed7ca0..46a677d70 100644 --- a/docs/widgets/core/canvas.md +++ b/docs/widgets/core/canvas.md @@ -75,7 +75,10 @@ A given area of the canvas can be blurred horizontally with `lv_canvas_blur_hor( `r` is the radius of the blur (greater value means more intensive burring). `area` is the area where the blur should be applied (interpreted relative to the canvas). ## Events -The same events are sent as for the [Images](/widgets/core/img). +No special events are sent by canvas objects. +The same events are sent as for the + +See the events of the [Images](/widgets/core/img) too. Learn more about [Events](/overview/event). diff --git a/docs/widgets/core/checkbox.md b/docs/widgets/core/checkbox.md index 781a31aa8..3f5e89b59 100644 --- a/docs/widgets/core/checkbox.md +++ b/docs/widgets/core/checkbox.md @@ -36,9 +36,13 @@ lv_obj_add_state(cb, LV_STATE_CHECKED | LV_STATE_DISABLED); /*Make the checkbox ## Events - `LV_EVENT_VALUE_CHANGED` Sent when the checkbox is toggled. -- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for both main and indicator parts to allow hooking the drawing. -For more detail on the main part see the [Base object](/widgets/obj#events)'s documentation. -For the indicator the following fields are used: `clip_area`, `draw_area`, `rect_dsc`, `part`. +- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for the following types: + - `LV_CHECKBOX_DRAW_PART_BOX` The tickbox of the checkbox + - `part`: `LV_PART_INDICATOR` + - `draw_area`: the area of the tickbox + - `rect_dsc` + +See the events of the [Base object](/widgets/obj) too. Learn more about [Events](/overview/event). diff --git a/docs/widgets/core/dropdown.md b/docs/widgets/core/dropdown.md index b24b8d08e..f723f5a51 100644 --- a/docs/widgets/core/dropdown.md +++ b/docs/widgets/core/dropdown.md @@ -77,6 +77,8 @@ To manually open or close the drop-down list the `lv_dropdown_open/close(dropdow Apart from the [Generic events](../overview/event.html#generic-events), the following [Special events](../overview/event.html#special-events) are sent by the drop-down list: - `LV_EVENT_VALUE_CHANGED` Sent when the new option is selected or the list is opened/closed. +See the events of the [Base object](/widgets/obj) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/core/img.md b/docs/widgets/core/img.md index e8f3e11d3..7c537c634 100644 --- a/docs/widgets/core/img.md +++ b/docs/widgets/core/img.md @@ -95,6 +95,8 @@ Note that the real coordinates of image objects won't change during transformati ## Events No special events are sent by image objects. +See the events of the [Base object](/widgets/obj) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/core/label.md b/docs/widgets/core/label.md index 48b0b6754..0e022af99 100644 --- a/docs/widgets/core/label.md +++ b/docs/widgets/core/label.md @@ -64,6 +64,8 @@ The labels can display symbols alongside letters (or on their own). Read the [Fo ## Events No special events are sent by the Label. +See the events of the [Base object](/widgets/obj) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/core/line.md b/docs/widgets/core/line.md index 0d4dddae7..88ad616d0 100644 --- a/docs/widgets/core/line.md +++ b/docs/widgets/core/line.md @@ -25,6 +25,8 @@ By default, the *y == 0* point is in the top of the object. It might be conter-i ## Events Only the [Generic events](../overview/event.html#generic-events) are sent by the object type. +See the events of the [Base object](/widgets/obj) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/core/roller.md b/docs/widgets/core/roller.md index 687835c24..1bbe0e5ae 100644 --- a/docs/widgets/core/roller.md +++ b/docs/widgets/core/roller.md @@ -35,6 +35,8 @@ This function calculates the height with the current style. If the font, line sp ## Events - `LV_EVENT_VALUE_CHANGED` Sent when a new option is selected. +See the events of the [Base object](/widgets/obj) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/core/slider.md b/docs/widgets/core/slider.md index a3d164c35..5bf656e99 100644 --- a/docs/widgets/core/slider.md +++ b/docs/widgets/core/slider.md @@ -36,8 +36,22 @@ In the latter case the knob moves to the point clicked and slider value changes ## Events - `LV_EVENT_VALUE_CHANGED` Sent while the slider is being dragged or changed with keys. The event is sent continuously while the slider is dragged and once when released. Use `lv_slider_is_dragged` to detemine whether the Slider is still being dragged or has just been released. +- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for the following parts. + - `LV_SLIDER_DRAW_PART_KNOB` The main (right) knob of the slider + - `part`: `LV_PART_KNOB` + - `draw_area`: area of the indicator + - `rect_dsc` + - `id`: 0 + - `LV_SLIDER_DRAW_PART_KNOB` The left knob of the slider + - `part`: `LV_PART_KNOB` + - `draw_area`: area of the indicator + - `rect_dsc` + - `id`: 1 + +See the events of the [Bar](/widgets/core/bar) too. Learn more about [Events](/overview/event). + ## Keys - `LV_KEY_UP/RIGHT` Increment the slider's value by 1 - `LV_KEY_DOWN/LEFT` Decrement the slider's value by 1 diff --git a/docs/widgets/core/switch.md b/docs/widgets/core/switch.md index 67d4f9943..9524edf9f 100644 --- a/docs/widgets/core/switch.md +++ b/docs/widgets/core/switch.md @@ -25,6 +25,8 @@ To manually turn the switch on/off call `lvobj_add/clear_state(switch, LV_STATE_ ## Events - `LV_EVENT_VALUE_CHANGED` Sent when the switch changes state. +See the events of the [Base object](/widgets/obj) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/core/table.md b/docs/widgets/core/table.md index 9dda941d8..53f419aa8 100644 --- a/docs/widgets/core/table.md +++ b/docs/widgets/core/table.md @@ -49,10 +49,15 @@ E.g. `lv_obj_set_size(table, LV_SIZE_CONTENT, LV_SIZE_CONTENT)` automatically se If the width or height is set to a smaller number than the "intrinsic" size then the table becomes scrollable. ## Events -- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for both main and items parts to allow hooking the drawing. -For more detail on the main part see the [Base object](/widgets/obj#events)'s documentation. -For the items (cells) the following fields are used: `clip_area`, `draw_area`, `part`, `rect_dsc`, `label_dsc` `id` (current row × col count + current column). +- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for the following types: + - `LV_TABLE_DRAW_PART_CELL` The individual cells of the table + - `part`: `LV_PART_ITEMS` + - `draw_area`: area of the indicator + - `rect_dsc` + - `label_dsc` + - `id`: current row × col count + current column +See the events of the [Base object](/widgets/obj) too. Learn more about [Events](/overview/event). diff --git a/docs/widgets/core/textarea.md b/docs/widgets/core/textarea.md index 7adae6dad..70339c67b 100644 --- a/docs/widgets/core/textarea.md +++ b/docs/widgets/core/textarea.md @@ -98,6 +98,8 @@ The new text cannot be in a local variable which is destroyed when the event cal - `LV_EVENT_VALUE_CHANGED` Sent when the content of the text area has been changed. - `LV_EVENT_APPLY` Sent when `LV_KEY_ENTER` is pressed (or(sent) to a one line text area. +See the events of the [Base object](/widgets/obj) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/extra/chart.md b/docs/widgets/extra/chart.md index 9f43432a4..f04a3e547 100644 --- a/docs/widgets/extra/chart.md +++ b/docs/widgets/extra/chart.md @@ -131,16 +131,46 @@ The possible values of `dir` `LV_DIR_NONE/RIGHT/UP/LEFT/DOWN/HOR/VER/ALL` or th ## Events - `LV_EVENT_VALUE_CHANGED` Sent when a new point is clicked pressed. `lv_chart_get_pressed_point(chart)` returns the zero-based index of the pressed point. -- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent for multiple parts. The fields of `lv_obj_draw_part_dsc_t` are set as follows: - - `LV_PART_ITEMS` (the series) - - *Line chart* `clip_area`, `id` (index of the point), `value` (value of `id`th point), `p1`, `p2` (points of the line), `draw_area` (area of the point), `line_dsc`, `rect_dsc`, `sub_part_ptr` (pointer to the series), `part` - - *Bar chart* `clip_area`, `id` (index of the point), `value` (value of `id`th point), `draw_area` (area of the point), `rect_dsc`, `sub_part_ptr` (pointer to the series), `part` - - `LV_PART_TICKS` (major tick lines and label) `clip_area`, `id` (axis), `value` (scaled value of the tick), `text` (`value` converted to decimal), `line_dsc`, `label_dsc`, `part` - - `LV_PART_CURSOR` These events are sent at three times: - - vertical line `clip_area`, `p1`, `p2` (points of the line), `line_dsc`, `part` - - horizontal line `clip_area`, `p1`, `p2` (points of the line), `line_dsc`, `part` - - point `clip_area`, `draw_area` (points of the line), `rect_dsc`, `part` - - `LV_PART_MAIN` (the division lines) `clip_area`, `id` (index of the line), `p1`, `p2` (points of the line), `line_dsc`, `part`. Besides events for every line, an event is sent before the first line and after the last line with `id=0xFFFFFFFF`, `p1 = NULL` and `p2 = NULL`. It can be used to add/remove masks, or draw special division lines. +- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` are sent with the following types: + - `LV_CHART_DRAW_PART_DIV_LINE_INIT` Used before/after drawn the div lines to add masks to any extra drawings. The following fields are set: + - `part`: `LV_PART_MAIN` + - `line_dsc` + - `LV_CHART_DRAW_PART_DIV_LINE_HOR`, `LV_CHART_DRAW_PART_DIV_LINE_VER` Used for each horizontal and vertical division lines. + - `part`: `LV_PART_MAIN` + - `id`: index of the line + - `p1`, `p2`: (points of the line + - `line_dsc` + - `LV_CHART_DRAW_PART_LINE_AND_POINT` Used on line and scatter charts for lines and points. + - `part`: `LV_PART_ITEMS` + - `id`: index of the point + - `value`: value of `id`th point + - `p1`, `p2`: points of the line + - `draw_area`: area of the point + - `line_dsc` + - `rect_dsc` + - `sub_part_ptr`: pointer to the series + - `LV_CHART_DRAW_PART_BAR` Used on bar charts for the rectangles. + - `part`: `LV_PART_ITEMS` + - `id`: index of the point + - `value`: value of `id`th point + - `draw_area`: area of the point + - `rect_dsc`: + - `sub_part_ptr`: pointer to the series + - `LV_CHART_DRAW_PART_CURSOR` Used on cursor lines and points. + - `part`: `LV_PART_CURSOR` + - `p1`, `p2`: points of the line + - `line_dsc` + - `rect_dsc` + - `draw_area`: area of the points + - `LV_CHART_DRAW_PART_TICK_LABEL` Used on tick lines and labels. + - `part`: `LV_PART_TICKS` + - `id`: axis + - `value`: value of the tick + - `text`: `value` converted to decimal or `NULL` for minor ticks + - `line_dsc`, + - `label_dsc`, + +See the events of the [Base object](/widgets/obj) too. Learn more about [Events](/overview/event). diff --git a/docs/widgets/extra/led.md b/docs/widgets/extra/led.md index 4f6bbfd73..711edf6ad 100644 --- a/docs/widgets/extra/led.md +++ b/docs/widgets/extra/led.md @@ -24,7 +24,14 @@ You can set their brightness with `lv_led_set_bright(led, bright)`. The brightne Use `lv_led_on(led)` and `lv_led_off(led)` to set the brightness to a predefined ON or OFF value. The `lv_led_toggle(led)` toggles between the ON and OFF state. ## Events -No special event are sent by the LED object. +- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` is sent for the following types: + - `LV_LED_DRAW_PART_RECTANGLE` The main rectangle. `LV_OBJ_DRAW_PART_RECTANGLE` is not sent by the base object. + - `part`: `LV_PART_MAIN` + - `rect_dsc` + - `draw_area`: the area of the rectangle + + +See the events of the [Base object](/widgets/obj) too. Learn more about [Events](/overview/event). diff --git a/docs/widgets/extra/meter.md b/docs/widgets/extra/meter.md index 207131226..9689c361e 100644 --- a/docs/widgets/extra/meter.md +++ b/docs/widgets/extra/meter.md @@ -63,9 +63,34 @@ If `local` is `false` `color_start` and `color_end` will be mapped to the start `lv_meter_set_indicator_start_value(meter, inidicator, value)` and `lv_meter_set_indicator_end_value(meter, inidicator, value)` sets the value of the indicator. ## Events -- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` is sent for the tick labels to allow overwriting the texts. The following fields of `lv_obj_draw_part_dsc_t` is set: -`clip_area`, `part` (to `LV_PART_TICK`), `id` (the index of the major tick line), `value` (the value of the tick line), `label_dsc`, `text` (value converted to decimal) - +- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` is sent for the following types: + - `LV_METER_DRAW_PART_ARC` The arc indicator + - `part`: `LV_PART_ITEMS` + - `sub_part_ptr`: pointer to the indicator + - `arc_dsc` + - `radius`: radius of the arc + - `p1` center of the arc + - `LV_METER_DRAW_PART_NEEDLE_LINE` The needle lines + - `part`: `LV_PART_ITEMS` + - `p1`, `p2` points of the line + - `line_dsc` + - `sub_part_ptr`: pointer to the indicator + - `LV_METER_DRAW_PART_NEEDLE_IMG` The needle images + - `part`: `LV_PART_ITEMS` + - `p1`, `p2` points of the line + - `img_dsc` + - `sub_part_ptr`: pointer to the indicator + - `LV_METER_DRAW_PART_TICK` The tick lines and labels + - `part`: `LV_PART_TICKS` + - `value`: the value of the line + - `text`: `value` converted to decimal or `NULL` on minor lines + - `label_dsc`: label draw descriptor or `NULL` on minor lines + - `line_dsc`: + - `id`: the index of the line + + +See the events of the [Base object](/widgets/obj) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/extra/spinbox.md b/docs/widgets/extra/spinbox.md index 717a53d5d..52f249e7d 100644 --- a/docs/widgets/extra/spinbox.md +++ b/docs/widgets/extra/spinbox.md @@ -33,6 +33,8 @@ The parts of the Spinbox are identical to the [Text area](/widgets/core/textarea ## Events - `LV_EVENT_VALUE_CHANGED` Sent when the value has changed. +See the events of the [Text area](/widgets/core/textarea) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/extra/spinner.md b/docs/widgets/extra/spinner.md index 993507d01..6f6827ac9 100644 --- a/docs/widgets/extra/spinner.md +++ b/docs/widgets/extra/spinner.md @@ -19,6 +19,8 @@ To create a spinner use `lv_spinner_create(parent, spin_time, arc_length)`. `spi ## Events No special events are sent the the Spinner. +See the events of the [Arc](/widgets/core/arc) too. + Learn more about [Events](/overview/event). ## Keys diff --git a/docs/widgets/obj.md b/docs/widgets/obj.md index 188af5e5d..911f66895 100644 --- a/docs/widgets/obj.md +++ b/docs/widgets/obj.md @@ -149,6 +149,19 @@ By default, the objects can be clicked only on their coordinates, however, this ## Events - `LV_EVENT_VALUE_CHANGED` when the `LV_OBJ_FLAG_CHECKABLE` flag is enabled and the object clicked (on transition to/from the checked state) +- `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` is sent for the following types: + - `LV_OBJ_DRAW_PART_RECTANGLE` The main rectangle + - `part`: `LV_PART_MAIN` + - `rect_dsc` + - `draw_area`: the area of the rectangle + - `LV_OBJ_DRAW_PART_BORDER_POST` The border if the `border_post` style property is `true` + - `part`: `LV_PART_MAIN` + - `rect_dsc` + - `draw_area`: the area of the rectangle + - `LV_OBJ_DRAW_PART_SCROLLBAR` the scrollbars + - `part`: `LV_PART_SCROLLBAR` + - `rect_dsc` + - `draw_area`: the area of the rectangle Learn more about [Events](/overview/event). diff --git a/examples/widgets/chart/lv_example_chart_3.c b/examples/widgets/chart/lv_example_chart_3.c index d4560b41f..0c46668c3 100644 --- a/examples/widgets/chart/lv_example_chart_3.c +++ b/examples/widgets/chart/lv_example_chart_3.c @@ -3,10 +3,12 @@ static void draw_event_cb(lv_event_t * e) { - lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); - if(dsc->part == LV_PART_TICKS && dsc->id == LV_CHART_AXIS_PRIMARY_X) { + lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e); + if(!lv_obj_draw_part_check_type(dsc, &lv_chart_class, LV_CHART_DRAW_PART_TICK_LABEL)) return; + + if(dsc->id == LV_CHART_AXIS_PRIMARY_X && dsc->text) { const char * month[] = {"Jan", "Febr", "March", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec"}; - lv_snprintf(dsc->text, sizeof(dsc->text), "%s", month[dsc->value]); + dsc->text = month[dsc->value]; } } diff --git a/examples/widgets/chart/lv_example_chart_6.c b/examples/widgets/chart/lv_example_chart_6.c index 07a931196..7cc3c3b3b 100644 --- a/examples/widgets/chart/lv_example_chart_6.c +++ b/examples/widgets/chart/lv_example_chart_6.c @@ -19,37 +19,38 @@ static void event_cb(lv_event_t * e) } else if(code == LV_EVENT_DRAW_PART_END) { lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e); - if(dsc->part == LV_PART_CURSOR && dsc->p1 && dsc->p2 && dsc->p1->y == dsc->p2->y && last_id >= 0) { - lv_coord_t * data_array = lv_chart_get_y_array(chart, ser); - lv_coord_t v = data_array[last_id]; - char buf[16]; - lv_snprintf(buf, sizeof(buf), "%d", v); + if(!lv_obj_draw_part_check_type(dsc, &lv_chart_class, LV_CHART_DRAW_PART_CURSOR)) return; + if(dsc->p1 == NULL || dsc->p2 == NULL || dsc->p1->y != dsc->p2->y || last_id < 0) return; - lv_point_t size; - lv_txt_get_size(&size, buf, LV_FONT_DEFAULT, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE); + lv_coord_t * data_array = lv_chart_get_y_array(chart, ser); + lv_coord_t v = data_array[last_id]; + char buf[16]; + lv_snprintf(buf, sizeof(buf), "%d", v); - lv_area_t a; - a.y2 = dsc->p1->y - 5; - a.y1 = a.y2 - size.y - 10; - a.x1 = dsc->p1->x + 10; - a.x2 = a.x1 + size.x + 10; + lv_point_t size; + lv_txt_get_size(&size, buf, LV_FONT_DEFAULT, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE); - lv_draw_rect_dsc_t draw_rect_dsc; - lv_draw_rect_dsc_init(&draw_rect_dsc); - draw_rect_dsc.bg_color = lv_palette_main(LV_PALETTE_BLUE); - draw_rect_dsc.radius = 3; + lv_area_t a; + a.y2 = dsc->p1->y - 5; + a.y1 = a.y2 - size.y - 10; + a.x1 = dsc->p1->x + 10; + a.x2 = a.x1 + size.x + 10; - lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc); + lv_draw_rect_dsc_t draw_rect_dsc; + lv_draw_rect_dsc_init(&draw_rect_dsc); + draw_rect_dsc.bg_color = lv_palette_main(LV_PALETTE_BLUE); + draw_rect_dsc.radius = 3; - lv_draw_label_dsc_t draw_label_dsc; - lv_draw_label_dsc_init(&draw_label_dsc); - draw_label_dsc.color = lv_color_white(); - a.x1 += 5; - a.x2 -= 5; - a.y1 += 5; - a.y2 -= 5; - lv_draw_label(&a, dsc->clip_area, &draw_label_dsc, buf, NULL); - } + lv_draw_rect(&a, dsc->clip_area, &draw_rect_dsc); + + lv_draw_label_dsc_t draw_label_dsc; + lv_draw_label_dsc_init(&draw_label_dsc); + draw_label_dsc.color = lv_color_white(); + a.x1 += 5; + a.x2 -= 5; + a.y1 += 5; + a.y2 -= 5; + lv_draw_label(&a, dsc->clip_area, &draw_label_dsc, buf, NULL); } } diff --git a/src/core/lv_obj.c b/src/core/lv_obj.c index 2d0221b80..31a6a0cbc 100644 --- a/src/core/lv_obj.c +++ b/src/core/lv_obj.c @@ -500,6 +500,8 @@ static void lv_obj_draw(lv_event_t * e) lv_obj_draw_part_dsc_t part_dsc; lv_obj_draw_dsc_init(&part_dsc, clip_area); + part_dsc.class_p = MY_CLASS; + part_dsc.type = LV_OBJ_DRAW_PART_RECTANGLE; part_dsc.rect_dsc = &draw_dsc; part_dsc.draw_area = &coords; part_dsc.part = LV_PART_MAIN; @@ -547,7 +549,19 @@ static void lv_obj_draw(lv_event_t * e) coords.x2 += w; coords.y1 -= h; coords.y2 += h; + + + lv_obj_draw_part_dsc_t part_dsc; + lv_obj_draw_dsc_init(&part_dsc, clip_area); + part_dsc.class_p = MY_CLASS; + part_dsc.type = LV_OBJ_DRAW_PART_BORDER_POST; + part_dsc.rect_dsc = &draw_dsc; + part_dsc.draw_area = &coords; + part_dsc.part = LV_PART_MAIN; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_dsc); + lv_draw_rect(&coords, clip_area, &draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_dsc); } } } @@ -567,6 +581,8 @@ static void draw_scrollbar(lv_obj_t * obj, const lv_area_t * clip_area) lv_obj_draw_part_dsc_t part_dsc; lv_obj_draw_dsc_init(&part_dsc, clip_area); + part_dsc.class_p = MY_CLASS; + part_dsc.type = LV_OBJ_DRAW_PART_SCROLLBAR; part_dsc.rect_dsc = &draw_dsc; part_dsc.part = LV_PART_SCROLLBAR; diff --git a/src/core/lv_obj.h b/src/core/lv_obj.h index 103c70353..79d542236 100644 --- a/src/core/lv_obj.h +++ b/src/core/lv_obj.h @@ -105,19 +105,29 @@ enum { LV_OBJ_FLAG_IGNORE_LAYOUT = (1 << 15), /**< Make the object position-able by the layouts*/ LV_OBJ_FLAG_FLOATING = (1 << 16), /**< Do not scroll the object when the parent scrolls and ignore layout*/ - LV_OBJ_FLAG_LAYOUT_1 = (1 << 23), /** Custom flag, free to use by layouts*/ - LV_OBJ_FLAG_LAYOUT_2 = (1 << 24), /** Custom flag, free to use by layouts*/ + LV_OBJ_FLAG_LAYOUT_1 = (1 << 23), /**< Custom flag, free to use by layouts*/ + LV_OBJ_FLAG_LAYOUT_2 = (1 << 24), /**< Custom flag, free to use by layouts*/ - LV_OBJ_FLAG_WIDGET_1 = (1 << 25), /** Custom flag, free to use by widget*/ - LV_OBJ_FLAG_WIDGET_2 = (1 << 26), /** Custom flag, free to use by widget*/ + LV_OBJ_FLAG_WIDGET_1 = (1 << 25), /**< Custom flag, free to use by widget*/ + LV_OBJ_FLAG_WIDGET_2 = (1 << 26), /**< Custom flag, free to use by widget*/ - LV_OBJ_FLAG_USER_1 = (1 << 27), /** Custom flag, free to use by user*/ - LV_OBJ_FLAG_USER_2 = (1 << 28), /** Custom flag, free to use by user*/ - LV_OBJ_FLAG_USER_3 = (1 << 29), /** Custom flag, free to use by user*/ - LV_OBJ_FLAG_USER_4 = (1 << 30), /** Custom flag, free to use by user*/ + LV_OBJ_FLAG_USER_1 = (1 << 27), /**< Custom flag, free to use by user*/ + LV_OBJ_FLAG_USER_2 = (1 << 28), /**< Custom flag, free to use by user*/ + LV_OBJ_FLAG_USER_3 = (1 << 29), /**< Custom flag, free to use by user*/ + LV_OBJ_FLAG_USER_4 = (1 << 30), /**< Custom flag, free to use by user*/ }; typedef uint32_t lv_obj_flag_t; +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_obj_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_OBJ_DRAW_PART_RECTANGLE, /**< The main rectangle*/ + LV_OBJ_DRAW_PART_BORDER_POST,/**< The border if style_border_post = true*/ + LV_OBJ_DRAW_PART_SCROLLBAR, /**< The scrollbar*/ +}lv_obj_draw_part_type_t; + #include "lv_obj_tree.h" #include "lv_obj_pos.h" #include "lv_obj_scroll.h" diff --git a/src/core/lv_obj_draw.c b/src/core/lv_obj_draw.c index f0d50b60b..a9b6dbf89 100644 --- a/src/core/lv_obj_draw.c +++ b/src/core/lv_obj_draw.c @@ -330,6 +330,12 @@ void lv_obj_draw_dsc_init(lv_obj_draw_part_dsc_t * dsc, const lv_area_t * clip_a dsc->clip_area = clip_area; } +bool lv_obj_draw_part_check_type(lv_obj_draw_part_dsc_t * dsc, const lv_obj_class_t * class_p, uint32_t type) +{ + if(dsc->class_p == class_p && dsc->type == type) return true; + else return false; +} + void lv_obj_refresh_ext_draw_size(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); diff --git a/src/core/lv_obj_draw.h b/src/core/lv_obj_draw.h index 4858195e8..c50616e2d 100644 --- a/src/core/lv_obj_draw.h +++ b/src/core/lv_obj_draw.h @@ -24,6 +24,7 @@ extern "C" { **********************/ struct _lv_obj_t; +struct _lv_obj_class_t; /** Cover check results.*/ typedef enum { @@ -35,6 +36,8 @@ typedef enum { typedef struct { const lv_area_t * clip_area; /**< The current clip area, required if you need to draw something in the event*/ + const struct _lv_obj_class_t * class_p; /**< The class that sent the event */ + uint32_t type; /**< The type if part being draw. Element of `lv__draw_part_type_t` */ lv_area_t * draw_area; /**< The area of the part being drawn*/ lv_draw_rect_dsc_t * rect_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for rectangle-like parts*/ lv_draw_label_dsc_t * label_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for text-like parts*/ @@ -43,7 +46,7 @@ typedef struct lv_draw_arc_dsc_t * arc_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for arc-like parts*/ const lv_point_t * p1; /**< A point calculated during drawing. E.g. a point of chart or the center of an arc.*/ const lv_point_t * p2; /**< A point calculated during drawing. E.g. a point of chart.*/ - char text[16]; /**< A text calculated during drawing. Can be modified. E.g. tick labels on a chart axis.*/ + const char * text; /**< A text calculated during drawing. Can be modified. E.g. tick labels on a chart axis.*/ uint32_t part; /**< The current part for which the event is sent*/ uint32_t id; /**< The index of the part. E.g. a button's index on button matrix or table cell index.*/ lv_coord_t radius; /**< E.g. the radius of an arc (not the corner radius).*/ @@ -120,6 +123,15 @@ lv_coord_t lv_obj_calculate_ext_draw_size(struct _lv_obj_t * obj, uint32_t part) */ void lv_obj_draw_dsc_init(lv_obj_draw_part_dsc_t * dsc, const lv_area_t * clip_area); +/** + * Check the type obj a part draw descriptor + * @param dsc the descriptor (normally the event parameter) + * @param class_p pointer to class to which `type` is related + * @param type element of `lv__draw_part_type_t` + * @return true if ::dsc is related to ::class_p and ::type + */ +bool lv_obj_draw_part_check_type(lv_obj_draw_part_dsc_t * dsc, const struct _lv_obj_class_t * class_p, uint32_t type); + /** * Send a 'LV_EVENT_REFR_EXT_DRAW_SIZE' Call the ancestor's event handler to the object to refresh the value of the extended draw size. * The result will be saved in `obj`. diff --git a/src/extra/widgets/chart/lv_chart.c b/src/extra/widgets/chart/lv_chart.c index b5d1f1989..5ab7b3705 100644 --- a/src/extra/widgets/chart/lv_chart.c +++ b/src/extra/widgets/chart/lv_chart.c @@ -751,14 +751,16 @@ static void draw_div_lines(lv_obj_t * obj, const lv_area_t * clip_area) lv_draw_line_dsc_init(&line_dsc); lv_obj_init_draw_line_dsc(obj, LV_PART_MAIN, &line_dsc); - lv_obj_draw_part_dsc_t obj_draw_dsc; - lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area); - obj_draw_dsc.line_dsc = &line_dsc; - obj_draw_dsc.part = LV_PART_MAIN; - obj_draw_dsc.id = 0xFFFFFFFF; - obj_draw_dsc.p1 = NULL; - obj_draw_dsc.p2 = NULL; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc); + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.part = LV_PART_MAIN; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_CHART_DRAW_PART_DIV_LINE_INIT; + part_draw_dsc.line_dsc = &line_dsc; + part_draw_dsc.id = 0xFFFFFFFF; + part_draw_dsc.p1 = NULL; + part_draw_dsc.p2 = NULL; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_opa_t border_opa = lv_obj_get_style_border_opa(obj, LV_PART_MAIN); lv_coord_t border_w = lv_obj_get_style_border_width(obj, LV_PART_MAIN); @@ -783,13 +785,15 @@ static void draw_div_lines(lv_obj_t * obj, const lv_area_t * clip_area) p1.y += y_ofs; p2.y = p1.y; - obj_draw_dsc.p1 = &p1; - obj_draw_dsc.p2 = &p2; - obj_draw_dsc.id = i; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_CHART_DRAW_PART_DIV_LINE_HOR; + part_draw_dsc.p1 = &p1; + part_draw_dsc.p2 = &p2; + part_draw_dsc.id = i; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_line(&p1, &p2, &series_mask, &line_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } @@ -809,20 +813,22 @@ static void draw_div_lines(lv_obj_t * obj, const lv_area_t * clip_area) p1.x += x_ofs; p2.x = p1.x; - obj_draw_dsc.p1 = &p1; - obj_draw_dsc.p2 = &p2; - obj_draw_dsc.id = i; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_CHART_DRAW_PART_DIV_LINE_VER; + part_draw_dsc.p1 = &p1; + part_draw_dsc.p2 = &p2; + part_draw_dsc.id = i; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_line(&p1, &p2, &series_mask, &line_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } - obj_draw_dsc.id = 0xFFFFFFFF; - obj_draw_dsc.p1 = NULL; - obj_draw_dsc.p2 = NULL; - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc); + part_draw_dsc.id = 0xFFFFFFFF; + part_draw_dsc.p1 = NULL; + part_draw_dsc.p2 = NULL; + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } @@ -884,12 +890,14 @@ static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area) y_tmp = y_tmp / (chart->ymax[ser->y_axis_sec] - chart->ymin[ser->y_axis_sec]); p2.y = h - y_tmp + y_ofs; - lv_obj_draw_part_dsc_t dsc; - lv_obj_draw_dsc_init(&dsc, clip_area); - dsc.part = LV_PART_ITEMS; - dsc.line_dsc = &line_dsc_default; - dsc.rect_dsc = &point_dsc_default; - dsc.sub_part_ptr = ser; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_CHART_DRAW_PART_LINE_AND_POINT; + part_draw_dsc.part = LV_PART_ITEMS; + part_draw_dsc.line_dsc = &line_dsc_default; + part_draw_dsc.rect_dsc = &point_dsc_default; + part_draw_dsc.sub_part_ptr = ser; lv_coord_t y_min = p2.y; lv_coord_t y_max = p2.y; @@ -939,13 +947,13 @@ static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area) point_area.y1 = p1.y - point_h; point_area.y2 = p1.y + point_h; - dsc.id = i - 1; - dsc.p1 = ser->y_points[p_prev] != LV_CHART_POINT_NONE ? &p1 : NULL; - dsc.p2 = ser->y_points[p_act] != LV_CHART_POINT_NONE ? &p2 : NULL; - dsc.draw_area = &point_area; - dsc.value = ser->y_points[p_prev]; + part_draw_dsc.id = i - 1; + part_draw_dsc.p1 = ser->y_points[p_prev] != LV_CHART_POINT_NONE ? &p1 : NULL; + part_draw_dsc.p2 = ser->y_points[p_act] != LV_CHART_POINT_NONE ? &p2 : NULL; + part_draw_dsc.draw_area = &point_area; + part_draw_dsc.value = ser->y_points[p_prev]; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); if(ser->y_points[p_prev] != LV_CHART_POINT_NONE && ser->y_points[p_act] != LV_CHART_POINT_NONE) { lv_draw_line(&p1, &p2, &series_mask, &line_dsc_default); @@ -955,7 +963,7 @@ static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area) lv_draw_rect(&point_area, &series_mask, &point_dsc_default); } - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } @@ -972,14 +980,14 @@ static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area) point_area.y1 = p2.y - point_h; point_area.y2 = p2.y + point_h; - dsc.id = i - 1; - dsc.p1 = NULL; - dsc.p2 = NULL; - dsc.draw_area = &point_area; - dsc.value = ser->y_points[p_act]; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + part_draw_dsc.id = i - 1; + part_draw_dsc.p1 = NULL; + part_draw_dsc.p2 = NULL; + part_draw_dsc.draw_area = &point_area; + part_draw_dsc.value = ser->y_points[p_act]; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&point_area, &series_mask, &point_dsc_default); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } } @@ -1049,12 +1057,14 @@ static void draw_series_scatter(lv_obj_t * obj, const lv_area_t * clip_area) p2.y = LV_COORD_MIN; } - lv_obj_draw_part_dsc_t dsc; - lv_obj_draw_dsc_init(&dsc, clip_area); - dsc.part = LV_PART_ITEMS; - dsc.line_dsc = &line_dsc_default; - dsc.rect_dsc = &point_dsc_default; - dsc.sub_part_ptr = ser; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.part = LV_PART_ITEMS; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_CHART_DRAW_PART_LINE_AND_POINT; + part_draw_dsc.line_dsc = &line_dsc_default; + part_draw_dsc.rect_dsc = &point_dsc_default; + part_draw_dsc.sub_part_ptr = ser; for(i = 0; i < chart->point_cnt; i++) { p1.x = p2.x; @@ -1081,13 +1091,13 @@ static void draw_series_scatter(lv_obj_t * obj, const lv_area_t * clip_area) point_area.y1 = p1.y - point_h; point_area.y2 = p1.y + point_h; - dsc.id = i - 1; - dsc.p1 = ser->y_points[p_prev] != LV_CHART_POINT_NONE ? &p1 : NULL; - dsc.p2 = ser->y_points[p_act] != LV_CHART_POINT_NONE ? &p2 : NULL; - dsc.draw_area = &point_area; - dsc.value = ser->y_points[p_prev]; + part_draw_dsc.id = i - 1; + part_draw_dsc.p1 = ser->y_points[p_prev] != LV_CHART_POINT_NONE ? &p1 : NULL; + part_draw_dsc.p2 = ser->y_points[p_act] != LV_CHART_POINT_NONE ? &p2 : NULL; + part_draw_dsc.draw_area = &point_area; + part_draw_dsc.value = ser->y_points[p_prev]; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); if(ser->y_points[p_prev] != LV_CHART_POINT_NONE && ser->y_points[p_act] != LV_CHART_POINT_NONE) { lv_draw_line(&p1, &p2, &series_mask, &line_dsc_default); @@ -1096,7 +1106,7 @@ static void draw_series_scatter(lv_obj_t * obj, const lv_area_t * clip_area) } } - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } p_prev = p_act; } @@ -1111,14 +1121,14 @@ static void draw_series_scatter(lv_obj_t * obj, const lv_area_t * clip_area) point_area.y1 = p2.y - point_h; point_area.y2 = p2.y + point_h; - dsc.id = i - 1; - dsc.p1 = NULL; - dsc.p2 = NULL; - dsc.draw_area = &point_area; - dsc.value = ser->y_points[p_act]; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + part_draw_dsc.id = i - 1; + part_draw_dsc.p1 = NULL; + part_draw_dsc.p2 = NULL; + part_draw_dsc.draw_area = &point_area; + part_draw_dsc.value = ser->y_points[p_act]; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&point_area, &series_mask, &point_dsc_default); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } } @@ -1160,15 +1170,17 @@ static void draw_series_bar(lv_obj_t * obj, const lv_area_t * clip_area) bool mask_ret = _lv_area_intersect(&series_mask, &obj->coords, clip_area); if(mask_ret == false) return; - lv_obj_draw_part_dsc_t dsc; - lv_obj_draw_dsc_init(&dsc, &series_mask); - dsc.part = LV_PART_ITEMS; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, &series_mask); + part_draw_dsc.part = LV_PART_ITEMS; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_CHART_DRAW_PART_BAR; /*Go through all points*/ for(i = 0; i < chart->point_cnt; i++) { lv_coord_t x_act = (int32_t)((int32_t)(w + block_gap) * i) / (chart->point_cnt) + obj->coords.x1 + x_ofs; - dsc.id = i; + part_draw_dsc.id = i; /*Draw the current point of all data line*/ _LV_LL_READ_BACK(&chart->series_ll, ser) { @@ -1190,13 +1202,13 @@ static void draw_series_bar(lv_obj_t * obj, const lv_area_t * clip_area) col_a.y1 = h - y_tmp + obj->coords.y1 + y_ofs; if(ser->y_points[p_act] != LV_CHART_POINT_NONE) { - dsc.draw_area = &col_a; - dsc.rect_dsc = &col_dsc; - dsc.sub_part_ptr = ser; - dsc.value = ser->y_points[p_act]; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + part_draw_dsc.draw_area = &col_a; + part_draw_dsc.rect_dsc = &col_dsc; + part_draw_dsc.sub_part_ptr = ser; + part_draw_dsc.value = ser->y_points[p_act]; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&col_a, &series_mask, &col_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } } @@ -1228,11 +1240,13 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area) lv_coord_t point_w = lv_obj_get_style_width(obj, LV_PART_CURSOR) / 2; lv_coord_t point_h = lv_obj_get_style_width(obj, LV_PART_CURSOR) / 2; - lv_obj_draw_part_dsc_t dsc; - lv_obj_draw_dsc_init(&dsc, clip_area); - dsc.line_dsc = &line_dsc_tmp; - dsc.rect_dsc = &point_dsc_tmp; - dsc.part = LV_PART_CURSOR; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.line_dsc = &line_dsc_tmp; + part_draw_dsc.rect_dsc = &point_dsc_tmp; + part_draw_dsc.part = LV_PART_CURSOR; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_CHART_DRAW_PART_CURSOR; lv_area_t clip_area2; _lv_area_intersect(&clip_area2, clip_area, &obj->coords); @@ -1244,8 +1258,8 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area) line_dsc_tmp.color = cursor->color; point_dsc_tmp.bg_color = cursor->color; - dsc.p1 = &p1; - dsc.p2 = &p2; + part_draw_dsc.p1 = &p1; + part_draw_dsc.p2 = &p2; lv_coord_t cx; lv_coord_t cy; @@ -1263,15 +1277,26 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area) cx += obj->coords.x1; cy += obj->coords.y1; + lv_area_t point_area; + if(point_w && point_h) { + point_area.x1 = cx - point_w; + point_area.x2 = cx + point_w; + point_area.y1 = cy - point_h; + point_area.y2 = cy + point_h; + + part_draw_dsc.draw_area = &point_area; + } else { + part_draw_dsc.draw_area = NULL; + } + if(cursor->dir & LV_DIR_HOR) { p1.x = cursor->dir & LV_DIR_LEFT ? obj->coords.x1 : cx; p1.y = cy; p2.x = cursor->dir & LV_DIR_RIGHT ? obj->coords.x2 : cx; p2.y = p1.y; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_line(&p1, &p2, &clip_area2, &line_dsc_tmp); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); } if(cursor->dir & LV_DIR_VER) { @@ -1280,27 +1305,12 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area) p2.x = p1.x; p2.y = cursor->dir & LV_DIR_BOTTOM ? obj->coords.y2 : cy; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_line(&p1, &p2, &clip_area2, &line_dsc_tmp); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); } - if(point_w && point_h) { - lv_area_t point_area; - - point_area.x1 = cx - point_w; - point_area.x2 = cx + point_w; - point_area.y1 = cy - point_h; - point_area.y2 = cy + point_h; - - dsc.draw_area = &point_area; - dsc.p1 = NULL; - dsc.p2 = NULL; - - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); - lv_draw_rect(&point_area, &clip_area2, &point_dsc_tmp); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); - } + lv_draw_rect(&point_area, &clip_area2, &point_dsc_tmp); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } @@ -1351,12 +1361,14 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a lv_draw_label_dsc_init(&label_dsc); lv_obj_init_draw_label_dsc(obj, LV_PART_TICKS, &label_dsc); - lv_obj_draw_part_dsc_t dsc; - lv_obj_draw_dsc_init(&dsc, clip_area); - dsc.id = axis; - dsc.part = LV_PART_TICKS; - dsc.line_dsc = &line_dsc; - dsc.label_dsc = &label_dsc; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_CHART_DRAW_PART_TICK_LABEL; + part_draw_dsc.id = axis; + part_draw_dsc.part = LV_PART_TICKS; + part_draw_dsc.line_dsc = &line_dsc; + part_draw_dsc.label_dsc = &label_dsc; uint32_t total_tick_num = (t->major_cnt - 1) * (t->minor_cnt); for(i = 0; i <= total_tick_num; i++) { @@ -1377,22 +1389,23 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a if(major) p2.x = p1.x - major_len; /*major tick*/ else p2.x = p1.x - minor_len; /*minor tick*/ - if(p1.y + line_dsc.width / 2 >= obj->coords.y1 && - p2.y - line_dsc.width / 2 <= obj->coords.y2) - { - lv_draw_line(&p1, &p2, clip_area, &line_dsc); - } + part_draw_dsc.p1 = &p1; + part_draw_dsc.p2 = &p2; + + int32_t tick_value = lv_map(total_tick_num - i, 0, total_tick_num, chart->ymin[sec_axis], chart->ymax[sec_axis]); + part_draw_dsc.value = tick_value; /*add text only to major tick*/ - if(major && t->label_en) { - int32_t tick_value = lv_map(total_tick_num - i, 0, total_tick_num, chart->ymin[sec_axis], chart->ymax[sec_axis]); - lv_snprintf(dsc.text, sizeof(dsc.text), "%d", tick_value); - dsc.value = tick_value; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + if(major && t->label_en) { + char buf[16]; + lv_snprintf(buf, sizeof(buf), "%d", tick_value); + part_draw_dsc.label_dsc = &label_dsc; + part_draw_dsc.text = buf; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); /*reserve appropriate area*/ lv_point_t size; - lv_txt_get_size(&size, dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, LV_TEXT_FLAG_NONE); + lv_txt_get_size(&size, part_draw_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, LV_TEXT_FLAG_NONE); /*set the area at some distance of the major tick len left of the tick*/ lv_area_t a; @@ -1411,10 +1424,21 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a if(a.y2 >= obj->coords.y1 && a.y1 <= obj->coords.y2) { - lv_draw_label(&a, clip_area, &label_dsc, dsc.text, NULL); + lv_draw_label(&a, clip_area, &label_dsc, part_draw_dsc.text, NULL); } - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + } else { + part_draw_dsc.label_dsc = NULL; + part_draw_dsc.text = NULL; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); } + + if(p1.y + line_dsc.width / 2 >= obj->coords.y1 && + p2.y - line_dsc.width / 2 <= obj->coords.y2) + { + lv_draw_line(&p1, &p2, clip_area, &line_dsc); + } + + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } @@ -1460,12 +1484,14 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a line_dsc.dash_gap = 0; line_dsc.dash_width = 0; - lv_obj_draw_part_dsc_t dsc; - lv_obj_draw_dsc_init(&dsc, clip_area); - dsc.id = LV_CHART_AXIS_PRIMARY_X; - dsc.part = LV_PART_TICKS; - dsc.label_dsc = &label_dsc; - dsc.line_dsc = &line_dsc; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_CHART_DRAW_PART_TICK_LABEL; + part_draw_dsc.id = LV_CHART_AXIS_PRIMARY_X; + part_draw_dsc.part = LV_PART_TICKS; + part_draw_dsc.label_dsc = &label_dsc; + part_draw_dsc.line_dsc = &line_dsc; uint8_t sec_axis = axis == LV_CHART_AXIS_PRIMARY_X ? 0 : 1; @@ -1489,49 +1515,62 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a if(sec_axis) p2.y = p1.y - (major ? t->major_len : t->minor_len); else p2.y = p1.y + (major ? t->major_len : t->minor_len); - if(p1.x + line_dsc.width / 2 >= obj->coords.x1 && - p2.x - line_dsc.width / 2 <= obj->coords.x2) - { - lv_draw_line(&p1, &p2, clip_area, &line_dsc); - } + part_draw_dsc.p1 = &p1; + part_draw_dsc.p2 = &p2; /*add text only to major tick*/ - if(!major || !t->label_en) continue; - int32_t tick_value; if(chart->type == LV_CHART_TYPE_SCATTER) { tick_value = lv_map(i, 0, total_tick_num, chart->xmin[sec_axis], chart->xmax[sec_axis]); } else { tick_value = i / t->minor_cnt; } + part_draw_dsc.value = tick_value; - lv_snprintf(dsc.text, sizeof(dsc.text), "%d", tick_value); - dsc.value = tick_value; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + if(major && t->label_en) { + char buf[16]; + lv_snprintf(buf, sizeof(buf), "%d", tick_value); + part_draw_dsc.label_dsc = &label_dsc; + part_draw_dsc.text = buf; - /*reserve appropriate area*/ - lv_point_t size; - lv_txt_get_size(&size, dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, LV_TEXT_FLAG_NONE); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); - /*set the area at some distance of the major tick len under of the tick*/ - lv_area_t a; - a.x1 = (p2.x - size.x / 2); - a.x2 = (p2.x + size.x / 2); - if(sec_axis) { - a.y2 = p2.y - label_gap; - a.y1 = a.y2 - size.y; - } - else { - a.y1 = p2.y + label_gap; - a.y2 = a.y1 + size.y; + /*reserve appropriate area*/ + lv_point_t size; + lv_txt_get_size(&size, part_draw_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, LV_TEXT_FLAG_NONE); + + /*set the area at some distance of the major tick len under of the tick*/ + lv_area_t a; + a.x1 = (p2.x - size.x / 2); + a.x2 = (p2.x + size.x / 2); + if(sec_axis) { + a.y2 = p2.y - label_gap; + a.y1 = a.y2 - size.y; + } + else { + a.y1 = p2.y + label_gap; + a.y2 = a.y1 + size.y; + } + + if(a.x2 >= obj->coords.x1 && + a.x1 <= obj->coords.x2) + { + lv_draw_label(&a, clip_area, &label_dsc, part_draw_dsc.text, NULL); + } + } else { + part_draw_dsc.label_dsc = NULL; + part_draw_dsc.text = NULL; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); } - if(a.x2 >= obj->coords.x1 && - a.x1 <= obj->coords.x2) + + if(p1.x + line_dsc.width / 2 >= obj->coords.x1 && + p2.x - line_dsc.width / 2 <= obj->coords.x2) { - lv_draw_label(&a, clip_area, &label_dsc, dsc.text, NULL); + lv_draw_line(&p1, &p2, clip_area, &line_dsc); } - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } diff --git a/src/extra/widgets/chart/lv_chart.h b/src/extra/widgets/chart/lv_chart.h index 03b85e7d9..cc3db3041 100644 --- a/src/extra/widgets/chart/lv_chart.h +++ b/src/extra/widgets/chart/lv_chart.h @@ -116,6 +116,20 @@ typedef struct { extern const lv_obj_class_t lv_chart_class; +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_chart_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_CHART_DRAW_PART_DIV_LINE_INIT, /**< Used before/after drawn the div lines*/ + LV_CHART_DRAW_PART_DIV_LINE_HOR, /**< Used for each horizontal division lines*/ + LV_CHART_DRAW_PART_DIV_LINE_VER, /**< Used for each vertical division lines*/ + LV_CHART_DRAW_PART_LINE_AND_POINT, /**< Used on line and scatter charts for lines and points*/ + LV_CHART_DRAW_PART_BAR, /**< Used on bar charts for the rectangles*/ + LV_CHART_DRAW_PART_CURSOR, /**< Used on cursor lines and points*/ + LV_CHART_DRAW_PART_TICK_LABEL, /**< Used on tick lines and labels*/ +}lv_chart_draw_part_type_t; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/extra/widgets/led/lv_led.c b/src/extra/widgets/led/lv_led.c index 905616484..24d8ba0f4 100644 --- a/src/extra/widgets/led/lv_led.c +++ b/src/extra/widgets/led/lv_led.c @@ -203,15 +203,17 @@ static void lv_led_event(const lv_obj_class_t * class_p, lv_event_t * e) const lv_area_t * clip_area = lv_event_get_param(e); - lv_obj_draw_part_dsc_t part_dsc; - lv_obj_draw_dsc_init(&part_dsc, clip_area); - part_dsc.draw_area = &obj->coords; - part_dsc.rect_dsc = &rect_dsc; - part_dsc.part = LV_PART_MAIN; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.draw_area = &obj->coords; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_LED_DRAW_PART_RECTANGLE; + part_draw_dsc.rect_dsc = &rect_dsc; + part_draw_dsc.part = LV_PART_MAIN; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&obj->coords, clip_area, &rect_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } diff --git a/src/extra/widgets/led/lv_led.h b/src/extra/widgets/led/lv_led.h index 7c9b350cb..83b765e07 100644 --- a/src/extra/widgets/led/lv_led.h +++ b/src/extra/widgets/led/lv_led.h @@ -35,6 +35,14 @@ typedef struct { extern const lv_obj_class_t lv_led_class; +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_led_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_LED_DRAW_PART_RECTANGLE, /**< The main rectangle*/ +}lv_ledc_draw_part_type_t; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/extra/widgets/meter/lv_meter.c b/src/extra/widgets/meter/lv_meter.c index ff175404a..af7b76782 100644 --- a/src/extra/widgets/meter/lv_meter.c +++ b/src/extra/widgets/meter/lv_meter.c @@ -322,6 +322,14 @@ static void draw_arcs(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area lv_opa_t opa_main = lv_obj_get_style_opa(obj, LV_PART_MAIN); lv_meter_indicator_t * indic; + + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.arc_dsc = &arc_dsc; + part_draw_dsc.part = LV_PART_INDICATOR; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_METER_DRAW_PART_ARC; + _LV_LL_READ_BACK(&meter->indicator_ll, indic) { if(indic->type != LV_METER_INDICATOR_TYPE_ARC) continue; @@ -333,7 +341,14 @@ static void draw_arcs(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area int32_t start_angle = lv_map(indic->start_value, scale->min, scale->max, scale->rotation, scale->rotation + scale->angle_range); int32_t end_angle = lv_map(indic->end_value, scale->min, scale->max, scale->rotation, scale->rotation + scale->angle_range); - lv_draw_arc(scale_center.x, scale_center.y, r_out + indic->type_data.arc.r_mod, start_angle, end_angle, clip_area, &arc_dsc); + + part_draw_dsc.radius = r_out + indic->type_data.arc.r_mod; + part_draw_dsc.sub_part_ptr = indic; + part_draw_dsc.p1 = &scale_center; + + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); + lv_draw_arc(scale_center.x, scale_center.y, part_draw_dsc.radius, start_angle, end_angle, clip_area, &arc_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } @@ -359,22 +374,24 @@ static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c lv_meter_scale_t * scale; - lv_obj_draw_part_dsc_t dsc; - lv_obj_draw_dsc_init(&dsc, clip_area); - -#if LV_DRAW_COMPLEX lv_draw_mask_radius_param_t inner_minor_mask; lv_draw_mask_radius_param_t inner_major_mask; lv_draw_mask_radius_param_t outer_mask; -#endif + + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.part = LV_PART_TICKS; + part_draw_dsc.type = LV_METER_DRAW_PART_TICK; + part_draw_dsc.line_dsc = &line_dsc; _LV_LL_READ_BACK(&meter->scale_ll, scale) { + part_draw_dsc.sub_part_ptr = scale; lv_coord_t r_out = r_edge + scale->r_mod; lv_coord_t r_in_minor = r_out - scale->tick_length; lv_coord_t r_in_major = r_out - scale->tick_major_length; -#if LV_DRAW_COMPLEX lv_area_t area_inner_minor; area_inner_minor.x1 = p_center.x - r_in_minor; area_inner_minor.y1 = p_center.y - r_in_minor; @@ -398,7 +415,6 @@ static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c int16_t outer_mask_id = lv_draw_mask_add(&outer_mask, NULL); int16_t inner_act_mask_id = -1; /*Will be added later*/ -#endif uint32_t minor_cnt = scale->tick_major_nth ? scale->tick_major_nth - 1 : 0xFFFF; for(i = 0; i < scale->tick_cnt; i++) { @@ -409,11 +425,10 @@ static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c major = true; } -#if LV_DRAW_COMPLEX inner_act_mask_id = lv_draw_mask_add(major ? &inner_major_mask : &inner_minor_mask, NULL); -#endif int32_t value_of_line = lv_map(i, 0, scale->tick_cnt - 1, scale->min, scale->max); + part_draw_dsc.value = value_of_line; lv_color_t line_color = major ? scale->tick_major_color : scale->tick_color; lv_color_t line_color_ori = line_color; @@ -457,40 +472,27 @@ static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c int32_t cos_high = lv_trigo_cos(angle_high + scale->rotation); int32_t cos_mid = (cos_low * (256 - angle_rem) + cos_high * angle_rem) >> 8; - line_dsc.color = line_color; line_dsc.width = line_width; -#if LV_DRAW_COMPLEX /*Use the interpolated angle to get the outer x and y coordinates. *Draw a little bit longer lines to be sure the mask will clip them correctly*/ lv_point_t p_outer; p_outer.x = (int32_t)(((int32_t)cos_mid * (r_out + line_width) + 127) >> (LV_TRIGO_SHIFT)) + p_center.x; p_outer.y = (int32_t)(((int32_t)sin_mid * (r_out + line_width) + 127) >> (LV_TRIGO_SHIFT)) + p_center.y; - lv_draw_line(&p_outer, &p_center, clip_area, &line_dsc); -#else - /*Use the interpolated angle to get the outer and inner x and y coordinates.*/ - lv_point_t p_outer; - p_outer.x = (int32_t)(((int32_t)cos_mid * (r_out) + 127) >> (LV_TRIGO_SHIFT)) + p_center.x; - p_outer.y = (int32_t)(((int32_t)sin_mid * (r_out) + 127) >> (LV_TRIGO_SHIFT)) + p_center.y; - lv_point_t p_inner; - lv_coord_t r_in = major ? r_in_major : r_in_minor; - p_inner.x = (int32_t)(((int32_t)cos_mid * (r_in) + 127) >> (LV_TRIGO_SHIFT)) + p_center.x; - p_inner.y = (int32_t)(((int32_t)sin_mid * (r_in) + 127) >> (LV_TRIGO_SHIFT)) + p_center.y; - lv_draw_line(&p_outer, &p_inner, clip_area, &line_dsc); -#endif + + part_draw_dsc.p1 = &p_outer; + part_draw_dsc.p1 = &p_center; + part_draw_dsc.id = i; + part_draw_dsc.label_dsc = &label_dsc; line_dsc.color = line_color_ori; line_dsc.width = line_width_ori; -#if LV_DRAW_COMPLEX lv_draw_mask_remove_id(inner_act_mask_id); -#endif /*Draw the text*/ if(major) { -#if LV_DRAW_COMPLEX lv_draw_mask_remove_id(outer_mask_id); -#endif uint32_t r_text = r_in_major - scale->label_gap; lv_point_t p; p.x = (int32_t)((int32_t)((int32_t)cos_mid * r_text + 127) >> LV_TRIGO_SHIFT) + p_center.x; @@ -499,14 +501,16 @@ static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c lv_draw_label_dsc_t label_dsc_tmp; lv_memcpy(&label_dsc_tmp, &label_dsc, sizeof(label_dsc_tmp)); - dsc.id = i / scale->tick_major_nth; - dsc.value = value_of_line; - dsc.label_dsc = &label_dsc_tmp; - lv_snprintf(dsc.text, sizeof(dsc.text), "%d", value_of_line); - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + part_draw_dsc.label_dsc = &label_dsc_tmp; + char buf[16]; + + lv_snprintf(buf, sizeof(buf), "%d", value_of_line); + part_draw_dsc.text = buf; + + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_point_t label_size; - lv_txt_get_size(&label_size, dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, + lv_txt_get_size(&label_size, part_draw_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, LV_TEXT_FLAG_NONE); lv_area_t label_cord; @@ -515,18 +519,20 @@ static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c label_cord.x2 = label_cord.x1 + label_size.x; label_cord.y2 = label_cord.y1 + label_size.y; - lv_draw_label(&label_cord, clip_area, &label_dsc, dsc.text, NULL); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + lv_draw_label(&label_cord, clip_area, &label_dsc, part_draw_dsc.text, NULL); -#if LV_DRAW_COMPLEX outer_mask_id = lv_draw_mask_add(&outer_mask, NULL); -#endif + } else { + part_draw_dsc.label_dsc = NULL; + part_draw_dsc.text = NULL; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); } + lv_draw_line(&p_outer, &p_center, clip_area, &line_dsc); + lv_event_send(obj, LV_EVENT_DRAW_MAIN_END, &part_draw_dsc); + } -#if LV_DRAW_COMPLEX lv_draw_mask_remove_id(outer_mask_id); -#endif } } @@ -542,17 +548,23 @@ static void draw_needles(lv_obj_t * obj, const lv_area_t * clip_area, const lv_a lv_draw_line_dsc_t line_dsc; lv_draw_line_dsc_init(&line_dsc); - lv_obj_init_draw_line_dsc(obj, LV_PART_INDICATOR, &line_dsc); + lv_obj_init_draw_line_dsc(obj, LV_PART_ITEMS, &line_dsc); lv_draw_img_dsc_t img_dsc; lv_draw_img_dsc_init(&img_dsc); - lv_obj_init_draw_img_dsc(obj, LV_PART_INDICATOR, &img_dsc); - img_dsc.antialias = 1; + lv_obj_init_draw_img_dsc(obj, LV_PART_ITEMS, &img_dsc); lv_opa_t opa_main = lv_obj_get_style_opa(obj, LV_PART_MAIN); + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.p1 = &scale_center; + lv_meter_indicator_t * indic; _LV_LL_READ_BACK(&meter->indicator_ll, indic) { lv_meter_scale_t * scale = indic->scale; + part_draw_dsc.sub_part_ptr = indic; + if(indic->type == LV_METER_INDICATOR_TYPE_NEEDLE_LINE) { int32_t angle = lv_map(indic->end_value, scale->min, scale->max, scale->rotation, scale->rotation + scale->angle_range); lv_coord_t r_out = r_edge + scale->r_mod + indic->type_data.needle_line.r_mod; @@ -562,7 +574,14 @@ static void draw_needles(lv_obj_t * obj, const lv_area_t * clip_area, const lv_a line_dsc.color = indic->type_data.needle_line.color; line_dsc.width = indic->type_data.needle_line.width; line_dsc.opa = indic->opa > LV_OPA_MAX ? opa_main : (opa_main * indic->opa) >> 8; + + part_draw_dsc.id = LV_METER_DRAW_PART_NEEDLE_LINE; + part_draw_dsc.line_dsc = &line_dsc; + part_draw_dsc.p2 = &p_end; + + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_line(&scale_center, &p_end, clip_area, &line_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } else if(indic->type == LV_METER_INDICATOR_TYPE_NEEDLE_IMG) { if(indic->type_data.needle_img.src == NULL) continue; @@ -582,7 +601,12 @@ static void draw_needles(lv_obj_t * obj, const lv_area_t * clip_area, const lv_a angle = angle * 10; if(angle > 3600) angle -= 3600; img_dsc.angle = angle; + + part_draw_dsc.img_dsc = &img_dsc; + + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_img(&a, clip_area, indic->type_data.needle_img.src, &img_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } } diff --git a/src/extra/widgets/meter/lv_meter.h b/src/extra/widgets/meter/lv_meter.h index 1151408d7..2084f1c89 100644 --- a/src/extra/widgets/meter/lv_meter.h +++ b/src/extra/widgets/meter/lv_meter.h @@ -17,6 +17,11 @@ extern "C" { #if LV_USE_METER != 0 +/*Testing of dependencies*/ +#if LV_DRAW_COMPLEX == 0 +#error "lv_meter: Complex drawing is required. Enable it in lv_conf.h (LV_DRAW_COMPLEX 1)" +#endif + /********************* * DEFINES *********************/ @@ -93,6 +98,17 @@ typedef struct { extern const lv_obj_class_t lv_meter_class; +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_meter_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_METER_DRAW_PART_ARC, /**< The arc indicator*/ + LV_METER_DRAW_PART_NEEDLE_LINE, /**< The needle lines*/ + LV_METER_DRAW_PART_NEEDLE_IMG, /**< The needle images*/ + LV_METER_DRAW_PART_TICK, /**< The tick lines and labels*/ +}lv_meter_draw_part_type_t; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/widgets/lv_arc.c b/src/widgets/lv_arc.c index 2b7bc8a35..e81caef59 100644 --- a/src/widgets/lv_arc.c +++ b/src/widgets/lv_arc.c @@ -688,8 +688,8 @@ static void lv_arc_draw(lv_event_t * e) lv_coord_t arc_r; get_center(obj, ¢er, &arc_r); - lv_obj_draw_part_dsc_t obj_draw_dsc; - lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area); + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); /*Draw the background arc*/ lv_draw_arc_dsc_t arc_dsc; @@ -697,17 +697,19 @@ static void lv_arc_draw(lv_event_t * e) lv_draw_arc_dsc_init(&arc_dsc); lv_obj_init_draw_arc_dsc(obj, LV_PART_MAIN, &arc_dsc); - obj_draw_dsc.part = LV_PART_MAIN; - obj_draw_dsc.p1 = ¢er; - obj_draw_dsc.radius = arc_r; - obj_draw_dsc.arc_dsc = &arc_dsc; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc); + part_draw_dsc.part = LV_PART_MAIN; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_ARC_DRAW_PART_BACKGROUND; + part_draw_dsc.p1 = ¢er; + part_draw_dsc.radius = arc_r; + part_draw_dsc.arc_dsc = &arc_dsc; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); - lv_draw_arc(center.x, center.y, arc_r, arc->bg_angle_start + arc->rotation, + lv_draw_arc(center.x, center.y, part_draw_dsc.radius, arc->bg_angle_start + arc->rotation, arc->bg_angle_end + arc->rotation, clip_area, &arc_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } /*make the indicator arc smaller or larger according to its greatest padding value*/ @@ -721,17 +723,19 @@ static void lv_arc_draw(lv_event_t * e) lv_draw_arc_dsc_init(&arc_dsc); lv_obj_init_draw_arc_dsc(obj, LV_PART_INDICATOR, &arc_dsc); - obj_draw_dsc.part = LV_PART_INDICATOR; - obj_draw_dsc.p1 = ¢er; - obj_draw_dsc.radius = indic_r; - obj_draw_dsc.arc_dsc = &arc_dsc; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc); + part_draw_dsc.part = LV_PART_INDICATOR; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_ARC_DRAW_PART_FOREGROUND; + part_draw_dsc.p1 = ¢er; + part_draw_dsc.radius = indic_r; + part_draw_dsc.arc_dsc = &arc_dsc; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); - lv_draw_arc(center.x, center.y, indic_r, arc->indic_angle_start +arc->rotation, + lv_draw_arc(center.x, center.y, part_draw_dsc.radius, arc->indic_angle_start +arc->rotation, arc->indic_angle_end + arc->rotation, clip_area, &arc_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } lv_area_t knob_area; @@ -741,14 +745,16 @@ static void lv_arc_draw(lv_event_t * e) lv_draw_rect_dsc_init(&knob_rect_dsc); lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &knob_rect_dsc); - obj_draw_dsc.part = LV_PART_KNOB; - obj_draw_dsc.draw_area = &knob_area; - obj_draw_dsc.rect_dsc = &knob_rect_dsc; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc); + part_draw_dsc.part = LV_PART_KNOB; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_ARC_DRAW_PART_KNOB; + part_draw_dsc.draw_area = &knob_area; + part_draw_dsc.rect_dsc = &knob_rect_dsc; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&knob_area, clip_area, &knob_rect_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } static void inv_arc_area(lv_obj_t * obj, uint16_t start_angle, uint16_t end_angle, lv_part_t part) diff --git a/src/widgets/lv_arc.h b/src/widgets/lv_arc.h index 6fbc9b761..e0c11e35f 100644 --- a/src/widgets/lv_arc.h +++ b/src/widgets/lv_arc.h @@ -54,6 +54,16 @@ typedef struct { extern const lv_obj_class_t lv_arc_class; +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_arc_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_ARC_DRAW_PART_BACKGROUND, /**< The background arc*/ + LV_ARC_DRAW_PART_FOREGROUND, /**< The foreground arc*/ + LV_ARC_DRAW_PART_KNOB, /**< The knob*/ +}lv_arc_draw_part_type_t; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/widgets/lv_bar.c b/src/widgets/lv_bar.c index 793be15ce..6f119ae02 100644 --- a/src/widgets/lv_bar.c +++ b/src/widgets/lv_bar.c @@ -382,13 +382,15 @@ static void draw_indic(lv_event_t * e) /*Do not draw a zero length indicator but at least call the draw part events*/ if(!sym && indic_length_calc(&bar->indic_area) <= 1) { - lv_obj_draw_part_dsc_t obj_draw_dsc; - lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area); - obj_draw_dsc.part = LV_PART_INDICATOR; - obj_draw_dsc.draw_area = &bar->indic_area; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.part = LV_PART_INDICATOR; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_BAR_DRAW_PART_INDICATOR; + part_draw_dsc.draw_area = &bar->indic_area; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); return; } @@ -403,13 +405,15 @@ static void draw_indic(lv_event_t * e) lv_draw_rect_dsc_init(&draw_rect_dsc); lv_obj_init_draw_rect_dsc(obj, LV_PART_INDICATOR, &draw_rect_dsc); - lv_obj_draw_part_dsc_t obj_draw_dsc; - lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area); - obj_draw_dsc.part = LV_PART_INDICATOR; - obj_draw_dsc.rect_dsc = &draw_rect_dsc; - obj_draw_dsc.draw_area = &bar->indic_area; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.part = LV_PART_INDICATOR; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_BAR_DRAW_PART_INDICATOR; + part_draw_dsc.rect_dsc = &draw_rect_dsc; + part_draw_dsc.draw_area = &bar->indic_area; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); /*Draw only the shadow if the indicator is long enough. *The radius of the bg and the indicator can make a strange shape where @@ -486,7 +490,7 @@ static void draw_indic(lv_event_t * e) lv_draw_mask_remove_id(mask_bg_id); #endif - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } static void lv_bar_event(const lv_obj_class_t * class_p, lv_event_t * e) diff --git a/src/widgets/lv_bar.h b/src/widgets/lv_bar.h index cb3f99d20..8091923e3 100644 --- a/src/widgets/lv_bar.h +++ b/src/widgets/lv_bar.h @@ -58,6 +58,14 @@ typedef struct { extern const lv_obj_class_t lv_bar_class; +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_bar_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_BAR_DRAW_PART_INDICATOR, /**< The indicator*/ +}lv_bar_draw_part_type_t; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/widgets/lv_btnmatrix.c b/src/widgets/lv_btnmatrix.c index dd33ade13..12aaada78 100644 --- a/src/widgets/lv_btnmatrix.c +++ b/src/widgets/lv_btnmatrix.c @@ -670,11 +670,13 @@ static void draw_main(lv_event_t * e) char * txt_ap = lv_mem_buf_get(txt_ap_size); #endif - lv_obj_draw_part_dsc_t dsc; - lv_obj_draw_dsc_init(&dsc, clip_area); - dsc.part = LV_PART_ITEMS; - dsc.rect_dsc = &draw_rect_dsc_act; - dsc.label_dsc = &draw_label_dsc_act; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.part = LV_PART_ITEMS; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_BTNMATRIX_DRAW_PART_BTN; + part_draw_dsc.rect_dsc = &draw_rect_dsc_act; + part_draw_dsc.label_dsc = &draw_label_dsc_act; for(btn_i = 0; btn_i < btnm->btn_cnt; btn_i++, txt_i++) { /*Search the next valid text in the map*/ @@ -725,9 +727,9 @@ static void draw_main(lv_event_t * e) else draw_label_dsc_act.flag &= ~LV_TEXT_FLAG_RECOLOR; - dsc.draw_area = &btn_area; - dsc.id = btn_i; - lv_event_send(obj,LV_EVENT_DRAW_PART_BEGIN, &dsc); + part_draw_dsc.draw_area = &btn_area; + part_draw_dsc.id = btn_i; + lv_event_send(obj,LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); /*Remove borders on the edges if `LV_BORDER_SIDE_INTERNAL`*/ if(draw_rect_dsc_act.border_side & LV_BORDER_SIDE_INTERNAL) { @@ -767,7 +769,7 @@ static void draw_main(lv_event_t * e) /*Draw the text*/ lv_draw_label(&btn_area, clip_area, &draw_label_dsc_act, txt, NULL); - lv_event_send(obj,LV_EVENT_DRAW_PART_END, &dsc); + lv_event_send(obj,LV_EVENT_DRAW_PART_END, &part_draw_dsc); } obj->skip_trans = 0; diff --git a/src/widgets/lv_btnmatrix.h b/src/widgets/lv_btnmatrix.h index c13493d2d..7e782f2e8 100644 --- a/src/widgets/lv_btnmatrix.h +++ b/src/widgets/lv_btnmatrix.h @@ -62,6 +62,14 @@ typedef struct { extern const lv_obj_class_t lv_btnmatrix_class; +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_btnmatrix_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_BTNMATRIX_DRAW_PART_BTN, /**< The rectangle and label of buttons*/ +}lv_btnmatrix_draw_part_type_t; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/widgets/lv_checkbox.c b/src/widgets/lv_checkbox.c index 651d14114..ddc1c5c92 100644 --- a/src/widgets/lv_checkbox.c +++ b/src/widgets/lv_checkbox.c @@ -234,15 +234,17 @@ static void lv_checkbox_draw(lv_event_t * e) marker_area_transf.y1 -= transf_h; marker_area_transf.y2 += transf_h; - lv_obj_draw_part_dsc_t obj_draw_dsc; - lv_obj_draw_dsc_init(&obj_draw_dsc, clip_area); - obj_draw_dsc.rect_dsc = &indic_dsc; - obj_draw_dsc.draw_area = &marker_area_transf; - obj_draw_dsc.part = LV_PART_INDICATOR; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.rect_dsc = &indic_dsc; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_CHECKBOX_DRAW_PART_BOX; + part_draw_dsc.draw_area = &marker_area_transf; + part_draw_dsc.part = LV_PART_INDICATOR; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&marker_area_transf, clip_area, &indic_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &obj_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN); lv_coord_t letter_space = lv_obj_get_style_text_letter_space(obj, LV_PART_MAIN); diff --git a/src/widgets/lv_checkbox.h b/src/widgets/lv_checkbox.h index a1027a021..a21cfd7be 100644 --- a/src/widgets/lv_checkbox.h +++ b/src/widgets/lv_checkbox.h @@ -34,6 +34,14 @@ typedef struct { extern const lv_obj_class_t lv_checkbox_class; +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_checkbox_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_CHECKBOX_DRAW_PART_BOX, /**< The tick box*/ +}lv_checkbox_draw_part_type_t; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/widgets/lv_slider.c b/src/widgets/lv_slider.c index 327fbb2ef..ad8ef2466 100644 --- a/src/widgets/lv_slider.c +++ b/src/widgets/lv_slider.c @@ -370,25 +370,27 @@ static void draw_knob(lv_event_t * e) position_knob(obj, &knob_area, knob_size, hor); lv_area_copy(&slider->right_knob_area, &knob_area); - lv_obj_draw_part_dsc_t dsc; - lv_obj_draw_dsc_init(&dsc, clip_area); - dsc.part = LV_PART_KNOB; - dsc.id = 0; - dsc.draw_area = &slider->right_knob_area; - dsc.rect_dsc = &knob_rect_dsc; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.part = LV_PART_KNOB; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_SLIDER_DRAW_PART_KNOB; + part_draw_dsc.id = 0; + part_draw_dsc.draw_area = &slider->right_knob_area; + part_draw_dsc.rect_dsc = &knob_rect_dsc; if(lv_slider_get_mode(obj) != LV_SLIDER_MODE_RANGE) { - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&slider->right_knob_area, clip_area, &knob_rect_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } else { - /*Save the draw dsc. because it can be modified in the event*/ + /*Save the draw part_draw_dsc. because it can be modified in the event*/ lv_draw_rect_dsc_t knob_rect_dsc_tmp; lv_memcpy(&knob_rect_dsc_tmp, &knob_rect_dsc, sizeof(lv_draw_rect_dsc_t)); - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&slider->right_knob_area, clip_area, &knob_rect_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); /*Draw a second knob for the start_value side*/ if(hor) { @@ -401,13 +403,14 @@ static void draw_knob(lv_event_t * e) lv_area_copy(&slider->left_knob_area, &knob_area); lv_memcpy(&knob_rect_dsc, &knob_rect_dsc_tmp, sizeof(lv_draw_rect_dsc_t)); - dsc.draw_area = &slider->left_knob_area; - dsc.rect_dsc = &knob_rect_dsc; - dsc.id = 1; + part_draw_dsc.type = LV_SLIDER_DRAW_PART_KNOB_LEFT; + part_draw_dsc.draw_area = &slider->left_knob_area; + part_draw_dsc.rect_dsc = &knob_rect_dsc; + part_draw_dsc.id = 1; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&slider->left_knob_area, clip_area, &knob_rect_dsc); - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } } diff --git a/src/widgets/lv_slider.h b/src/widgets/lv_slider.h index 2cf44d4c1..c845c8923 100644 --- a/src/widgets/lv_slider.h +++ b/src/widgets/lv_slider.h @@ -51,6 +51,15 @@ typedef struct { extern const lv_obj_class_t lv_slider_class; +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_slider_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_SLIDER_DRAW_PART_KNOB, /**< The main (right) knob's rectangle*/ + LV_SLIDER_DRAW_PART_KNOB_LEFT, /**< The left knob's rectangle*/ +}lv_slider_draw_part_type_t; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/widgets/lv_table.c b/src/widgets/lv_table.c index 283540cf5..02e1da059 100644 --- a/src/widgets/lv_table.c +++ b/src/widgets/lv_table.c @@ -623,11 +623,13 @@ static void draw_main(lv_event_t * e) bool rtl = lv_obj_get_style_base_dir(obj, LV_PART_MAIN) == LV_BASE_DIR_RTL ? true : false; /*Handle custom drawer*/ - lv_obj_draw_part_dsc_t dsc; - lv_obj_draw_dsc_init(&dsc, clip_area); - dsc.part = LV_PART_ITEMS; - dsc.rect_dsc = &rect_dsc_act; - dsc.label_dsc = &label_dsc_act; + lv_obj_draw_part_dsc_t part_draw_dsc; + lv_obj_draw_dsc_init(&part_draw_dsc, clip_area); + part_draw_dsc.part = LV_PART_ITEMS; + part_draw_dsc.class_p = MY_CLASS; + part_draw_dsc.type = LV_TABLE_DRAW_PART_CELL; + part_draw_dsc.rect_dsc = &rect_dsc_act; + part_draw_dsc.label_dsc = &label_dsc_act; for(row = 0; row < table->row_cnt; row++) { lv_coord_t h_row = table->row_h[row]; @@ -718,9 +720,9 @@ static void draw_main(lv_event_t * e) obj->skip_trans = 0; } - dsc.draw_area = &cell_area_border; - dsc.id = row * table->col_cnt + col; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); + part_draw_dsc.draw_area = &cell_area_border; + part_draw_dsc.id = row * table->col_cnt + col; + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&cell_area_border, clip_area, &rect_dsc_act); @@ -753,7 +755,7 @@ static void draw_main(lv_event_t * e) } } - lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); cell += col_merge + 1; col += col_merge; diff --git a/src/widgets/lv_table.h b/src/widgets/lv_table.h index cd87e19b7..bd7611946 100644 --- a/src/widgets/lv_table.h +++ b/src/widgets/lv_table.h @@ -60,6 +60,14 @@ typedef struct { extern const lv_obj_class_t lv_table_class; +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_table_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_TABLE_DRAW_PART_CELL, /**< A cell*/ +}lv_table_draw_part_type_t; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/tests/defines.py b/tests/defines.py index b4179d16a..ab084d00a 100644 --- a/tests/defines.py +++ b/tests/defines.py @@ -5,6 +5,7 @@ minimal_monochrome = { "LV_DPI_DEF":40, "LV_DRAW_COMPLEX":0, + "LV_USE_METER":0, "LV_USE_LOG":1, @@ -34,6 +35,7 @@ minimal_16bit = { "LV_DPI_DEF":40, "LV_DRAW_COMPLEX":0, + "LV_USE_METER":0, "LV_USE_LOG":1,