2016-12-29 07:10:49 +01:00
|
|
|
/**
|
|
|
|
* @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"
|
2017-01-06 13:39:13 +01:00
|
|
|
#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_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
|
|
|
|
**********************/
|
2016-12-29 23:48:01 +01:00
|
|
|
/**
|
|
|
|
* Initialize the Notifications
|
|
|
|
*/
|
2016-12-29 07:10:49 +01:00
|
|
|
void lv_app_notice_init(void)
|
|
|
|
{
|
2016-12-29 23:48:01 +01:00
|
|
|
lv_app_style_t * app_style = lv_app_style_get();
|
|
|
|
|
2016-12-29 07:10:49 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-12-29 23:48:01 +01:00
|
|
|
/**
|
|
|
|
* Add a notification with a given text
|
2017-01-06 13:39:13 +01:00
|
|
|
* @param format pritntf-like format string
|
2017-01-10 16:09:06 +01:00
|
|
|
* @return pointer the notice which is a message box (lv_mbox) object
|
2016-12-29 23:48:01 +01:00
|
|
|
*/
|
2017-01-10 16:09:06 +01:00
|
|
|
lv_obj_t * lv_app_notice_add(const char * format, ...)
|
2016-12-29 07:10:49 +01:00
|
|
|
{
|
2017-01-06 13:39:13 +01:00
|
|
|
char txt[LV_APP_NOTICE_MAX_LEN];
|
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
|
|
|
vsprintf(txt,format, va);
|
|
|
|
va_end(va);
|
|
|
|
|
2016-12-29 23:48:01 +01:00
|
|
|
lv_app_style_t * app_style = lv_app_style_get();
|
2016-12-29 07:10:49 +01:00
|
|
|
|
2017-01-10 16:09:06 +01:00
|
|
|
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, "");
|
2017-01-16 10:07:52 +01:00
|
|
|
lv_mbox_set_text(mbox, txt);
|
2017-01-10 16:09:06 +01:00
|
|
|
lv_obj_set_opa(mbox, app_style->menu_opa);
|
2016-12-29 07:10:49 +01:00
|
|
|
|
2017-01-10 16:09:06 +01:00
|
|
|
#if LV_APP_NOTICE_SHOW_TIME != 0
|
2017-01-16 12:41:21 +01:00
|
|
|
lv_mbox_start_auto_close(mbox, LV_APP_NOTICE_SHOW_TIME);
|
2017-01-10 16:09:06 +01:00
|
|
|
#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(¬ice_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());
|
|
|
|
|
2017-01-10 16:09:06 +01:00
|
|
|
return mbox;
|
2016-12-29 07:10:49 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
2016-12-29 23:48:01 +01:00
|
|
|
|
2016-12-29 07:10:49 +01:00
|
|
|
#endif
|