/**1* @file lv_btnm.h2*3*/456#ifndef LV_BTNM_H7#define LV_BTNM_H89#ifdef __cplusplus10extern "C" {11#endif1213/*********************14* INCLUDES15*********************/16#ifdef LV_CONF_INCLUDE_SIMPLE17#include "lv_conf.h"18#else19#include "../../lv_conf.h"20#endif2122#if USE_LV_BTNM != 02324#include "../lv_core/lv_obj.h"25#include "lv_label.h"26#include "lv_btn.h"2728/*********************29* DEFINES30*********************/3132/*Control byte*/33#define LV_BTNM_CTRL_CODE 0x80 /*The control byte has to begin (if present) with 0b10xxxxxx*/34#define LV_BTNM_CTRL_MASK 0xC035#define LV_BTNM_WIDTH_MASK 0x0736#define LV_BTNM_HIDE_MASK 0x0837#define LV_BTNM_REPEAT_DISABLE_MASK 0x1038#define LV_BTNM_INACTIVE_MASK 0x20394041#define LV_BTNM_PR_NONE 0xFFFF42/**********************43* TYPEDEFS44**********************/4546/* Type of callback function which is called when a button is released or long pressed on the button matrix47* Parameters: button matrix, text of the released button48* return LV_ACTION_RES_INV if the button matrix is deleted else LV_ACTION_RES_OK*/49typedef lv_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt);5051/*Data of button matrix*/52typedef struct53{54/*No inherited ext.*/ /*Ext. of ancestor*/55/*New data for this type */56const char ** map_p; /*Pointer to the current map*/57lv_area_t *button_areas; /*Array of areas of buttons*/58lv_btnm_action_t action; /*A function to call when a button is releases*/59lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/60uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/61uint16_t btn_id_pr; /*Index of the currently pressed button (in `button_areas`) or LV_BTNM_PR_NONE*/62uint16_t btn_id_tgl; /*Index of the currently toggled button (in `button_areas`) or LV_BTNM_PR_NONE */63uint8_t toggle :1; /*Enable toggling*/64uint8_t recolor :1; /*Enable button recoloring*/65} lv_btnm_ext_t;6667enum {68LV_BTNM_STYLE_BG,69LV_BTNM_STYLE_BTN_REL,70LV_BTNM_STYLE_BTN_PR,71LV_BTNM_STYLE_BTN_TGL_REL,72LV_BTNM_STYLE_BTN_TGL_PR,73LV_BTNM_STYLE_BTN_INA,74};75typedef uint8_t lv_btnm_style_t;7677/**********************78* GLOBAL PROTOTYPES79**********************/8081/**82* Create a button matrix objects83* @param par pointer to an object, it will be the parent of the new button matrix84* @param copy pointer to a button matrix object, if not NULL then the new object will be copied from it85* @return pointer to the created button matrix86*/87lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy);8889/*=====================90* Setter functions91*====================*/9293/**94* Set a new map. Buttons will be created/deleted according to the map.95* @param btnm pointer to a button matrix object96* @param map pointer a string array. The last string has to be: "".97* Use "\n" to begin a new line.98* The first byte can be a control data:99* - bit 7: always 1100* - bit 6: always 0101* - bit 5: inactive (disabled)102* - bit 4: no repeat (on long press)103* - bit 3: hidden104* - bit 2..0: button relative width105* Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press106*/107void lv_btnm_set_map(lv_obj_t * btnm, const char ** map);108109/**110* Set a new callback function for the buttons (It will be called when a button is released)111* @param btnm: pointer to button matrix object112* @param action pointer to a callback function113*/114void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t action);115116/**117* Enable or disable button toggling118* @param btnm pointer to button matrix object119* @param en true: enable toggling; false: disable toggling120* @param id index of the currently toggled button (ignored if 'en' == false)121*/122void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id);123124/**125* Set a style of a button matrix126* @param btnm pointer to a button matrix object127* @param type which style should be set128* @param style pointer to a style129*/130void lv_btnm_set_style(lv_obj_t *btnm, lv_btnm_style_t type, lv_style_t *style);131132/**133* Set whether recoloring is enabled134* @param btnm pointer to button matrix object135* @param en whether recoloring is enabled136*/137void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en);138139/*=====================140* Getter functions141*====================*/142143/**144* Get the current map of a button matrix145* @param btnm pointer to a button matrix object146* @return the current map147*/148const char ** lv_btnm_get_map(const lv_obj_t * btnm);149150/**151* Get a the callback function of the buttons on a button matrix152* @param btnm: pointer to button matrix object153* @return pointer to the callback function154*/155lv_btnm_action_t lv_btnm_get_action(const lv_obj_t * btnm);156157/**158* Get the pressed button159* @param btnm pointer to button matrix object160* @return index of the currently pressed button (LV_BTNM_PR_NONE: if unset)161*/162uint16_t lv_btnm_get_pressed(const lv_obj_t * btnm);163164/**165* Get the toggled button166* @param btnm pointer to button matrix object167* @return index of the currently toggled button (LV_BTNM_PR_NONE: if unset)168*/169uint16_t lv_btnm_get_toggled(const lv_obj_t * btnm);170171/**172* Get a style of a button matrix173* @param btnm pointer to a button matrix object174* @param type which style should be get175* @return style pointer to a style176*/177lv_style_t * lv_btnm_get_style(const lv_obj_t *btnm, lv_btnm_style_t type);178179/**180* Find whether recoloring is enabled181* @param btnm pointer to button matrix object182* @return whether recoloring is enabled183*/184bool lv_btnm_get_recolor(const lv_obj_t * btnm);185186/**********************187* MACROS188**********************/189190#endif /*USE_LV_BTNM*/191192#ifdef __cplusplus193} /* extern "C" */194#endif195196#endif /*LV_BTNM_H*/197198199