Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(event, widgets) improve the paramter of LV_EVENT_DRAW_PART_BEGIN…
…/END

Add lv_<widget>_draw_part_type_t to widgets to precisly describe the hooked drawings.
Also add class_p element to lv_obj_draw_part_dsc_t to show what widgets lv_<widget>_draw_part_type_t needs to be used.

Related to: https://forum.lvgl.io/t/how-to-add-minor-division-lines-to-a-chart/5366/
  • Loading branch information
kisvegabor committed Jul 7, 2021
1 parent f172eb3 commit 88c4859
Show file tree
Hide file tree
Showing 46 changed files with 723 additions and 360 deletions.
24 changes: 18 additions & 6 deletions docs/widgets/core/arc.md
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions docs/widgets/core/bar.md
Expand Up @@ -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).

Expand Down
4 changes: 2 additions & 2 deletions docs/widgets/core/btn.md
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions docs/widgets/core/btnmatrix.md
Expand Up @@ -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.

Expand Down
5 changes: 4 additions & 1 deletion docs/widgets/core/canvas.md
Expand Up @@ -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).

Expand Down
10 changes: 7 additions & 3 deletions docs/widgets/core/checkbox.md
Expand Up @@ -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).
Expand Down
2 changes: 2 additions & 0 deletions docs/widgets/core/dropdown.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/widgets/core/img.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/widgets/core/label.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/widgets/core/line.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/widgets/core/roller.md
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions docs/widgets/core/slider.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/widgets/core/switch.md
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions docs/widgets/core/table.md
Expand Up @@ -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 &times; 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 &times; col count + current column

See the events of the [Base object](/widgets/obj) too.

Learn more about [Events](/overview/event).

Expand Down
2 changes: 2 additions & 0 deletions docs/widgets/core/textarea.md
Expand Up @@ -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
Expand Down
50 changes: 40 additions & 10 deletions docs/widgets/extra/chart.md
Expand Up @@ -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).

Expand Down
9 changes: 8 additions & 1 deletion docs/widgets/extra/led.md
Expand Up @@ -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).

Expand Down
31 changes: 28 additions & 3 deletions docs/widgets/extra/meter.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/widgets/extra/spinbox.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/widgets/extra/spinner.md
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions docs/widgets/obj.md
Expand Up @@ -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).
Expand Down
8 changes: 5 additions & 3 deletions examples/widgets/chart/lv_example_chart_3.c
Expand Up @@ -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];
}
}

Expand Down

0 comments on commit 88c4859

Please sign in to comment.