/*1* Copyright (c) 2019 CTCaer2*3* This program is free software; you can redistribute it and/or modify it4* under the terms and conditions of the GNU General Public License,5* version 2, as published by the Free Software Foundation.6*7* This program is distributed in the hope it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for10* more details.11*12* You should have received a copy of the GNU General Public License13* along with this program. If not, see <http://www.gnu.org/licenses/>.14*/1516/**17* @file lv_mbox.h18*19*/2021#ifndef LV_MBOX_H22#define LV_MBOX_H2324#ifdef __cplusplus25extern "C" {26#endif2728/*********************29* INCLUDES30*********************/31#ifdef LV_CONF_INCLUDE_SIMPLE32#include "lv_conf.h"33#else34#include "../../lv_conf.h"35#endif3637#if USE_LV_MBOX != 03839/*Testing of dependencies*/40#if USE_LV_CONT == 041#error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) "42#endif4344#if USE_LV_BTNM == 045#error "lv_mbox: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) "46#endif4748#if USE_LV_LABEL == 049#error "lv_mbox: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) "50#endif515253#include "../lv_core/lv_obj.h"54#include "lv_cont.h"55#include "lv_btnm.h"56#include "lv_label.h"5758/*********************59* DEFINES60*********************/6162/**********************63* TYPEDEFS64**********************/6566/*Data of message box*/67typedef struct68{69lv_cont_ext_t bg; /*Ext. of ancestor*/70/*New data for this type */71lv_obj_t *text; /*Text of the message box*/72lv_obj_t *btnm; /*Button matrix for the buttons*/73uint16_t anim_time; /*Duration of close animation [ms] (0: no animation)*/74} lv_mbox_ext_t;7576enum {77LV_MBOX_STYLE_BG,78LV_MBOX_STYLE_BTN_BG,79LV_MBOX_STYLE_BTN_REL,80LV_MBOX_STYLE_BTN_PR,81LV_MBOX_STYLE_BTN_TGL_REL,82LV_MBOX_STYLE_BTN_TGL_PR,83LV_MBOX_STYLE_BTN_INA,84};85typedef uint8_t lv_mbox_style_t;8687/**********************88* GLOBAL PROTOTYPES89**********************/9091/**92* Create a message box objects93* @param par pointer to an object, it will be the parent of the new message box94* @param copy pointer to a message box object, if not NULL then the new object will be copied from it95* @return pointer to the created message box96*/97lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy);9899/*======================100* Add/remove functions101*=====================*/102103/**104* Add button to the message box105* @param mbox pointer to message box object106* @param btn_map button descriptor (button matrix map).107* E.g. a const char *txt[] = {"ok", "close", ""} (Can not be local variable)108* @param action a function which will be called when a button is released109*/110void lv_mbox_add_btns(lv_obj_t * mbox, const char **btn_map, lv_btnm_action_t action);111112/*=====================113* Setter functions114*====================*/115116/**117* Set the text of the message box118* @param mbox pointer to a message box119* @param txt a '\0' terminated character string which will be the message box text120*/121void lv_mbox_set_text(lv_obj_t * mbox, const char * txt);122123/**124* Stop the action to call when button is released125* @param mbox pointer to a message box object126* @param pointer to an 'lv_btnm_action_t' action. In the action you need to use `lv_mbox_get_from_btn()` to get the `mbox`.127*/128void lv_mbox_set_action(lv_obj_t * mbox, lv_btnm_action_t action);129130/**131* Set animation duration132* @param mbox pointer to a message box object133* @param anim_time animation length in milliseconds (0: no animation)134*/135void lv_mbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time);136137/**138* Automatically delete the message box after a given time139* @param mbox pointer to a message box object140* @param delay a time (in milliseconds) to wait before delete the message box141*/142void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay);143144/**145* Stop the auto. closing of message box146* @param mbox pointer to a message box object147*/148void lv_mbox_stop_auto_close(lv_obj_t * mbox);149150/**151* Set a style of a message box152* @param mbox pointer to a message box object153* @param type which style should be set154* @param style pointer to a style155*/156void lv_mbox_set_style(lv_obj_t *mbox, lv_mbox_style_t type, lv_style_t *style);157158/**159* Set whether recoloring is enabled. Must be called after `lv_mbox_add_btns`.160* @param btnm pointer to button matrix object161* @param en whether recoloring is enabled162*/163void lv_mbox_set_recolor(lv_obj_t * mbox, bool en);164165void lv_mbox_set_recolor_text(lv_obj_t * mbox, bool en);166167/*=====================168* Getter functions169*====================*/170171/**172* Get the text of the message box173* @param mbox pointer to a message box object174* @return pointer to the text of the message box175*/176const char * lv_mbox_get_text(const lv_obj_t * mbox);177178/**179* Get the message box object from one of its button.180* It is useful in the button release actions where only the button is known181* @param btn pointer to a button of a message box182* @return pointer to the button's message box183*/184lv_obj_t * lv_mbox_get_from_btn(const lv_obj_t * btn);185186/**187* Get the animation duration (close animation time)188* @param mbox pointer to a message box object189* @return animation length in milliseconds (0: no animation)190*/191uint16_t lv_mbox_get_anim_time(const lv_obj_t * mbox);192193194/**195* Get a style of a message box196* @param mbox pointer to a message box object197* @param type which style should be get198* @return style pointer to a style199*/200lv_style_t * lv_mbox_get_style(const lv_obj_t *mbox, lv_mbox_style_t type);201202/**203* Get whether recoloring is enabled204* @param btnm pointer to button matrix object205* @return whether recoloring is enabled206*/207bool lv_mbox_get_recolor(const lv_obj_t * mbox);208209/**********************210* MACROS211**********************/212213214#endif /*USE_LV_MBOX*/215216#ifdef __cplusplus217} /* extern "C" */218#endif219220#endif /*LV_MBOX_H*/221222223