fix(msgbox) fix size settings

This commit is contained in:
Gabor Kiss-Vamosi
2021-05-13 17:27:09 +02:00
parent 052c3c9f3e
commit a2a65d48a5
3 changed files with 13 additions and 10 deletions

View File

@@ -140,7 +140,7 @@ bool lv_obj_refr_size(lv_obj_t * obj)
lv_coord_t minh = lv_obj_get_style_min_height(obj, LV_PART_MAIN);
lv_coord_t maxh = lv_obj_get_style_max_height(obj, LV_PART_MAIN);
h = lv_clamp_width(h, minh, maxh, parent_h);
h = lv_clamp_height(h, minh, maxh, parent_h);
}
/*calc_auto_size set the scroll x/y to 0 so revert the original value*/

View File

@@ -125,7 +125,7 @@ typedef struct {
#endif
#if LV_USE_MSGBOX
lv_style_t msgbox_btns_bg;
lv_style_t msgbox_bg, msgbox_btn_bg;
#endif
#if LV_USE_KEYBOARD
@@ -498,9 +498,12 @@ static void style_init(void)
#endif
#if LV_USE_MSGBOX
/*To add space for the buttons outline*/
style_init_reset(&styles->msgbox_btns_bg);
lv_style_set_pad_all(&styles->msgbox_btns_bg, OUTLINE_WIDTH);
/*To add space for for the button shadow*/
style_init_reset(&styles->msgbox_btn_bg);
lv_style_set_pad_all(&styles->msgbox_btn_bg, LV_DPX(4));
style_init_reset(&styles->msgbox_bg);
lv_style_set_max_width(&styles->msgbox_bg, lv_pct(100));
#endif
#if LV_USE_KEYBOARD
style_init_reset(&styles->keyboard_btn_bg);
@@ -668,7 +671,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
else if(lv_obj_check_type(obj, &lv_btnmatrix_class)) {
#if LV_USE_MSGBOX
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_msgbox_class)) {
lv_obj_add_style(obj, &styles->msgbox_btns_bg, 0);
lv_obj_add_style(obj, &styles->msgbox_btn_bg, 0);
lv_obj_add_style(obj, &styles->pad_gap, 0);
lv_obj_add_style(obj, &styles->btn, LV_PART_ITEMS);
lv_obj_add_style(obj, &styles->pressed, LV_PART_ITEMS | LV_STATE_PRESSED);
@@ -914,6 +917,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
#if LV_USE_MSGBOX
else if(lv_obj_check_type(obj, &lv_msgbox_class)) {
lv_obj_add_style(obj, &styles->card, 0);
lv_obj_add_style(obj, &styles->msgbox_bg, 0);
return;
}
#endif

View File

@@ -56,10 +56,8 @@ lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char *
if(mbox == NULL) return NULL;
if(auto_parent) lv_obj_add_flag(mbox, LV_MSGBOX_FLAG_AUTO_PARENT);
lv_coord_t w = lv_obj_get_content_width(parent);
if(w > 2 * LV_DPI_DEF) w = 2 * LV_DPI_DEF;
lv_obj_set_size(mbox, w, LV_SIZE_CONTENT);
lv_obj_set_size(mbox, LV_DPI_DEF * 2, LV_SIZE_CONTENT);
lv_obj_set_flex_flow(mbox, LV_FLEX_FLOW_ROW_WRAP);
lv_obj_set_flex_align(mbox, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START);
@@ -76,7 +74,8 @@ lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char *
lv_obj_add_event_cb(close_btn, msgbox_close_click_event_cb, LV_EVENT_CLICKED, NULL);
label = lv_label_create(close_btn);
lv_label_set_text(label, LV_SYMBOL_CLOSE);
lv_coord_t close_btn_size = LV_MAX(lv_obj_get_width(label), lv_obj_get_height(label)) + LV_DPX(10);
const lv_font_t * font = lv_obj_get_style_text_font(close_btn, LV_PART_MAIN);
lv_coord_t close_btn_size = lv_font_get_line_height(font) + LV_DPX(10);
lv_obj_set_size(close_btn, close_btn_size, close_btn_size);
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
}