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.