mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
94 lines
2.0 KiB
C
94 lines
2.0 KiB
C
/**
|
|
* @file lv_app_notice.c
|
|
*
|
|
*/
|
|
|
|
/*********************
|
|
* INCLUDES
|
|
*********************/
|
|
#include "lv_app_notice.h"
|
|
#if LV_APP_ENABLE != 0
|
|
|
|
#include "lvgl/lv_objx/lv_rect.h"
|
|
#include "lvgl/lv_objx/lv_label.h"
|
|
|
|
#include "lvgl/lv_misc/anim.h"
|
|
#include <stdio.h>
|
|
|
|
/*********************
|
|
* DEFINES
|
|
*********************/
|
|
|
|
/**********************
|
|
* TYPEDEFS
|
|
**********************/
|
|
|
|
/**********************
|
|
* STATIC PROTOTYPES
|
|
**********************/
|
|
|
|
/**********************
|
|
* STATIC VARIABLES
|
|
**********************/
|
|
static lv_obj_t * notice_h;
|
|
|
|
/**********************
|
|
* MACROS
|
|
**********************/
|
|
|
|
/**********************
|
|
* GLOBAL FUNCTIONS
|
|
**********************/
|
|
/**
|
|
* Initialize the Notifications
|
|
*/
|
|
void lv_app_notice_init(void)
|
|
{
|
|
lv_app_style_t * app_style = lv_app_style_get();
|
|
|
|
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);
|
|
lv_obj_set_click(notice_h, false);
|
|
lv_obj_set_style(notice_h, lv_rects_get(LV_RECTS_TRANSP, NULL));
|
|
lv_rect_set_layout(notice_h, LV_RECT_LAYOUT_COL_R);
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
lv_obj_t * lv_app_notice_add(const char * format, ...)
|
|
{
|
|
char txt[LV_APP_NOTICE_MAX_LEN];
|
|
|
|
va_list va;
|
|
va_start(va, format);
|
|
vsprintf(txt,format, va);
|
|
va_end(va);
|
|
|
|
lv_app_style_t * app_style = lv_app_style_get();
|
|
|
|
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_text(mbox, txt);
|
|
lv_obj_set_opa(mbox, app_style->menu_opa);
|
|
|
|
#if LV_APP_NOTICE_SHOW_TIME != 0
|
|
lv_mbox_start_auto_close(mbox, LV_APP_NOTICE_SHOW_TIME);
|
|
#endif
|
|
|
|
lv_obj_set_parent(notice_h, lv_scr_act());
|
|
|
|
return mbox;
|
|
|
|
}
|
|
/**********************
|
|
* STATIC FUNCTIONS
|
|
**********************/
|
|
|
|
#endif
|