1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_app/lv_app_util/lv_app_notice.c

113 lines
2.5 KiB
C
Raw Normal View History

2016-12-29 07:10:49 +01:00
/**
* @file lv_app_notice.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_notice.h"
#if LV_APP_ENABLE != 0
2017-04-13 16:12:03 +02:00
#include <lvgl/lv_objx/lv_cont.h>
2016-12-29 07:10:49 +01:00
#include "lvgl/lv_objx/lv_label.h"
2017-04-21 09:15:39 +02:00
#include "misc/gfx/anim.h"
#include <stdio.h>
2016-12-29 07:10:49 +01:00
/*********************
* DEFINES
*********************/
2017-02-03 21:48:13 +01:00
/*Add the required configurations*/
#ifndef LV_APP_NOTICE_SHOW_TIME
#define LV_APP_NOTICE_SHOW_TIME 4000
#endif
#ifndef LV_APP_NOTICE_CLOSE_ANIM_TIME
#define LV_APP_NOTICE_CLOSE_ANIM_TIME 300
#endif
2017-02-03 21:48:13 +01:00
#ifndef LV_APP_NOTICE_MAX_NUM
#define LV_APP_NOTICE_MAX_NUM 6
#endif
#ifndef LV_APP_NOTICE_MAX_LEN
#define LV_APP_NOTICE_MAX_LEN 256
#endif
2016-12-29 07:10:49 +01:00
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_obj_t * notice_h;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the Notifications
*/
2016-12-29 07:10:49 +01:00
void lv_app_notice_init(void)
{
2017-04-13 16:12:03 +02:00
notice_h = lv_cont_create(lv_scr_act(), NULL);
2017-04-24 16:16:36 +02:00
lv_obj_set_size(notice_h, LV_HOR_RES, LV_VER_RES - LV_DPI / 8);
lv_obj_set_y(notice_h, LV_DPI / 8);
2016-12-29 07:10:49 +01:00
lv_obj_set_click(notice_h, false);
lv_obj_set_style(notice_h, lv_style_get(LV_STYLE_TRANSP, NULL));
2017-04-13 16:12:03 +02:00
lv_cont_set_layout(notice_h, LV_CONT_LAYOUT_COL_R);
2016-12-29 07:10:49 +01:00
}
/**
* 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, ...)
2016-12-29 07:10:49 +01:00
{
char txt[LV_APP_NOTICE_MAX_LEN];
va_list va;
va_start(va, format);
vsprintf(txt,format, va);
va_end(va);
lv_obj_t * mbox;
mbox = lv_mbox_create(notice_h, NULL);
// lv_obj_set_style(mbox, lv_mboxs_get(LV_MBOXS_INFO, NULL));
2017-01-16 10:07:52 +01:00
lv_mbox_set_text(mbox, txt);
2016-12-29 07:10:49 +01:00
#if LV_APP_NOTICE_SHOW_TIME != 0
lv_mbox_start_auto_close(mbox, LV_APP_NOTICE_SHOW_TIME, LV_APP_NOTICE_CLOSE_ANIM_TIME);
#endif
2016-12-29 07:10:49 +01:00
2017-02-03 21:48:13 +01:00
/*Delete the last children if there are too many*/
uint32_t child_num = lv_obj_get_child_num(notice_h);
if(child_num > LV_APP_NOTICE_MAX_NUM) {
lv_obj_t * last_child = ll_get_tail(&notice_h->child_ll);
lv_obj_del(last_child);
}
/*make sure the notices are on the top*/
2016-12-29 07:10:49 +01:00
lv_obj_set_parent(notice_h, lv_scr_act());
return mbox;
2016-12-29 07:10:49 +01:00
}
/**********************
* STATIC FUNCTIONS
**********************/
2016-12-29 07:10:49 +01:00
#endif