For 3), the buttons can be styled by adding a style to LV_MSGBOX_PART_BTN
(after you call lv_msgbox_add_btns
), in a similar fashion to how you styled LV_MSGBOX_PART_BG
For 1) and 2), I don’t think you can mix font sizes within a label, but you can create additional labels on the msgbox (with the msgbox as parent), and break your output text between lv_msgbox_set_text
for the first line, and use your labels for other lines.
The symbol (and other text) can be recolored in the msgbox text by accessing the msgbox label and setting its recolor attribute to true (thanks to @embeddedt for the update). This code:
static lv_style_t style_msgbox;
lv_style_init(&style_msgbox);
lv_style_set_text_font(&style_msgbox, LV_STATE_DEFAULT, &lv_font_montserrat_20);
lv_style_set_text_color(&style_msgbox, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_bg_color(&style_msgbox, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
static lv_style_t style_buttons;
lv_style_init(&style_buttons);
lv_style_set_text_font(&style_buttons, LV_STATE_DEFAULT, &lv_font_montserrat_12);
lv_style_set_text_color(&style_buttons, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_style_set_bg_color(&style_buttons, LV_STATE_DEFAULT, LV_COLOR_GREEN);
static lv_style_t style_label;
lv_style_init(&style_label);
lv_style_set_text_font(&style_label, LV_STATE_DEFAULT, &lv_font_montserrat_16);
lv_style_set_text_color(&style_label, LV_STATE_DEFAULT, LV_COLOR_BLUE);
static const char * btns[] = {"Close", ""};
lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
lv_obj_set_event_cb(mbox1, event_handler);
lv_obj_t * label1 = lv_label_create(mbox1, NULL);
lv_msgbox_add_btns(mbox1, btns);
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_style(mbox1, LV_MSGBOX_PART_BG, &style_msgbox);
lv_obj_add_style(label1, LV_LABEL_PART_MAIN, &style_label);
lv_obj_add_style(mbox1, LV_MSGBOX_PART_BTN, &style_buttons);
//Access msgbox label and set it to enable recoloring
lv_obj_t * msgbox_label = ((lv_msgbox_ext_t *)lv_obj_get_ext_attr(mbox1))->text;
if(msgbox_label)
lv_label_set_recolor(msgbox_label, true);
lv_msgbox_set_text(mbox1, "#ff0000 " LV_SYMBOL_WARNING "# Setting value input error\n");
lv_label_set_text(label1, "There is no value. Please enter a value." );
produced this:
If you don’t wish to add additional labels, you can still use the recolor style formatting when calling lv_msgbox_set_text
to change the colors of parts of the text.