2016-12-16 07:41:34 +01:00
|
|
|
/**
|
|
|
|
* @file lv_mbox.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2016-12-16 07:41:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_mbox.h"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_MBOX != 0
|
2016-12-16 07:41:34 +01:00
|
|
|
|
2019-09-24 16:30:38 +02:00
|
|
|
#include "../lv_core/lv_debug.h"
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_group.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_anim.h"
|
|
|
|
#include "../lv_misc/lv_math.h"
|
2017-01-10 16:07:46 +01:00
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-09-26 10:51:54 +02:00
|
|
|
#define LV_OBJX_NAME "lv_mbos"
|
2017-11-27 17:48:54 +01:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2019-04-04 07:15:40 +02:00
|
|
|
#ifndef LV_MBOX_CLOSE_ANIM_TIME
|
|
|
|
#define LV_MBOX_CLOSE_ANIM_TIME 200 /*List close animation time) */
|
|
|
|
#endif
|
2017-11-27 17:48:54 +01:00
|
|
|
#else
|
2019-04-04 07:15:40 +02:00
|
|
|
#undef LV_MBOX_CLOSE_ANIM_TIME
|
|
|
|
#define LV_MBOX_CLOSE_ANIM_TIME 0 /*No animations*/
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2016-12-16 07:41:34 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2017-11-05 00:48:57 +01:00
|
|
|
static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param);
|
2018-06-19 09:49:58 +02:00
|
|
|
static void mbox_realign(lv_obj_t * mbox);
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-04-22 08:45:07 +02:00
|
|
|
static void lv_mbox_close_ready_cb(lv_anim_t * a);
|
2019-05-20 18:31:47 -07:00
|
|
|
#endif
|
2019-03-12 06:20:45 +01:00
|
|
|
static void lv_mbox_default_event_cb(lv_obj_t * mbox, lv_event_t event);
|
2019-07-05 14:46:53 -04:00
|
|
|
static void lv_mbox_btnm_event_cb(lv_obj_t * btnm, lv_event_t event);
|
2016-12-16 07:41:34 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t ancestor_signal;
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a message box objects
|
|
|
|
* @param par pointer to an object, it will be the parent of the new message box
|
2019-04-04 07:15:40 +02:00
|
|
|
* @param copy pointer to a message box object, if not NULL then the new object will be copied from
|
|
|
|
* it
|
2016-12-16 07:41:34 +01:00
|
|
|
* @return pointer to the created message box
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy)
|
2016-12-16 07:41:34 +01:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("mesasge box create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
/*Create the ancestor message box*/
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * new_mbox = lv_cont_create(par, copy);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(new_mbox);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(new_mbox == NULL) return NULL;
|
|
|
|
|
2019-04-10 06:40:49 +02:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_mbox);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
/*Allocate the message box type specific extended data*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_allocate_ext_attr(new_mbox, sizeof(lv_mbox_ext_t));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(ext == NULL) return NULL;
|
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
ext->text = NULL;
|
|
|
|
ext->btnm = NULL;
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-07 15:13:34 +01:00
|
|
|
ext->anim_time = LV_MBOX_CLOSE_ANIM_TIME;
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2016-12-16 07:41:34 +01:00
|
|
|
|
|
|
|
/*The signal and design functions are not copied so set them here*/
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(new_mbox, lv_mbox_signal);
|
2016-12-16 07:41:34 +01:00
|
|
|
|
|
|
|
/*Init the new message box message box*/
|
|
|
|
if(copy == NULL) {
|
2018-06-19 09:49:58 +02:00
|
|
|
ext->text = lv_label_create(new_mbox, NULL);
|
|
|
|
lv_label_set_align(ext->text, LV_LABEL_ALIGN_CENTER);
|
|
|
|
lv_label_set_long_mode(ext->text, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_label_set_text(ext->text, "Message");
|
2016-12-16 07:41:34 +01:00
|
|
|
|
2017-11-17 15:43:08 +01:00
|
|
|
lv_cont_set_layout(new_mbox, LV_LAYOUT_COL_M);
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_cont_set_fit2(new_mbox, LV_FIT_NONE, LV_FIT_TIGHT);
|
2019-02-07 19:17:10 +01:00
|
|
|
lv_obj_set_width(new_mbox, LV_DPI * 2);
|
2017-11-16 15:32:33 +01:00
|
|
|
lv_obj_align(new_mbox, NULL, LV_ALIGN_CENTER, 0, 0);
|
2019-03-12 06:20:45 +01:00
|
|
|
lv_obj_set_event_cb(new_mbox, lv_mbox_default_event_cb);
|
2017-11-16 15:32:33 +01:00
|
|
|
|
|
|
|
/*Set the default styles*/
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_theme_t * th = lv_theme_get_current();
|
|
|
|
if(th) {
|
2019-02-11 09:35:06 +01:00
|
|
|
lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, th->style.mbox.bg);
|
2018-06-19 09:49:58 +02:00
|
|
|
} else {
|
|
|
|
lv_mbox_set_style(new_mbox, LV_MBOX_STYLE_BG, &lv_style_pretty);
|
|
|
|
}
|
2016-12-16 07:41:34 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
/*Copy an existing message box*/
|
|
|
|
else {
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_mbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2017-01-17 00:49:16 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
ext->text = lv_label_create(new_mbox, copy_ext->text);
|
2017-01-02 14:10:32 +01:00
|
|
|
|
2017-01-10 16:07:46 +01:00
|
|
|
/*Copy the buttons and the label on them*/
|
2017-11-15 15:50:33 +01:00
|
|
|
if(copy_ext->btnm) ext->btnm = lv_btnm_create(new_mbox, copy_ext->btnm);
|
2017-11-08 11:07:29 +01:00
|
|
|
|
2017-01-08 13:06:41 +01:00
|
|
|
/*Refresh the style with new signal function*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_refresh_style(new_mbox);
|
2016-12-16 07:41:34 +01:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("mesasge box created");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
return new_mbox;
|
|
|
|
}
|
|
|
|
|
2017-11-17 15:43:08 +01:00
|
|
|
/*======================
|
|
|
|
* Add/remove functions
|
|
|
|
*=====================*/
|
|
|
|
|
2017-01-16 10:07:52 +01:00
|
|
|
/**
|
2017-11-17 15:43:08 +01:00
|
|
|
* Add button to the message box
|
2016-12-16 07:41:34 +01:00
|
|
|
* @param mbox pointer to message box object
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param btn_map button descriptor (button matrix map).
|
|
|
|
* E.g. a const char *txt[] = {"ok", "close", ""} (Can not be local variable)
|
2016-12-16 07:41:34 +01:00
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
void lv_mbox_add_btns(lv_obj_t * mbox, const char ** btn_map)
|
2016-12-16 07:41:34 +01:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2016-12-16 07:41:34 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/*Create a button matrix if not exists yet*/
|
|
|
|
if(ext->btnm == NULL) {
|
|
|
|
ext->btnm = lv_btnm_create(mbox, NULL);
|
2017-11-16 15:32:33 +01:00
|
|
|
|
|
|
|
/*Set the default styles*/
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_theme_t * th = lv_theme_get_current();
|
|
|
|
if(th) {
|
2019-02-11 09:35:06 +01:00
|
|
|
lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_BG, th->style.mbox.btn.bg);
|
|
|
|
lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_REL, th->style.mbox.btn.rel);
|
|
|
|
lv_mbox_set_style(mbox, LV_MBOX_STYLE_BTN_PR, th->style.mbox.btn.pr);
|
2018-06-19 09:49:58 +02:00
|
|
|
} else {
|
|
|
|
lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BG, &lv_style_transp_fit);
|
|
|
|
}
|
2017-04-13 10:20:35 +02:00
|
|
|
}
|
2017-01-17 00:49:16 +01:00
|
|
|
|
2019-04-10 08:40:52 +02:00
|
|
|
lv_btnm_set_map(ext->btnm, btn_map);
|
2019-06-17 16:05:30 +02:00
|
|
|
lv_btnm_set_btn_ctrl_all(ext->btnm, LV_BTNM_CTRL_CLICK_TRIG | LV_BTNM_CTRL_NO_REPEAT);
|
2019-07-05 14:46:53 -04:00
|
|
|
lv_obj_set_event_cb(ext->btnm, lv_mbox_btnm_event_cb);
|
2017-11-08 11:07:29 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
mbox_realign(mbox);
|
2016-12-16 07:41:34 +01:00
|
|
|
}
|
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
/**
|
2017-04-13 10:20:35 +02:00
|
|
|
* Set the text of the message box
|
|
|
|
* @param mbox pointer to a message box
|
|
|
|
* @param txt a '\0' terminated character string which will be the message box text
|
2016-12-16 07:41:34 +01:00
|
|
|
*/
|
2017-04-13 10:20:35 +02:00
|
|
|
void lv_mbox_set_text(lv_obj_t * mbox, const char * txt)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_label_set_text(ext->text, txt);
|
2017-11-07 16:18:38 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
mbox_realign(mbox);
|
2017-11-08 11:07:29 +01:00
|
|
|
}
|
|
|
|
|
2017-05-08 10:09:41 +02:00
|
|
|
/**
|
2017-11-07 15:13:34 +01:00
|
|
|
* Set animation duration
|
2017-05-08 10:09:41 +02:00
|
|
|
* @param mbox pointer to a message box object
|
2018-03-01 12:21:49 +01:00
|
|
|
* @param anim_time animation length in milliseconds (0: no animation)
|
2017-05-08 10:09:41 +02:00
|
|
|
*/
|
2018-03-01 12:21:49 +01:00
|
|
|
void lv_mbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time)
|
2017-05-08 10:09:41 +02:00
|
|
|
{
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2019-06-06 06:05:40 +02:00
|
|
|
anim_time = 0;
|
|
|
|
ext->anim_time = anim_time;
|
2019-05-20 09:22:09 -07:00
|
|
|
#else
|
2019-06-06 06:05:40 +02:00
|
|
|
(void)mbox;
|
|
|
|
(void)anim_time;
|
2019-05-20 09:22:09 -07:00
|
|
|
#endif
|
2017-05-08 10:09:41 +02:00
|
|
|
}
|
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
/**
|
|
|
|
* Automatically delete the message box after a given time
|
|
|
|
* @param mbox pointer to a message box object
|
2017-11-07 15:13:34 +01:00
|
|
|
* @param delay a time (in milliseconds) to wait before delete the message box
|
2016-12-16 07:41:34 +01:00
|
|
|
*/
|
2017-11-07 15:13:34 +01:00
|
|
|
void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay)
|
2016-12-16 07:41:34 +01:00
|
|
|
{
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2019-05-20 09:22:09 -07:00
|
|
|
if(lv_mbox_get_anim_time(mbox) != 0) {
|
2017-05-02 00:16:48 +02:00
|
|
|
/*Add shrinking animations*/
|
2019-05-07 06:30:38 +02:00
|
|
|
lv_anim_t a;
|
2019-06-06 06:05:40 +02:00
|
|
|
a.var = mbox;
|
|
|
|
a.start = lv_obj_get_height(mbox);
|
|
|
|
a.end = 0;
|
2019-06-12 23:10:54 +02:00
|
|
|
a.exec_cb = (lv_anim_exec_xcb_t)lv_obj_set_height;
|
2019-06-06 06:05:40 +02:00
|
|
|
a.path_cb = lv_anim_path_linear;
|
|
|
|
a.ready_cb = NULL;
|
|
|
|
a.act_time = -delay;
|
|
|
|
a.time = lv_mbox_get_anim_time(mbox);
|
|
|
|
a.playback = 0;
|
2019-05-07 06:30:38 +02:00
|
|
|
a.playback_pause = 0;
|
2019-06-06 06:05:40 +02:00
|
|
|
a.repeat = 0;
|
|
|
|
a.repeat_pause = 0;
|
2019-05-07 06:30:38 +02:00
|
|
|
lv_anim_create(&a);
|
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
a.start = lv_obj_get_width(mbox);
|
2019-06-12 23:10:54 +02:00
|
|
|
a.exec_cb = (lv_anim_exec_xcb_t)lv_obj_set_width;
|
2019-05-07 06:30:38 +02:00
|
|
|
a.ready_cb = lv_mbox_close_ready_cb;
|
|
|
|
lv_anim_create(&a);
|
2017-05-02 00:16:48 +02:00
|
|
|
|
2017-11-07 15:13:34 +01:00
|
|
|
/*Disable fit to let shrinking work*/
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_cont_set_fit(mbox, LV_FIT_NONE);
|
2017-05-02 00:16:48 +02:00
|
|
|
} else {
|
2019-05-07 06:30:38 +02:00
|
|
|
/*Create an animation to delete the mbox `delay` ms later*/
|
|
|
|
lv_anim_t a;
|
2019-06-06 06:05:40 +02:00
|
|
|
a.var = mbox;
|
|
|
|
a.start = 0;
|
|
|
|
a.end = 1;
|
2019-06-12 23:10:54 +02:00
|
|
|
a.exec_cb = (lv_anim_exec_xcb_t)NULL;
|
2019-06-06 06:05:40 +02:00
|
|
|
a.path_cb = lv_anim_path_linear;
|
|
|
|
a.ready_cb = lv_mbox_close_ready_cb;
|
|
|
|
a.act_time = -delay;
|
|
|
|
a.time = 0;
|
|
|
|
a.playback = 0;
|
2019-05-07 06:30:38 +02:00
|
|
|
a.playback_pause = 0;
|
2019-06-06 06:05:40 +02:00
|
|
|
a.repeat = 0;
|
|
|
|
a.repeat_pause = 0;
|
2019-05-07 06:30:38 +02:00
|
|
|
lv_anim_create(&a);
|
2017-05-02 00:16:48 +02:00
|
|
|
}
|
2017-11-27 17:48:54 +01:00
|
|
|
#else
|
2018-10-09 15:03:46 +02:00
|
|
|
(void)delay; /*Unused*/
|
2017-11-27 17:48:54 +01:00
|
|
|
lv_obj_del(mbox);
|
|
|
|
#endif
|
2016-12-16 07:41:34 +01:00
|
|
|
}
|
|
|
|
|
2017-01-16 12:41:21 +01:00
|
|
|
/**
|
|
|
|
* Stop the auto. closing of message box
|
|
|
|
* @param mbox pointer to a message box object
|
|
|
|
*/
|
|
|
|
void lv_mbox_stop_auto_close(lv_obj_t * mbox)
|
|
|
|
{
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_anim_del(mbox, NULL);
|
2018-10-09 15:03:46 +02:00
|
|
|
#else
|
|
|
|
(void)mbox; /*Unused*/
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-01-16 12:41:21 +01:00
|
|
|
}
|
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Set a style of a message box
|
2017-11-10 15:01:40 +01:00
|
|
|
* @param mbox pointer to a message box object
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param type which style should be set
|
|
|
|
* @param style pointer to a style
|
2017-11-10 15:01:40 +01:00
|
|
|
*/
|
2019-04-11 19:59:55 +08:00
|
|
|
void lv_mbox_set_style(lv_obj_t * mbox, lv_mbox_style_t type, const lv_style_t * style)
|
2017-11-10 15:01:40 +01:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
switch(type) {
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_MBOX_STYLE_BG: lv_obj_set_style(mbox, style); break;
|
|
|
|
case LV_MBOX_STYLE_BTN_BG: lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BG, style); break;
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_MBOX_STYLE_BTN_REL: lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_REL, style); break;
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_MBOX_STYLE_BTN_PR: lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_PR, style); break;
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_MBOX_STYLE_BTN_TGL_REL: lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_REL, style); break;
|
|
|
|
case LV_MBOX_STYLE_BTN_TGL_PR: lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_PR, style); break;
|
|
|
|
case LV_MBOX_STYLE_BTN_INA: lv_btnm_set_style(ext->btnm, LV_BTNM_STYLE_BTN_INA, style); break;
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
|
2018-10-17 11:27:08 +02:00
|
|
|
mbox_realign(mbox);
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 09:33:10 -05:00
|
|
|
/**
|
|
|
|
* Set whether recoloring is enabled
|
|
|
|
* @param btnm pointer to button matrix object
|
|
|
|
* @param en whether recoloring is enabled
|
|
|
|
*/
|
|
|
|
void lv_mbox_set_recolor(lv_obj_t * mbox, bool en)
|
|
|
|
{
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2018-12-16 09:33:10 -05:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->btnm) lv_btnm_set_recolor(ext->btnm, en);
|
2018-12-16 09:33:10 -05:00
|
|
|
}
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the text of the message box
|
|
|
|
* @param mbox pointer to a message box object
|
|
|
|
* @return pointer to the text of the message box
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
const char * lv_mbox_get_text(const lv_obj_t * mbox)
|
2016-12-16 07:41:34 +01:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2016-12-16 07:41:34 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
return lv_label_get_text(ext->text);
|
2017-11-08 11:07:29 +01:00
|
|
|
}
|
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
/**
|
2019-03-12 06:20:45 +01:00
|
|
|
* Get the index of the lastly "activated" button by the user (pressed, released etc)
|
|
|
|
* Useful in the the `event_cb`.
|
|
|
|
* @param btnm pointer to button matrix object
|
|
|
|
* @return index of the last released button (LV_BTNM_BTN_NONE: if unset)
|
2016-12-16 07:41:34 +01:00
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
uint16_t lv_mbox_get_active_btn(lv_obj_t * mbox)
|
2016-12-16 07:41:34 +01:00
|
|
|
{
|
2019-03-12 06:20:45 +01:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->btnm)
|
|
|
|
return lv_btnm_get_active_btn(ext->btnm);
|
|
|
|
else
|
|
|
|
return LV_BTNM_BTN_NONE;
|
2019-03-12 06:20:45 +01:00
|
|
|
}
|
2016-12-16 07:41:34 +01:00
|
|
|
|
2019-03-12 06:20:45 +01:00
|
|
|
/**
|
|
|
|
* Get the text of the lastly "activated" button by the user (pressed, released etc)
|
|
|
|
* Useful in the the `event_cb`.
|
|
|
|
* @param btnm pointer to button matrix object
|
|
|
|
* @return text of the last released button (NULL: if unset)
|
|
|
|
*/
|
|
|
|
const char * lv_mbox_get_active_btn_text(lv_obj_t * mbox)
|
|
|
|
{
|
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2019-04-04 07:15:40 +02:00
|
|
|
if(ext->btnm)
|
|
|
|
return lv_btnm_get_active_btn_text(ext->btnm);
|
|
|
|
else
|
|
|
|
return NULL;
|
2016-12-16 07:41:34 +01:00
|
|
|
}
|
|
|
|
|
2017-05-08 10:09:41 +02:00
|
|
|
/**
|
2017-11-07 15:13:34 +01:00
|
|
|
* Get the animation duration (close animation time)
|
2017-05-08 10:09:41 +02:00
|
|
|
* @param mbox pointer to a message box object
|
|
|
|
* @return animation length in milliseconds (0: no animation)
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
uint16_t lv_mbox_get_anim_time(const lv_obj_t * mbox)
|
2017-05-08 10:09:41 +02:00
|
|
|
{
|
2019-05-20 09:22:09 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2017-11-07 15:13:34 +01:00
|
|
|
return ext->anim_time;
|
2019-05-20 09:22:09 -07:00
|
|
|
#else
|
2019-06-06 06:05:40 +02:00
|
|
|
(void)mbox;
|
2019-05-20 09:22:09 -07:00
|
|
|
return 0;
|
|
|
|
#endif
|
2017-05-08 10:09:41 +02:00
|
|
|
}
|
2017-11-07 15:13:34 +01:00
|
|
|
|
2017-11-08 11:07:29 +01:00
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Get a style of a message box
|
2017-11-08 11:07:29 +01:00
|
|
|
* @param mbox pointer to a message box object
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param type which style should be get
|
|
|
|
* @return style pointer to a style
|
2017-11-08 11:07:29 +01:00
|
|
|
*/
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * lv_mbox_get_style(const lv_obj_t * mbox, lv_mbox_style_t type)
|
2017-11-08 11:07:29 +01:00
|
|
|
{
|
2019-06-06 06:05:40 +02:00
|
|
|
const lv_style_t * style = NULL;
|
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
|
|
|
switch(type) {
|
2019-04-04 07:15:40 +02:00
|
|
|
case LV_MBOX_STYLE_BG: style = lv_obj_get_style(mbox); break;
|
|
|
|
case LV_MBOX_STYLE_BTN_BG: style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BG); break;
|
2019-06-06 06:05:40 +02:00
|
|
|
case LV_MBOX_STYLE_BTN_REL: style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_REL); break;
|
|
|
|
case LV_MBOX_STYLE_BTN_PR: style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_PR); break;
|
|
|
|
case LV_MBOX_STYLE_BTN_TGL_REL: style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_REL); break;
|
|
|
|
case LV_MBOX_STYLE_BTN_TGL_PR: style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_TGL_PR); break;
|
|
|
|
case LV_MBOX_STYLE_BTN_INA: style = lv_btnm_get_style(ext->btnm, LV_BTNM_STYLE_BTN_INA); break;
|
2019-04-04 07:15:40 +02:00
|
|
|
default: style = NULL; break;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
2016-12-16 07:41:34 +01:00
|
|
|
|
2018-11-05 22:21:20 -06:00
|
|
|
return style;
|
2017-04-13 10:20:35 +02:00
|
|
|
}
|
2016-12-16 07:41:34 +01:00
|
|
|
|
2018-12-16 09:33:10 -05:00
|
|
|
/**
|
|
|
|
* Get whether recoloring is enabled
|
2019-02-28 09:08:53 +01:00
|
|
|
* @param mbox pointer to a message box object
|
2018-12-16 09:33:10 -05:00
|
|
|
* @return whether recoloring is enabled
|
|
|
|
*/
|
|
|
|
bool lv_mbox_get_recolor(const lv_obj_t * mbox)
|
|
|
|
{
|
2019-02-28 09:09:58 +01:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
2018-12-16 09:33:10 -05:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
if(!ext->btnm) return false;
|
2018-12-16 09:33:10 -05:00
|
|
|
|
2019-02-28 09:09:58 +01:00
|
|
|
return lv_btnm_get_recolor(ext->btnm);
|
2018-12-16 09:33:10 -05:00
|
|
|
}
|
|
|
|
|
2019-02-28 09:07:07 +01:00
|
|
|
/**
|
|
|
|
* Get message box button matrix
|
|
|
|
* @param mbox pointer to a message box object
|
|
|
|
* @return pointer to button matrix object
|
|
|
|
* @remarks return value will be NULL unless `lv_mbox_add_btns` has been already called
|
|
|
|
*/
|
|
|
|
lv_obj_t * lv_mbox_get_btnm(lv_obj_t * mbox)
|
|
|
|
{
|
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
|
|
|
return ext->btnm;
|
2018-12-16 09:33:10 -05:00
|
|
|
}
|
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
2017-11-05 00:48:57 +01:00
|
|
|
* Signal function of the message box
|
|
|
|
* @param mbox pointer to a message box object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
2016-12-16 07:41:34 +01:00
|
|
|
*/
|
2017-11-05 00:48:57 +01:00
|
|
|
static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
|
2016-12-16 07:41:34 +01:00
|
|
|
{
|
2017-11-05 00:48:57 +01:00
|
|
|
lv_res_t res;
|
2016-12-16 07:41:34 +01:00
|
|
|
|
2019-04-08 14:36:20 +02:00
|
|
|
/*Translate LV_KEY_UP/DOWN to LV_KEY_LEFT/RIGHT */
|
2018-03-21 13:15:02 +01:00
|
|
|
char c_trans = 0;
|
2019-03-19 07:15:00 +01:00
|
|
|
if(sign == LV_SIGNAL_CONTROL) {
|
2018-06-19 09:49:58 +02:00
|
|
|
c_trans = *((char *)param);
|
2019-04-08 14:36:20 +02:00
|
|
|
if(c_trans == LV_KEY_DOWN) c_trans = LV_KEY_LEFT;
|
|
|
|
if(c_trans == LV_KEY_UP) c_trans = LV_KEY_RIGHT;
|
2018-03-21 13:15:02 +01:00
|
|
|
|
|
|
|
param = &c_trans;
|
|
|
|
}
|
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(mbox, sign, param);
|
2017-11-07 17:00:55 +01:00
|
|
|
if(res != LV_RES_OK) return res;
|
2019-09-26 10:51:54 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(mbox, param, LV_OBJX_NAME);
|
2016-12-16 07:41:34 +01:00
|
|
|
|
2017-11-07 17:00:55 +01:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
|
|
|
if(sign == LV_SIGNAL_CORD_CHG) {
|
2017-11-28 16:15:13 +01:00
|
|
|
if(lv_obj_get_width(mbox) != lv_area_get_width(param)) {
|
2017-11-15 15:50:33 +01:00
|
|
|
mbox_realign(mbox);
|
2017-11-07 17:00:55 +01:00
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_STYLE_CHG) {
|
2017-11-15 15:50:33 +01:00
|
|
|
mbox_realign(mbox);
|
2019-04-04 07:15:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_RELEASED) {
|
2019-06-13 05:13:34 +02:00
|
|
|
if(ext->btnm) {
|
2019-06-19 13:43:02 +02:00
|
|
|
uint32_t btn_id = lv_btnm_get_active_btn(ext->btnm);
|
2019-06-14 06:56:54 +02:00
|
|
|
if(btn_id != LV_BTNM_BTN_NONE) lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id);
|
2019-06-13 05:13:34 +02:00
|
|
|
}
|
2019-04-04 07:15:40 +02:00
|
|
|
} else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROL ||
|
|
|
|
sign == LV_SIGNAL_GET_EDITABLE) {
|
2017-11-15 15:50:33 +01:00
|
|
|
if(ext->btnm) {
|
2019-02-26 09:25:46 +01:00
|
|
|
ext->btnm->signal_cb(ext->btnm, sign, param);
|
2018-09-26 14:21:39 +02:00
|
|
|
}
|
2018-07-25 21:52:50 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
/* The button matrix with ENCODER input supposes it's in a group but in this case it isn't
|
|
|
|
* (Only the message box's container) So so some actions here instead*/
|
2018-09-26 14:21:39 +02:00
|
|
|
if(sign == LV_SIGNAL_FOCUS) {
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GROUP
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_indev_t * indev = lv_indev_get_act();
|
2019-03-29 16:10:18 +01:00
|
|
|
lv_indev_type_t indev_type = lv_indev_get_type(indev);
|
2018-10-05 17:22:49 +02:00
|
|
|
if(indev_type == LV_INDEV_TYPE_ENCODER) {
|
2018-09-26 14:21:39 +02:00
|
|
|
/*In navigation mode don't select any button but in edit mode select the fist*/
|
|
|
|
lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btnm);
|
2019-04-04 07:15:40 +02:00
|
|
|
if(lv_group_get_editing(lv_obj_get_group(mbox)))
|
|
|
|
btnm_ext->btn_id_pr = 0;
|
|
|
|
else
|
|
|
|
btnm_ext->btn_id_pr = LV_BTNM_BTN_NONE;
|
2018-09-26 14:21:39 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2016-12-16 07:41:34 +01:00
|
|
|
}
|
|
|
|
|
2017-01-10 16:07:46 +01:00
|
|
|
/**
|
2017-11-07 16:18:38 +01:00
|
|
|
* Resize the button holder to fit
|
2017-11-07 15:13:34 +01:00
|
|
|
* @param mbox pointer to message box object
|
2017-01-10 16:07:46 +01:00
|
|
|
*/
|
2018-06-19 09:49:58 +02:00
|
|
|
static void mbox_realign(lv_obj_t * mbox)
|
2017-01-10 16:07:46 +01:00
|
|
|
{
|
2017-11-07 16:18:38 +01:00
|
|
|
lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
|
|
|
|
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BG);
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_coord_t w = lv_obj_get_width(mbox) - style->body.padding.left - style->body.padding.right;
|
2017-11-17 15:43:08 +01:00
|
|
|
|
|
|
|
if(ext->text) {
|
|
|
|
lv_obj_set_width(ext->text, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ext->btnm) {
|
2019-04-11 19:59:55 +08:00
|
|
|
const lv_style_t * btn_bg_style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BTN_BG);
|
|
|
|
const lv_style_t * btn_rel_style = lv_mbox_get_style(mbox, LV_MBOX_STYLE_BTN_REL);
|
2019-04-23 15:56:59 +02:00
|
|
|
lv_coord_t font_h = lv_font_get_line_height(btn_rel_style->text.font);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_set_size(ext->btnm, w,
|
2019-06-06 06:05:40 +02:00
|
|
|
font_h + btn_rel_style->body.padding.top + btn_rel_style->body.padding.bottom +
|
|
|
|
btn_bg_style->body.padding.top + btn_bg_style->body.padding.bottom);
|
2017-11-17 15:43:08 +01:00
|
|
|
}
|
2017-01-10 16:07:46 +01:00
|
|
|
}
|
|
|
|
|
2019-05-20 18:31:47 -07:00
|
|
|
#if LV_USE_ANIMATION
|
2019-04-22 08:45:07 +02:00
|
|
|
static void lv_mbox_close_ready_cb(lv_anim_t * a)
|
2017-11-16 15:32:33 +01:00
|
|
|
{
|
2019-04-22 08:45:07 +02:00
|
|
|
lv_obj_del(a->var);
|
2017-11-16 15:32:33 +01:00
|
|
|
}
|
2019-05-20 18:31:47 -07:00
|
|
|
#endif
|
2017-11-16 15:32:33 +01:00
|
|
|
|
2019-03-12 06:20:45 +01:00
|
|
|
static void lv_mbox_default_event_cb(lv_obj_t * mbox, lv_event_t event)
|
2019-01-05 19:44:43 +01:00
|
|
|
{
|
2019-06-14 06:56:54 +02:00
|
|
|
if(event != LV_EVENT_VALUE_CHANGED) return;
|
2019-03-12 06:20:45 +01:00
|
|
|
|
2019-06-19 13:43:02 +02:00
|
|
|
uint32_t btn_id = lv_mbox_get_active_btn(mbox);
|
2019-03-12 06:20:45 +01:00
|
|
|
if(btn_id == LV_BTNM_BTN_NONE) return;
|
|
|
|
|
|
|
|
lv_mbox_start_auto_close(mbox, 0);
|
2019-01-05 19:44:43 +01:00
|
|
|
}
|
2019-03-12 06:20:45 +01:00
|
|
|
|
2019-07-05 14:46:53 -04:00
|
|
|
static void lv_mbox_btnm_event_cb(lv_obj_t * btnm, lv_event_t event)
|
|
|
|
{
|
|
|
|
lv_obj_t * mbox = lv_obj_get_parent(btnm);
|
|
|
|
|
|
|
|
/*clang-format off*/
|
|
|
|
if(event == LV_EVENT_PRESSED || event == LV_EVENT_PRESSING || event == LV_EVENT_PRESS_LOST ||
|
|
|
|
event == LV_EVENT_RELEASED || event == LV_EVENT_SHORT_CLICKED || event == LV_EVENT_CLICKED ||
|
|
|
|
event == LV_EVENT_LONG_PRESSED || event == LV_EVENT_LONG_PRESSED_REPEAT ||
|
|
|
|
event == LV_EVENT_VALUE_CHANGED) {
|
|
|
|
lv_event_send(mbox, event, lv_event_get_data());
|
|
|
|
}
|
|
|
|
/*clang-format on*/
|
|
|
|
}
|
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
#endif
|