[LVGL9.0] How to resize the message box to make it not fit it's content


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

PC simulation

What LVGL version are you using?


What do you want to achieve?

I want to create a fixed size of message box. However,I found the footer of message box will always be located at the bottom of mesaage box text.
for examle,I want to create a message box and its size is 300×200,and it has only few text to display. My message box has one button in its footer area. I want the button is aligned in the bottom of the message box whatever the height of text message .

What have you tried so far?

I tried to set the align of the footer to Bottom Middle,but it didnt work.

After adding a title and one or more buttons to the MsgBox,
configure the size of the MsgBox’s content.

    int32_t h_header = lv_obj_get_height(((lv_msgbox_t*) msgbox)->header);
    int32_t h_footer = lv_obj_get_height(((lv_msgbox_t*) msgbox)->footer);
    int32_t w_content = 300;
    int32_t h_content = 200 - h_header - h_footer;
    lv_obj_set_size(((lv_msgbox_t*) msgbox)->content, w_content, h_content);
    const INT32 margin = 50;
    int32_t msgBoxWidth = LV_HOR_RES - margin * 2;
    int32_t msgBoxHeight = LV_VER_RES - margin * 2;

    INT32 headerHeight = lv_obj_get_height(lv_msgbox_get_header(msgBox));
    INT32 footerHeight = lv_obj_get_height(lv_msgbox_get_header(msgBox));
    INT32 contentHeight = msgBoxHeight - headerHeight - footerHeight;
    lv_obj_set_size(lv_msgbox_get_content(msgBox), lv_pct(100), contentHeight);

    lv_obj_set_size(msgBox, msgBoxWidth, msgBoxHeight);
    lv_obj_align(msgBox, LV_ALIGN_CENTER, 0, 0);

The above code works for me. I still need to set the message box 's width. Otherwise, the content of message box will not be changed even I set its size to a fixed value.

However, this code will cause the message box will be scrollable. It looks the accumulated height exceeds the fixed message box size. Is there any way to change the layout of message box content to match its parent height ??

To make the message box not scrollable, I have to substract the content height by 5.
INT32 contentHeight = msgBoxHeight - headerHeight - footerHeight - 5;

Although this current works well, but I think the hardcoded “5” is not a good practice.
Is there any way to achieve this more gracefully ?

Learn more about flex_align and flex_flow,
and apply them to lv_msgbox_get_content(msgBox).

Learn more about remove obj’s flag LV_OBJ_FLAG_SCROLLABLE
and apply them to lv_msgbox_get_content(msgBox).