How to disable roller scroll elastic and momentum?

What do you want to achieve?

I want to disable the scroll elastic and momentum of a roller widget

What have you tried so far?

As there are no such option under roller widget in Squareline Studio.
I have added some code (as below) to try to disable those function but seem no effect:

lv_obj_remove_flag(ui_Roller, LV_OBJ_FLAG_SCROLL_ELASTIC | LV_OBJ_FLAG_SCROLL_MOMENTUM);      /// Flags

Screenshot or video

Nope

Others

  • SquareLine Studio version: 1.5.0
  • Operating system: Windows 11
  • Target hardware: Renesas RA8 series

Hi, the issue is that you’re trying to apply the flags directly to the roller widget, but in LVGL, the roller has an internal scroll object that handles the scrolling behavior.

Try this approach instead:

lv_obj_t * roller_scrl = lv_roller_get_selected_obj(ui_Roller);
if(roller_scrl) {
    lv_obj_remove_flag(roller_scrl, LV_OBJ_FLAG_SCROLL_ELASTIC | LV_OBJ_FLAG_SCROLL_MOMENTUM);
}

This targets the internal scroll object of the roller rather than the roller widget itself.

If that doesn’t work, you could try using an event handler to modify the scrolling behavior when it begins:

static void roller_event_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    if(code == LV_EVENT_SCROLL_BEGIN) {
        lv_obj_t * roller = lv_event_get_target(e);
        lv_obj_t * scroller = lv_roller_get_selected_obj(roller);
        lv_obj_remove_flag(scroller, LV_OBJ_FLAG_SCROLL_ELASTIC | LV_OBJ_FLAG_SCROLL_MOMENTUM);
    }
}

// Add this event handler to your roller
lv_obj_add_event_cb(ui_Roller, roller_event_cb, LV_EVENT_ALL, NULL);

For newer LVGL versions (8.x+), you might also want to try:

lv_obj_set_scroll_snap_x(ui_Roller, LV_SCROLL_SNAP_CENTER);
lv_obj_set_scroll_mode(ui_Roller, LV_SCROLL_SNAP_ONE);

Hope this helps solve your issue!

1 Like