Hello
I am new to LVGL and doing experiments with respect to scrolling in list widget environment. The aim is to get focus on a specific list entry if the list contents are bigger than active screen area. There is no physical input device that will be present in my application, so I will setup the focus programmatically always by using appropriate calls and states.
I have set up a list with buttons. Each button further has one label as its child.
I created a group and added each label as a member of the group with initialization like below.
grp = lv_group_create();
currentButton = lv_obj_get_child(list1, 0);
lab = lv_obj_get_child(currentButton, 0); // get the label corresponding to the current button
lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.type = LV_INDEV_TYPE_KEYPAD; /*See below.*/
indev_drv.read_cb = NULL; /*See below.*/
/*Register the driver in LVGL and save the created input device object*/
my_indev = lv_indev_drv_register(&indev_drv);
lv_indev_set_group(my_indev, grp);
The keyboard is provided as input above, even though I do not have actual physical input device, and I think I could keep that entry null if needed.
The group is populated with each label as below along with setting LV_OBJ_FLAG_SCROLL_ON_FOCUS on each label.
lab = lv_label_create(btn);
lv_label_set_text_fmt(lab, "%s", bookNames[i]);
lv_style_set_text_color(&style_label[i], lv_color_hex3(0x07E0)); // green color
lv_obj_add_style(lab, &style_label[i], 0);
lv_obj_add_flag(lab, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_group_add_obj(grp, lab);
Then I am setting up the focus manually with the call
currentButton = lv_obj_get_child(list1, 1);
lab = lv_obj_get_child(currentButton, 0); // get the label corresponding to current button
lv_refr_now(NULL);
lv_group_focus_obj(lab);
In the above setup earlier I had lv_refr_now(NULL) because I was also changing the color of the label text on focus to indicate its in focus.
I have created an array of 10 text names that are set as text of each of the 10 labels on each of the 10 buttons in a root list object. I am displaying these text names sequentially one below another where I see that in an active screen only 6 fit, so 4 are out of view. So the scroll bars appear vertically on side. So the aim is to move the focus between different labels to see it getting selected and auto scrolled with focus. (see picture for a reference)
The above setup is working to some extent but in a flawed manner, where what I am observing is
-
if I comment out the lv_refr_now(NULL) and only keep lv_group_focus_obj(lab); then the auto scroll stops.
-
If I change the sequence of the two calls to swap their positions with each other like below (compared to the code shown earlier)
lv_group_focus_obj(lab);
lv_refr_now(NULL);
Then no focus selection and scrolling happens. So basically nothing happens.
- If I try to introduce delay(time) in between two focus related sequence calls (as above code) to try to do some movement in scroll selection to see how it looks on screen, then the delay is introduced first and then the focus selection takes place, for example
call function where object is focused to do scrolling such that last object in the list is selected
introduce delay
call function where object is focused to do scrolling such that the first object in the list is selected
what is observed is there is no scrolling for the duration of delay, then scrolling happens to last object, then quickly the scrolling happens to the first object. So delay is not introduced in between two calls but delay is introduced first before scrolling takes place.
- From the original position below.
currentButton = lv_obj_get_child(list1, 1);
lab = lv_obj_get_child(currentButton, 0); // get the label corresponding to the current button
lv_refr_now(NULL);
lv_group_focus_obj(lab);
If I change the sequence to this, a weird behavior is observed between two calls where the first focus related scroll is ignored and only the second one is successful.
currentButton = lv_obj_get_child(list1, 1);
lab = lv_obj_get_child(currentButton, 0); // get the label corresponding to the current button
lv_group_focus_obj(lab);
lv_refr_now(NULL);
So these are some of the observations with the context. My expectation overall was if I am using lv_group_focus_obj(lab); to focus on an object the scrolling should happen automatically without the need to use lv_refr_now(NULL); but it seems that’s not happening.
So can you please let me know if I am using these api’s correctly in the correct seuquence with the right way? As I have managed to get this info from lots of different forum posts to do experiments to see whats working etc and not exactly sure if any thing is being broken in terms of usage here.
Any insights / feedback / help will be highly appreciated.
I am using LVGL 8.3 in ESP32-S3 environment in Arduino IDE. I do not want to disturb the setup by upgrading to a different version of LVGL.
I hope to have given sufficient information. If not please ask if you need any further info.
Thanks for your time and kindly excuse any mistakes as this is my first post here.
Regards
Mg