mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
lv_app_notice: build notices from lv_mbox
This commit is contained in:
parent
b98dca77e1
commit
6bde942abe
@ -1021,9 +1021,9 @@ static void lv_app_init_style(void)
|
||||
app_style.sc_page_style.bg_rects.hpad = 0;
|
||||
app_style.sc_page_style.bg_rects.opad = 0;
|
||||
app_style.sc_page_style.scrl_rects.objs.transp = 1;
|
||||
app_style.sc_page_style.scrl_rects.hpad = 20 * LV_DOWNSCALE;
|
||||
app_style.sc_page_style.scrl_rects.vpad = 20 * LV_DOWNSCALE;
|
||||
app_style.sc_page_style.scrl_rects.opad = 20 * LV_DOWNSCALE;
|
||||
app_style.sc_page_style.scrl_rects.hpad = 10 * LV_DOWNSCALE;
|
||||
app_style.sc_page_style.scrl_rects.vpad = 10 * LV_DOWNSCALE;
|
||||
app_style.sc_page_style.scrl_rects.opad = 15 * LV_DOWNSCALE;
|
||||
|
||||
/*Shortcut styles*/
|
||||
lv_btns_get(LV_BTNS_DEF,&app_style.sc_style);
|
||||
|
@ -26,16 +26,12 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_action_res_t notice_rel_action(lv_obj_t * n, lv_dispi_t * dispi);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_obj_t * notice_h;
|
||||
|
||||
static lv_btns_t notice_btns;
|
||||
static lv_labels_t notice_labels;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
@ -50,22 +46,6 @@ void lv_app_notice_init(void)
|
||||
{
|
||||
lv_app_style_t * app_style = lv_app_style_get();
|
||||
|
||||
memcpy(¬ice_btns, &app_style->menu_style, sizeof(lv_rects_t));
|
||||
notice_btns.rects.round = 5 * LV_DOWNSCALE;
|
||||
notice_btns.bcolor[LV_BTN_STATE_REL] = COLOR_WHITE;
|
||||
notice_btns.mcolor[LV_BTN_STATE_REL] = COLOR_BLACK;
|
||||
notice_btns.gcolor[LV_BTN_STATE_REL] = COLOR_BLACK;
|
||||
notice_btns.bcolor[LV_BTN_STATE_PR] = COLOR_WHITE;
|
||||
notice_btns.mcolor[LV_BTN_STATE_PR] = COLOR_GRAY;
|
||||
notice_btns.gcolor[LV_BTN_STATE_PR] = COLOR_GRAY;
|
||||
notice_btns.rects.bwidth = 1 * LV_DOWNSCALE;
|
||||
notice_btns.rects.bopa = 90;
|
||||
notice_btns.rects.light = 5 * LV_DOWNSCALE;
|
||||
|
||||
memcpy(¬ice_labels, &app_style->menu_btn_label_style, sizeof(lv_labels_t));
|
||||
notice_labels.mid = 0;
|
||||
notice_labels.font = LV_APP_FONT_MEDIUM;
|
||||
|
||||
notice_h = lv_rect_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size(notice_h, LV_HOR_RES, LV_VER_RES - app_style->menu_h);
|
||||
lv_obj_set_y(notice_h, app_style->menu_h);
|
||||
@ -77,8 +57,9 @@ void lv_app_notice_init(void)
|
||||
/**
|
||||
* Add a notification with a given text
|
||||
* @param format pritntf-like format string
|
||||
* @return pointer the notice which is a message box (lv_mbox) object
|
||||
*/
|
||||
void lv_app_notice_add(const char * format, ...)
|
||||
lv_obj_t * lv_app_notice_add(const char * format, ...)
|
||||
{
|
||||
char txt[LV_APP_NOTICE_MAX_LEN];
|
||||
|
||||
@ -89,77 +70,24 @@ void lv_app_notice_add(const char * format, ...)
|
||||
|
||||
lv_app_style_t * app_style = lv_app_style_get();
|
||||
|
||||
lv_obj_t * n;
|
||||
n = lv_btn_create(notice_h, NULL);
|
||||
lv_rect_set_fit(n, true, true);
|
||||
lv_obj_set_style(n, ¬ice_btns);
|
||||
lv_obj_set_opa(n, app_style->menu_opa);
|
||||
lv_btn_set_rel_action(n, notice_rel_action);
|
||||
|
||||
lv_obj_t * l;
|
||||
l = lv_label_create(n, NULL);
|
||||
lv_label_set_text(l, txt);
|
||||
lv_obj_set_style(l, ¬ice_labels);
|
||||
lv_obj_t * mbox;
|
||||
mbox = lv_mbox_create(notice_h, NULL);
|
||||
lv_obj_set_style(mbox, lv_mboxs_get(LV_MBOXS_INFO, NULL));
|
||||
lv_mbox_set_title(mbox, "");
|
||||
lv_mbox_set_txt(mbox, txt);
|
||||
lv_obj_set_opa(mbox, app_style->menu_opa);
|
||||
|
||||
#if LV_APP_NOTICE_SHOW_TIME != 0
|
||||
lv_mbox_auto_close(mbox, LV_APP_NOTICE_SHOW_TIME);
|
||||
#endif
|
||||
|
||||
lv_obj_set_parent(notice_h, lv_scr_act());
|
||||
|
||||
lv_rect_set_fit(n, false, false);
|
||||
#if LV_APP_EFFECT_ANIM != 0 && LV_APP_ANIM_NOTICE != 0
|
||||
anim_t a;
|
||||
a.var = n;
|
||||
a.path = anim_get_path(ANIM_PATH_LIN);
|
||||
a.time = LV_APP_ANIM_NOTICE;
|
||||
a.act_time = - LV_APP_NOTICE_SHOW_TIME;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
a.end_cb = NULL;
|
||||
#if LV_APP_EFFECT_OPA_ANIM != 0
|
||||
a.fp = (anim_fp_t) lv_obj_set_opar;
|
||||
a.start = lv_obj_get_opa(n);
|
||||
a.end = OPA_TRANSP;
|
||||
anim_create(&a);
|
||||
|
||||
/*Restore the label opacity because the opar anim changes it*/
|
||||
lv_obj_set_opa(l, OPA_COVER);
|
||||
|
||||
a.act_time = - LV_APP_NOTICE_SHOW_TIME - LV_APP_ANIM_NOTICE; /*Do the next animation after the opa animation*/
|
||||
#endif
|
||||
|
||||
a.fp = (anim_fp_t) lv_obj_set_height;
|
||||
a.start = lv_obj_get_height(n);
|
||||
a.end = 0;
|
||||
a.end_cb = (anim_cb_t)lv_obj_del;
|
||||
anim_create(&a);
|
||||
#else
|
||||
anim_t a;
|
||||
a.var = n;
|
||||
a.path = anim_get_path(ANIM_PATH_STEP);
|
||||
a.time = LV_APP_ANIM_NOTICE;
|
||||
a.act_time = - LV_APP_NOTICE_SHOW_TIME + LV_APP_ANIM_NOTICE;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
a.fp = (anim_fp_t) lv_obj_set_height;
|
||||
a.start = lv_obj_get_height(n);
|
||||
a.end = lv_obj_get_height(n);
|
||||
a.end_cb = lv_obj_del;
|
||||
anim_create(&a);
|
||||
#endif
|
||||
return mbox;
|
||||
|
||||
}
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static lv_action_res_t notice_rel_action(lv_obj_t * n, lv_dispi_t * dispi)
|
||||
{
|
||||
lv_obj_del(n);
|
||||
|
||||
return LV_ACTION_RES_INV;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -25,7 +25,7 @@
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_app_notice_init(void);
|
||||
void lv_app_notice_add(const char * format, ...);
|
||||
lv_obj_t * lv_app_notice_add(const char * format, ...);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
@ -311,7 +311,8 @@ static void sysmon_task(void * param)
|
||||
static bool mem_warn_report = false;
|
||||
if(mem_mon.size_free < LV_APP_SYSMON_MEM_WARN && mem_warn_report == false) {
|
||||
mem_warn_report = true;
|
||||
lv_app_notice_add("Critically low memory");
|
||||
lv_obj_t * not = lv_app_notice_add("Critically low memory");
|
||||
lv_obj_set_style(not, lv_mboxs_get(LV_MBOXS_WARN, NULL));
|
||||
}
|
||||
|
||||
if(mem_mon.size_free > LV_APP_SYSMON_MEM_WARN) mem_warn_report = false;
|
||||
@ -320,7 +321,9 @@ static void sysmon_task(void * param)
|
||||
if(mem_mon.pct_frag > LV_APP_SYSMON_FRAG_WARN) {
|
||||
if(frag_warn_report == false) {
|
||||
frag_warn_report = true;
|
||||
lv_app_notice_add("Critically memory fragmentation");
|
||||
lv_obj_t * not =lv_app_notice_add("Critical memory\nfragmentation");
|
||||
lv_obj_set_style(not, lv_mboxs_get(LV_MBOXS_WARN, NULL));
|
||||
|
||||
dm_defrag(); /*Defrag. if the fragmentation is critical*/
|
||||
}
|
||||
}
|
||||
|
@ -136,6 +136,12 @@
|
||||
/*Message box (dependencies: lv_rect, lv_btn, lv_label)*/
|
||||
#define USE_LV_MBOX 1
|
||||
|
||||
/*Message box (dependencies: lv_rect, lv_btn, lv_label)*/
|
||||
#define USE_LV_MBOX 1
|
||||
#if USE_LV_MBOX != 0
|
||||
#define LV_MBOX_ANIM_TIME 250 /*How fast animate out the message box in auto close. 0: no animation [ms]*/
|
||||
#endif
|
||||
|
||||
/*==================
|
||||
* LV APP SETTINGS
|
||||
* =================*/
|
||||
@ -175,7 +181,7 @@
|
||||
#define LV_APP_EFFECT_OPA_ANIM 1 /*Enable the using opacity in the application animations*/
|
||||
#define LV_APP_ANIM_WIN 200 /*Animation time in milliseconds (0: turn off animation)*/
|
||||
#define LV_APP_ANIM_SC 200 /*Animation time in milliseconds (0: turn off animation)*/
|
||||
#define LV_APP_ANIM_NOTICE 300 /*How fast animate out a notice [ms]*/
|
||||
#define LV_APP_ANIM_NOTICE 300 /*Obsolete, use LV_MBOX_ANIM. */
|
||||
|
||||
/* App. utility settings */
|
||||
#define LV_APP_NOTICE_SHOW_TIME 4000 /*Notices will be shown for this time [ms]*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user