From 4dd1d566fc30bbaf1424dda8b78df97c6bf07402 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 28 Jul 2021 10:09:46 +0200 Subject: [PATCH] fix(dropdown) use LV_EVENT_READY/CANCEL on list open/close Instead of LV_EVENT_VALUE_CHANGE to avoid conflicts with new option selection. --- docs/widgets/core/dropdown.md | 11 +++++++---- src/widgets/lv_dropdown.c | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/widgets/core/dropdown.md b/docs/widgets/core/dropdown.md index f723f5a51..2cb5cce91 100644 --- a/docs/widgets/core/dropdown.md +++ b/docs/widgets/core/dropdown.md @@ -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. diff --git a/src/widgets/lv_dropdown.c b/src/widgets/lv_dropdown.c index 0eda800be..a1f781614 100644 --- a/src/widgets/lv_dropdown.c +++ b/src/widgets/lv_dropdown.c @@ -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); } /**********************