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.