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
https://sim.lvgl.io/v8.2/micropython/ports/javascript/index.html?script_startup=https://raw.githubusercontent.com/lvgl/lvgl/e19410f8f8a256609da72cff549598e0df6fa4cf/examples/header.py&script=https://raw.githubusercontent.com/lvgl/lvgl/e19410f8f8a256609da72cff549598e0df6fa4cf/examples/widgets/label/lv_example_label_1.py

import lvgl as lv
import display_driver

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

label2 = lv.label(lv.scr_act())
label2.set_long_mode(lv.label.LONG.WRAP)
label2.set_text("hello world2")
label2.set_width(150)
label2.align(lv.ALIGN.CENTER, 0, 0)
label2.refr_size()
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?

@kisvegabor

Hi,

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)

image

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

Hi.

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.

Tnx

Hey,

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