Change size of button on messagebox

Description

I have changed the font on a messagebox using lv_obj_set_style_text_font( _warningMessageBox, &ui_font_Robinson32, LV_PART_MAIN ); however, the button size do not change to accommodate the larger font and it is very cramped.
How can I set the size of a button (or buttons) on a messagebox?

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

Raspberry Pi 4

What LVGL version are you using?

Latest.

What do you want to achieve?

Manually set the button size on a messagebox.

What have you tried so far?

Nothing.

Hi again @AndyFraser,

Please see below expanding on your previous question:

void test() {

	static lv_obj_t 		*mb_test;
	static const char		*btns[] ={"Yes", "No", ""}; /*Button description.*/

	mb_test = lv_msgbox_create(NULL, "Test\n", "Test", btns, true);
	lv_obj_set_style_bg_color(mb_test, lv_palette_main(LV_PALETTE_BLUE_GREY), LV_PART_MAIN);

	lv_obj_t *btn = lv_msgbox_get_btns(mb_test);
    const lv_font_t * font = lv_obj_get_style_text_font(btn, LV_PART_ITEMS);
    lv_coord_t btn_h = lv_font_get_line_height(font) + 130 / 10;
    lv_obj_set_size(btn, 2/*2 buttons*/ * (2 * 130 / 3), btn_h);

}

This should give you a good fit based on the font size. I had a similar issue which in my case is related to my use of the #define LV_DPI_DEF 130 /*[px/inch]*/ which I set at a much lower value for my application to obtain different paddings in text areas etc… That is where the magic 130 comes from in my calculations if that makes sense…

Hope that helps.

Kind Regards,

Pete

1 Like

Thanks Pete, that is another great answer :slight_smile:
Works perfectly :+1:

Andy

1 Like