
i want to stop scrolling beyond endpoint for example scrolling down removed january from selection area it should lock
Hi @isfandcielo,
To prevent scrolling beyond the content endpoints you have two main approaches:
lv_obj_scroll_by_bounded()
lv_obj_scroll_by_bounded(my_obj, 0, -20, LV_ANIM_ON);
- Use Snap Points to Lock Items in Place
lv_obj_set_scroll_snap_y(container, LV_SCROLL_SNAP_CENTER);
lv_obj_add_flag(container, LV_OBJ_FLAG_SCROLL_ONE);
lv_obj_add_flag(child_item, LV_OBJ_FLAG_SNAPPABLE);
i have tried these three option they don’t work my roller still get dragged when scrolled beyond end point but it does come back and to last value
I was looking for to not even scroll beyond end points
Blockquote
LV_DRAW_BUF_DEFINE_STATIC(mask, 130, 150, LV_COLOR_FORMAT_L8);
LV_DRAW_BUF_INIT_STATIC(mask);
lv_obj_t *roller
= lv_obj_find_by_name(lv_screen_active(), “temp_setpnt_roller”);
if(roller == NULL)
return;
// lv_obj_scroll_by_bounded(roller, 0, 0, LV_ANIM_OFF);
lv_obj_set_scroll_snap_y(roller, LV_SCROLL_SNAP_CENTER);
lv_obj_add_flag(roller, LV_OBJ_FLAG_SCROLL_ONE);
lv_obj_add_flag(roller, LV_OBJ_FLAG_SNAPPABLE);
also lvgl ui pro editor doesnot have these option so had to branch the code to make this happen
roller_test.zip (289.7 KB)
Hi @isfandcielo ,
Now I understand what happened: the roller isn’t used to scroll, but it’s intercepted by LV_EVENT_PRESSING. So, you need to add a handler for LV_EVENT_PRESSING and re-clamp the y-axis before any draw event.
static void roller_clamp_top_cb(lv_event_t * e)
{
lv_obj_t * roller = lv_event_get_current_target_obj(e);
lv_obj_t * label = lv_obj_get_child(roller, 0);
if(label == NULL) return;
const lv_font_t * font = lv_obj_get_style_text_font(roller, LV_PART_MAIN);
int32_t line_space = lv_obj_get_style_text_line_space(roller, LV_PART_MAIN);
int32_t font_h = lv_font_get_line_height(font);
int32_t content_h = lv_obj_get_content_height(roller);
int32_t mid_y1 = content_h / 2 - font_h / 2; /*label y for index 0*/
if(lv_obj_get_y_aligned(label) > mid_y1) {
lv_obj_set_y(label, mid_y1);
}
}
...
lv_obj_add_event_cb(roller1, roller_clamp_top_cb, LV_EVENT_PRESSING, NULL);