Description
I want to make a multi-page drop-down list that is navigated with an encoder. Whenever an option is selected, the list should repopulate with a new set of options and reset the selected option to 0.
What MCU/Processor/Board and compiler are you using?
nRF52840
What LVGL version are you using?
8.2
What do you want to achieve?
I want the list to remain open and the widget to remain in edit mode (so the next set of options can be scrolled through and a second selection can be made) after the first selection is made. With the code below, the list repopulates and stays open after clicking on option 2 but turning the encoder afterwards changes to a different widget in the encoder group and closes the list instead of changing to a different selection in the list. The drop-down list seems to no longer be in an edit state.
What have you tried so far?
I’ve tried to manually add various states (checked and edited) to the drop-down after an event callback (LV_EVENT_RELEASED, LV_EVENT_VALUE_CHANGED, and LV_EVENT_CANCEL).
Code to reproduce
static void event_cb(lv_event_t *e) {
static bool load_next = false;
if (code == LV_EVENT_VALUE_CHANGED) {
if (lv_dropdown_get_selected(dd) == 2) { // TODO should only apply for first list
load_next = true;
}
}
else if (code == LV_EVENT_RELEASED) {
if (load_next == true) { // TODO else load original options
load_next = false;
lv_dropdown_set_options(dd, "F\n" "G\n" "H\n" "I\n" "J");
lv_dropdown_set_selected(dd, 0);
lv_dropdown_open(dd);
lv_obj_add_state(dd, LV_STATE_CHECKED);
lv_obj_add_state(dd, LV_STATE_EDITED);
}
}
}
...
void main(void)
{
dd = lv_dropdown_create(lv_scr_act());
lv_obj_align(dd, LV_ALIGN_CENTER, 0, 0);
lv_dropdown_set_options(dd, "A\n" "B\n" "C\n" "D\n" "E");
lv_obj_add_event_cb(dd, event_cb, LV_EVENT_ALL, NULL);
...
}
Screenshot and/or video
Sequence of encoder inputs in the video is click → right turn → right turn → click → right turn. The leaf is a fake cursor I added as a visual indicator for the group object the encoder is currently focused on.