Prevent a page from scrolling vertically (solved)

Description

When using a Page object, only allow horizontal scrolling

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

embedded linux using framebuffer.

What LVGL version are you using?

Master Git

What do you want to achieve?

I want to use a Page object to create a carousel effect. The page will have multiple objects consisting of an image and some text.

What have you tried so far?

Currently I am creating a Page object to fit across the screen and laying out a bunch of images.
Each image is 90x90 pixels and so extends outside the Page area.

By dragging I can slide any image into view which is what I am after, however even though each image is smaller than the page I can also scroll vertically which is not what I want.

I assume this can be done by using the lv_page_set_scrollable_fit() functions, but I can’t find anything that works.

Would either margins or padding be causing the vertical scrolling ?
Would it be better to use something other than a Page object ?
The List works nicely scrolling horizontally only, but I need more than a button/icon object.

Solved.

Slowly getting the hang of this library, although still get a bit confused with the styles and parts.

I created a style and set the top and bottom padding to 0 and set that style for the page object. That has stopped the vertical scrolling. The first object is aligned a bit high but the rest are fine, so not quite perfect but I am on the right track I think. Sorry for posting, hope it helps someone else.


Code to reproduce

void initPage(void)
{
   lv_obj_t * page = lv_page_create(lv_scr_act(), NULL);
   lv_obj_set_pos(page, 10, 175);
   lv_obj_set_size(page, 780, 100);

   for (int i = 0; i<20;i++) {
      lv_obj_t * img1 = lv_img_create(page, NULL);
      lv_img_set_src(img1, &tile);
      lv_obj_align(img1, page, LV_ALIGN_IN_LEFT_MID, i*90+5, 0);

      lv_obj_t * label1 = lv_label_create(img1, NULL);          /*Add a label to the button*/
      lv_obj_align(label1, img1, LV_ALIGN_IN_BOTTOM_MID, 0, -10);
      char buff[20];
      sprintf(buff,"tile %d",i);
      lv_label_set_text(label1, buff);

   }

}
1 Like