How Does Infinity Scroll work (roller)


What MCU/Processor/Board and compiler are you using?

I am building my own thing on linux with the lvgl libraries. To this point I am using just the simulator.

What LVGL version are you using?

Making a GUI.

What do you want to achieve?

Currently working on a Selectorbar. It should use the roller (Roller (lv_roller) — LVGL documentation) from lvgl and you can click threw it via two buttons (up&down).

What have you tried so far?

My new idea is to use a map (I am coding in C++) and look for an index in this map and then set its value to the roller options.

Problem is the infinity Scroll of the roller. How does it exactly work? Whenever I turn it on and navigate up / down threw the options, it jumps too far. I understand it this way: if the roller is infinite there are “pages” added to it so it seems to be infinite. You can see this in the roller.c/roller.h. I need the animation of the roller so the animation time is set to 1000ms. Thats why I see it jumping and scrolling over 3-4 options before it selects the wanted option. Can someone explain to me why it does that? And maybe help me with my map?

/You code here/

My Method to set the current value to the roller:

void BaseSelectorBar::setCurrentValue(int16_t index)
m_index = index;
int16_t max = m_map.size() - 1;

if(m_infinityScroll == true)
    //When infinityScroll enabled, 7 "Pages" are added to the roller-index

if(m_index == 0)
    lv_obj_clear_flag(m_imageButtonDown->getWidget(), LV_OBJ_FLAG_CLICKABLE);

else if(m_index == max)
    lv_obj_clear_flag(m_imageButtonUp->getWidget(), LV_OBJ_FLAG_CLICKABLE);

    lv_obj_add_flag(m_imageButtonUp->getWidget(), LV_OBJ_FLAG_CLICKABLE);
    lv_obj_add_flag(m_imageButtonDown->getWidget(), LV_OBJ_FLAG_CLICKABLE);
return lv_roller_set_selected(m_roller, index, LV_ANIM_ON);


The roller method:

if(roller->mode == LV_ROLLER_MODE_INFINITE)

int32_t sel_opt_signed = sel_opt;
uint16_t page = roller->sel_opt_id / LV_ROLLER_INF_PAGES;

/*sel_opt should be less than the number of options set by the user.
*If it’s more then probably it’s a reference from not the first page
so normalize sel_opt/
if(page != 0)

sel_opt_signed -= page * LV_ROLLER_INF_PAGES;

sel_opt = page * LV_ROLLER_INF_PAGES + sel_opt_signed;