LVGL9: Where is the lv_obj_set_pos anchor?

Hi guys,

Description

I do draw a custom model railway layout using lots of lv_lines. On the turnouts (consisting of two lines, one for straight one for the turn), I want to add text giving the turnout number.

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

Windows for testing and ESP32 for actual usage.

What LVGL version are you using?

9

What do you want to achieve?

I do calculate the bounding box of the lines and want to place a lv_label in the middle of it, but it is always a bit off.
I do all my calculations in screen space (so the full resolution, no other parent involved).

What have you tried so far?

auto lbl = lv_label_create(lvglScreenRailway);
lv_obj_set_pos(lbl, bounds.min.x + (bounds.max.x - bounds.min.x)/2 - 16, bounds.min.y + (bounds.max.y - bounds.min.y) / 2 - 16);
lv_obj_set_size(lbl, 32, 32);
        

of course I can try and play around with some offsets.
I am also open to do this in a different way… maybe a base object, adding the lines there and then centering the text inside? What are your recommendations?

Screenshot and/or video

Here is a small portion of what I mean: Orange are the lines (only the active one is visible). I want to have the label centered on the two lines.
image

Thanks
Daniel

So my solution for today is:
for this object placement:

        lv_obj_set_pos(button, bounds.min.x + (bounds.max.x - bounds.min.x)/2-16, bounds.min.y + (bounds.max.y - bounds.min.y) / 2-16);
        lv_obj_set_size(button, 32, 32);

I calculate the text height and pad from the top:

lv_point_t p;
lv_text_get_size(&p, "1234567890", &lv_font_montserrat_10, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_EXPAND);
lv_style_set_border_color(&lvglStyleTurnoutLabel, lv_palette_main(LV_PALETTE_DEEP_ORANGE));
lv_style_set_pad_top(&lvglStyleTurnoutLabel, 32/2 - ((p.y+1) / 2));

If you have a better plan, I am still curious. Or maybe, this will help others with the same issue :slight_smile: