I want to use a long table as a menu in a window and want to add UP and DOWN buttons that will scroll the table a few rows at a time. Could not find functions to do so.
I also looked at the lv_list_up() and lv_list_down() but got a compile error similar to :
unresolved external symbol lv_list_up referenced in function
(in Visual studio simulator)
OK I can do it with
lv_obj_scroll_by(obj, x, y, LV_ANIM_ON/OFF)
Still this is not optimal because I have no idea what part of the list is visible so the user can get an empty window if scrolled the entire list out by repeatedly clicking on the same scroll button. Also the list can be in different length (sub menus etc.)
I can get the list size by using the LV_EVENT_GET_SELF_SIZE event on the list, but could not get the window or the window content size (height) with this event (got 0 or -24576 as y value )
Optimally I want to be able to set the y value dynamically (lv_obj_scroll_by(obj, x, y, LV_ANIM_ON/OFF))
so the list or part of it is always visible.
I recently had a similar issue. My program add’s new rows to a table, and I want to auto-scroll to keep the newest item in view.
I solved this by doing the following:
void Display_AutoScrollConsole(void)
{
lv_coord_t y = lv_obj_get_self_height(lv_right_consol);
//If the object content is big enough to scroll
if (y > lv_obj_get_height(lv_right_consol))
{
//Calculate the "out of view" y size
lv_coord_t outOfView = y - lv_obj_get_height(lv_right_consol);
lv_coord_t currScrollPos = lv_obj_get_scroll_y(lv_right_consol);
if(outOfView > currScrollPos)
{
//Calculate the difference between the required scroll pos and the current scroll pos
lv_coord_t differenceToScroll = - (outOfView - currScrollPos);
//this will bring the bottom of the table into view
lv_obj_scroll_by(lv_right_consol, 0, differenceToScroll, LV_ANIM_ON);
}
}
return;
}
You can also have a look at the following (from the official docs)
" The “scroll one” feature tells LVGL to allow scrolling only one snappable child at a time. So this requires to make the children snappable and set a scroll snap alignment different from LV_SCROLL_SNAP_NONE
.
This feature can be enabled by the LV_OBJ_FLAG_SCROLL_ONE
flag."
I haven’t tried this, but it would be cool to get it working.
Eeach obj actually has a coords struct that depicts its size (y2-y1) and position relative to parent (y1). from here it is easy to dynamically calculate the amount of scroll. Much as you wrote. Thanks