Roller - LV_ROLLER_MODE_NORMAL not working correctly in DOWN direction

When I press the Down button the Roller works until it reaches the minimum number and then it rolls back to the max number. If I scroll UP it will reach the max number and stop. I am using LV_ROLLER_MODE_NORMAL in the
lv_roller_set_options(roller1, opts, LV_ROLLER_MODE_NORMAL);

I’ve tried the code in the PC simulator and a NUCLEO-H7A3ZIQ board
I’m using LVGL version 8.3

I need the rollers to stop scrolling when they hit the last number in the string.

The code block(s) should be formatted like:

static void event_handlerCurrent(lv_event_t* e2)
{
    lv_event_code_t code = lv_event_get_code(e2);
    lv_obj_t* obj2 = (lv_obj_t*)lv_event_get_target(e2);
    if (code == LV_EVENT_VALUE_CHANGED) {
        char buf[20];
        lv_roller_get_selected_str(roller1, buf, sizeof(buf));
        LV_LOG_USER("Selected Current: %s\n", buf);
    }
}

static void button_down_event_handler(lv_event_t* e)
{
    lv_event_code_t code = lv_event_get_code(e);
    void* user_data = lv_event_get_user_data(e);
    if (code == LV_EVENT_CLICKED) {
        LV_LOG_USER("Clicked");
    }
    else if (code == LV_EVENT_VALUE_CHANGED) {
        LV_LOG_USER("Toggled");
    }
        lv_roller_set_selected(roller1, lv_roller_get_selected(roller1) - 1, LV_ANIM_ON)
    }

void lv_current_1ma_roller(void)
{
    roller1 = lv_roller_create(lv_scr_act());
    const char* opts = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10";
    lv_roller_set_options(roller1, opts, LV_ROLLER_MODE_NORMAL);
    lv_roller_set_visible_row_count(roller1, 5);
    lv_obj_align(roller1, LV_ALIGN_CENTER, -325, 0);
    lv_roller_set_selected(roller1, 4, LV_ANIM_OFF);
    lv_obj_add_event(roller1, event_handlerCurrent, LV_EVENT_ALL, NULL);
}

So, when I press the DOWN button the numbers scroll from the starting value of 5 to 1 like they should but If I press the down button one more time with the scroll at 1 it will loop around and 10 is now visible. Is this normal behavior? I am not using the INFINITE mode but teh NORMAL mode.

Thanks,
Richard

try dont do this simply and check end…

Marian,

Thanks for your input but how would I check for the end if I don’t use the
lv_roller_get_selected(roller1) - 1 command?

And why does the UP button not have the same problems? Here I use:
lv_roller_get_selected(roller1) +1.

Thanks,
Richard

Hi Richard, simply
0 - 1 = -1
any number + 1 is + num…

So, if I use something like this:
roller_selection = lv_roller_get_selected(roller1);
if(roller_selection != 0)
lv_roller_set_selected(roller1, lv_roller_get_selected(roller1) - 1, LV_ANIM_ON);

It seems to work. Now if I hit the DOWN button until #1 shows up it stays there. It won’t roll over back to +10.