mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
fix(dropdown) use LV_EVENT_READY/CANCEL on list open/close
Instead of LV_EVENT_VALUE_CHANGE to avoid conflicts with new option selection.
This commit is contained in:
parent
dae7039803
commit
4dd1d566fc
@ -30,10 +30,11 @@ The button goes to `LV_STATE_CHECKED` when its opened.
|
||||
- `LV_PART_SELECTED` Refers to the currently pressed, checked or pressed+checked option. Also uses the typical background properties.
|
||||
|
||||
As list does not exist when the drop-down list is closed it's not possible to simply add styles to it.
|
||||
Instead the following should be done:
|
||||
1. Ad an event handler to the button for `LV_EVENT_VALUE_CHANGED` (triggered when the list is opened/closed)
|
||||
2. Use `lv_obj_t * list = lv_dropdown_get_list(dropdown)`
|
||||
3. `if(list != NULL) {/*Add the styles to the list*/}`
|
||||
Insteada add an event handler to the button for `LV_EVENT_READY` (triggered when the list is opened) and add styles to the list in it like this:
|
||||
```c
|
||||
lv_obj_t * list = lv_dropdown_get_list(dropdown) /*Get the list*/
|
||||
lv_obj_add_style(list, &my_style, ...) /*Add the styles to the list*/}`
|
||||
```
|
||||
|
||||
Alternatively the theme can be extended with the new styles.
|
||||
|
||||
@ -76,6 +77,8 @@ To manually open or close the drop-down list the `lv_dropdown_open/close(dropdow
|
||||
## Events
|
||||
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.
|
||||
- `LV_EVENT_APPLY` Sent when the list is opened
|
||||
- `LV_EVENT_CANCEL` Sent when the list is closed
|
||||
|
||||
See the events of the [Base object](/widgets/obj) too.
|
||||
|
||||
|
@ -423,7 +423,7 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj)
|
||||
}
|
||||
|
||||
/*To allow styling the list*/
|
||||
lv_event_send(dropdown_obj, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_event_send(dropdown_obj, LV_EVENT_READY, NULL);
|
||||
|
||||
lv_obj_t * label = get_label(dropdown_obj);
|
||||
lv_label_set_text_static(label, dropdown->options);
|
||||
@ -521,7 +521,7 @@ void lv_dropdown_close(lv_obj_t * obj)
|
||||
dropdown->pr_opt_id = LV_DROPDOWN_PR_NONE;
|
||||
if(dropdown->list) lv_obj_del(dropdown->list);
|
||||
|
||||
lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_event_send(obj, LV_EVENT_CANCEL, NULL);
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
Loading…
x
Reference in New Issue
Block a user