Lv_obj_align not working for OUT values

Description

Aligning a label with another label using any of the …OUT… enums does not appear to be working (for example LV_ALIGN_OUT_RIGHT_TOP). If I used any of the IN enums they do indeed work as expected. Am i doing something wrong?

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

Visual Studio simulation.

What do you want to achieve?

In my case alignment with the LV_ALIGN_OUT_RIGHT_TOP on its parent label, but none of the OUT enums appear to work. Label text is not shown!

What have you tried so far?

See below code

Code to reproduce

Here is a simplified version of my code which shows the problem

static void alignment_demo(lv_obj_t* parent)
{
	lv_obj_t* container = lv_cont_create(parent, NULL);
	lv_obj_align_origo(container, NULL, LV_ALIGN_CENTER, 0, 0);
	lv_cont_set_layout(container, LV_LAYOUT_COL_M);
	lv_cont_set_fit(container, LV_FIT_TIGHT);

	static lv_style_t bigFont;
	lv_style_copy(&bigFont, &lv_style_plain);
	bigFont.text.font = &lv_font_roboto_28;

	lv_obj_t* label1 = lv_label_create(container, NULL);
	lv_label_set_text(label1, "Hello World");
	lv_label_set_style(label1, LV_LABEL_STYLE_MAIN, &bigFont);

	lv_obj_t* label2 = lv_label_create(container, NULL);
	lv_label_set_text(label2, "==================================");

	lv_obj_t* label3 = lv_label_create(label1, NULL);
	lv_label_set_style(label3, LV_LABEL_STYLE_MAIN, &lv_style_plain);
	lv_label_set_text(label3, "!!!!");
	lv_obj_align(label3, NULL, LV_ALIGN_OUT_RIGHT_TOP, 0, 0);
	//lv_obj_realign(label3);
}

Screenshot and/or video

This is what I am getting:
image

This is what I was expecting to see. I know I could achieve similar by having another container which is horizontally aligned but I want, in this example, the text “Hello World” to be centred and the smaller font text “!!!” to be aligned to the top right.
image

If I change the alignment to be INternal (LV_ALIGN_IN_TOP_RIGHT) then it does as I would expect:
image

I have found the issue. Because I made the “!!!” label a parent of the “Hello World” label then I cannot use the OUT values as it is then trying to draw outside the area defined by the parent.

I then tried making “!!!” a parent of the container, but the Alignment values appear to be ignored when used in a container, which I guess makes sense.

So in the end I simply had to make it a parent of the active_screen. This is the working code for this example:

    static void alignment_demo(lv_obj_t* parent)
    {
    	lv_obj_t* container = lv_cont_create(parent, NULL);
    	lv_obj_align_origo(container, NULL, LV_ALIGN_CENTER, 0, 0);
    	lv_cont_set_layout(container, LV_LAYOUT_COL_M);
    	lv_cont_set_fit(container, LV_FIT_TIGHT);

    	static lv_style_t bigFont;
    	lv_style_copy(&bigFont, &lv_style_plain);
    	bigFont.text.font = &lv_font_roboto_28;

    	lv_obj_t* label1 = lv_label_create(container, NULL);
    	lv_label_set_text(label1, "Hello World");
    	lv_label_set_style(label1, LV_LABEL_STYLE_MAIN, &bigFont);

    	lv_obj_t* label2 = lv_label_create(container, NULL);
    	lv_label_set_text(label2, "==================================");

    	lv_obj_t* label3 = lv_label_create(lv_scr_act(), NULL);
    	lv_label_set_style(label3, LV_LABEL_STYLE_MAIN, &lv_style_plain);
    	lv_label_set_text(label3, "!!!!");
    	lv_obj_align(label3, label1, LV_ALIGN_OUT_RIGHT_TOP, 0, 0);
    }
1 Like