Scroll the label object


I have an object “Content” (as a container). I add a label “Label” to the container. The code is attached.
I use the external keys with which I want to scroll over the label. The “Content” is of fixed width and height.
The “Label” is of variable height. The button Handler function performs the movement of the label (lv_obj_scroll_by(Label, 0, 55, LV_ANIM_OFF); or (lv_obj_scroll_by(Label, 0, -55, LV_ANIM_OFF);

It is necessary to display a scroll if the text does not fit on the visible part of the “Label”.
It is necessary to disable scrolling up if we are at the beginning of the text, and disable scrolling down if we are at the end of the text.

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

ESP32-C3, ESP-IDF v5.0

What LVGL version are you using?


Content = lv_obj_create(ui_Screen);
lv_obj_set_style_text_font(content, &ui_Myfont, LV_PART_MAIN);
lv_obj_set_size(content, 240, 100);
lv_obj_set_style_bg_color(content, lv_color_hex(0xFFFFFF), LV_PART_MAIN);	
lv_obj_set_style_bg_opa(content, LV_OPA_100, LV_PART_MAIN);

Label = lv_label_create(Content);
lv_label_set_text(label, "... LONG TEXT ...");
lv_obj_set_size(labelContent, 240, 100);
lv_obj_set_align(labelContent, LV_ALIGN_BOTTOM_MID);
lv_obj_set_style_text_align(labelContent, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN);
lv_obj_set_scrollbar_mode(labelContent, LV_SCROLLBAR_MODE_AUTO);
lv_obj_set_style_text_line_space(labelContent, 3, LV_PART_MAIN);
lv_obj_set_style_text_color(labelContent, lv_color_hex(0x000000), LV_PART_MAIN);
lv_obj_set_scroll_dir(labelContent, LV_DIR_VER);

I mean you miss. Label isnt scrollable . Size for label need be content and container fixed and scrollable.

I used the LVGL ‘Message Box’ (LVGL v9.0) widget to create an object with the following functionality:
When the user selects ‘Help Btn’, a popup window opens that serves as additional explanation or some form of help for the object currently displayed on the screen

Appearance of such a window is shown in the picture:


The “Content” object contains the lv_label. The label has the following content:

lv_label_set_text(label, "First line\n"
					"Second line\n"
					"Third line\n"
					"Fourth line\n"
					"Fifth line\n"
					"Sixth line\n"
					"Seventh line\n");

I have three external buttons. With the UP/PREV key i need to move up,
with the DOWN/NEXT key i need to move down, and with the ENTER key I turn off the pop-up created screen.

How to limit scrolling up, if the first row is displayed?
How to limit the scroll down, if the last row is displayed?
How to display a vertical scroll line, and update its state depending on the current display of the label?

Each CLIK event is a shift of +/- 55px, because it is the height of one lines.

See the video.
Scroll Test - video

Thanks for your help

Try inspire here Flex — LVGL documentation

Video: Scroll Test - video

@kisvegabor can you help?
Thanks in advance.


Do you mean something like this?

  lv_obj_t * cont = lv_obj_create(lv_scr_act());
  lv_obj_set_size(cont, 150, 80);

  lv_obj_t * label = lv_label_create(cont);
  lv_obj_set_size(label, lv_pct(100), lv_pct(100));
  lv_label_set_text(label, "First line\n"
  					"Second line\n"
  					"Third line\n"
  					"Fourth line\n"
  					"Fifth line\n"
  					"Sixth line\n"
  					"Seventh line");
  lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL);

Thank you for your reply.

Only as many lines as the height of the label are visible on the label.
If there are multiple lines of text, then a scroll needs to be displayed on the label.

Scrolling is done manually, using the up/down keys.
Each key click moves the text by one line height.

Pseudo code: static void helpBtn_EventCb(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); if(code == BTN_PREV_CLICK) { lv_obj_scroll_by(labelContent, 0, 55, LV_ANIM_OFF); } else if(code == BTN_NEXT_CLICK) { lv_obj_scroll_by(labelContent, 0, -55, LV_ANIM_OFF); } }

Should limit scrolling up if the first line is displayed.
It should limit scrolling down if the last row is displayed.

I hope I managed to convey the necessary request: