In LV_LABEL_LONG_WRAP mode, the height of label is not precise as it need

There are two label. In LV_LABEL_LONG_WRAP mode, the height of label will very large when only setting the width of label(for example label2). I think it is better when label2.get_height() is 20.

code in following, run in LVGL/MicroPython simulator

import lvgl as lv
import display_driver

label1 = lv.label(lv.scr_act())
label1.set_text("hello world1")
label1.set_size(150, 10)
label1.align(lv.ALIGN.CENTER, 0, -40)
print("label1 width: %d, height: %d" % (label1.get_width(), label1.get_height()))

label2 = lv.label(lv.scr_act())
label2.set_text("hello world2")
label2.align(lv.ALIGN.CENTER, 0, 0)
print("label2 width: %d, height: %d" % (label2.get_width(), label2.get_height()))

@ kisvegabor

Setting size of label before setting long mode, the label’s height not be auto wrapped. Is it a bug?



Instead of label1.refr_size() you should call label1.update_layout() to get force LVGL calculating the coordinates. This way the height is set to 16.

You can add this set a background for the label:

label1.set_style_bg_opa(255, 0)
label1.set_style_bg_color(lv.color_hex(0xff0000), 0)


So the label is large enough and it doesn’t need to wrapped.


If you can help.
I am interested in how to place a text within the lv_label that cannot fit in the length of the label?

When placing the text in the label, the text is in several lines, but due to the limited height, only two lines are visible.

Question, how to enable text scrolling up <–>down.

Function call: lv_label_set_long_mode(labelContent, LV_LABEL_LONG_SCROLL_CIRCULAR);
it moves the text left ↔ right, which doesn’t suit me at all.



You can try this:

    lv_obj_t * label1 = lv_label_create(lv_screen_active());
    lv_label_set_long_mode(label1, LV_LABEL_LONG_SCROLL_CIRCULAR);     /*Break the long lines*/
    lv_label_set_text(label1, "Line1\nLine2\nLine3\nLine4\nLine5");
    lv_obj_set_width(label1, 100); 
    lv_obj_set_height(label1, 30); 

This is a great solution.

Thank you very much