Scroll top to bottom of label with event up/down

Hi @kisvegabor , @embeddedt

Description

I want to display a text about 30k characters.
Then test with sample in Page (lv_page) — LVGL documentation
My screen cant not touch, just use event up/down which receive from spi transfer.

What LVGL version are you using?

LVGL 7.10.1

What do you want to achieve?

  1. How do I scroll text from beginning to the end or vice versa step by step when up-up-… or down-down-…?
  2. Can color, size of the scroll bar be changed?
  3. For long text, just set LV_LABEL_LONG_TXT_HINT to 1 in lv_conf.h, is it right?
    Do I need to do anything else?

Code to reproduce

void lv_ex_page_1(void)
{
    /*Create a page*/
    lv_obj_t * page = lv_page_create(lv_scr_act(), NULL);
    lv_obj_set_size(page, 150, 200);
    lv_obj_align(page, NULL, LV_ALIGN_CENTER, 0, 0);

    /*Create a label on the page*/
    lv_obj_t * label = lv_label_create(page, NULL);
    lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);            /*Automatically break long lines*/
    lv_obj_set_width(label, lv_page_get_width_fit(page));          /*Set the label width to max value to not show hor. scroll bars*/
    lv_label_set_text(label, "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n"
                             "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n"
                             "Ut enim ad minim veniam, quis nostrud exercitation ullamco\n"
                             "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure\n"
                             "dolor in reprehenderit in voluptate velit esse cillum dolore\n"
                             "eu fugiat nulla pariatur.\n"
                             "Excepteur sint occaecat cupidatat non proident, sunt in culpa\n"
                             "qui officia deserunt mollit anim id est laborum.");
}

If you add a the page to group, LV_KEY_UP/DOWN should do the job. Or you can use lv_page_scroll_ver(page, 20) to scrol lteh page manually.

See Page (lv_page) — LVGL documentation

That’s it :slight_smile:

Hi @kisvegabor

Thanks for your soon reply.
I still have a thought about scroll behavior,

When content(text in label) is scrolled in page, I saw the container of content was moved up from x(0) to x(-)
Position value of an object (here is container) is int16_t, It’s mean -32768 ~ +32768
If height of label is over 32768, for ex 35000, the scroll is in the middle of scrolling(-32768), it will be turned to 0 and move down(+1 ~ +32768).
If it is right, when reach -32768, how to continue scroll remaining content (-32768 ~ -35000)?

Hi @nguyenan-ble1,

I believe you need to change the lv_coord_t type in lv_conf.c to fix this.

Change:

/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */
typedef int16_t lv_coord_t;

To:

/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */
typedef int32_t lv_coord_t;

Hope that helps.

Kind Regards,

Pete

1 Like

Hi @pete-pjb

Thanks you, you’re so cool! :heart_eyes:

1 Like