Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_objx/lv_btnm.h
1476 views
1
/**
2
* @file lv_btnm.h
3
*
4
*/
5
6
7
#ifndef LV_BTNM_H
8
#define LV_BTNM_H
9
10
#ifdef __cplusplus
11
extern "C" {
12
#endif
13
14
/*********************
15
* INCLUDES
16
*********************/
17
#ifdef LV_CONF_INCLUDE_SIMPLE
18
#include "lv_conf.h"
19
#else
20
#include "../../lv_conf.h"
21
#endif
22
23
#if USE_LV_BTNM != 0
24
25
#include "../lv_core/lv_obj.h"
26
#include "lv_label.h"
27
#include "lv_btn.h"
28
29
/*********************
30
* DEFINES
31
*********************/
32
33
/*Control byte*/
34
#define LV_BTNM_CTRL_CODE 0x80 /*The control byte has to begin (if present) with 0b10xxxxxx*/
35
#define LV_BTNM_CTRL_MASK 0xC0
36
#define LV_BTNM_WIDTH_MASK 0x07
37
#define LV_BTNM_HIDE_MASK 0x08
38
#define LV_BTNM_REPEAT_DISABLE_MASK 0x10
39
#define LV_BTNM_INACTIVE_MASK 0x20
40
41
42
#define LV_BTNM_PR_NONE 0xFFFF
43
/**********************
44
* TYPEDEFS
45
**********************/
46
47
/* Type of callback function which is called when a button is released or long pressed on the button matrix
48
* Parameters: button matrix, text of the released button
49
* return LV_ACTION_RES_INV if the button matrix is deleted else LV_ACTION_RES_OK*/
50
typedef lv_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt);
51
52
/*Data of button matrix*/
53
typedef struct
54
{
55
/*No inherited ext.*/ /*Ext. of ancestor*/
56
/*New data for this type */
57
const char ** map_p; /*Pointer to the current map*/
58
lv_area_t *button_areas; /*Array of areas of buttons*/
59
lv_btnm_action_t action; /*A function to call when a button is releases*/
60
lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/
61
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/
62
uint16_t btn_id_pr; /*Index of the currently pressed button (in `button_areas`) or LV_BTNM_PR_NONE*/
63
uint16_t btn_id_tgl; /*Index of the currently toggled button (in `button_areas`) or LV_BTNM_PR_NONE */
64
uint8_t toggle :1; /*Enable toggling*/
65
uint8_t recolor :1; /*Enable button recoloring*/
66
} lv_btnm_ext_t;
67
68
enum {
69
LV_BTNM_STYLE_BG,
70
LV_BTNM_STYLE_BTN_REL,
71
LV_BTNM_STYLE_BTN_PR,
72
LV_BTNM_STYLE_BTN_TGL_REL,
73
LV_BTNM_STYLE_BTN_TGL_PR,
74
LV_BTNM_STYLE_BTN_INA,
75
};
76
typedef uint8_t lv_btnm_style_t;
77
78
/**********************
79
* GLOBAL PROTOTYPES
80
**********************/
81
82
/**
83
* Create a button matrix objects
84
* @param par pointer to an object, it will be the parent of the new button matrix
85
* @param copy pointer to a button matrix object, if not NULL then the new object will be copied from it
86
* @return pointer to the created button matrix
87
*/
88
lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy);
89
90
/*=====================
91
* Setter functions
92
*====================*/
93
94
/**
95
* Set a new map. Buttons will be created/deleted according to the map.
96
* @param btnm pointer to a button matrix object
97
* @param map pointer a string array. The last string has to be: "".
98
* Use "\n" to begin a new line.
99
* The first byte can be a control data:
100
* - bit 7: always 1
101
* - bit 6: always 0
102
* - bit 5: inactive (disabled)
103
* - bit 4: no repeat (on long press)
104
* - bit 3: hidden
105
* - bit 2..0: button relative width
106
* Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press
107
*/
108
void lv_btnm_set_map(lv_obj_t * btnm, const char ** map);
109
110
/**
111
* Set a new callback function for the buttons (It will be called when a button is released)
112
* @param btnm: pointer to button matrix object
113
* @param action pointer to a callback function
114
*/
115
void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t action);
116
117
/**
118
* Enable or disable button toggling
119
* @param btnm pointer to button matrix object
120
* @param en true: enable toggling; false: disable toggling
121
* @param id index of the currently toggled button (ignored if 'en' == false)
122
*/
123
void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id);
124
125
/**
126
* Set a style of a button matrix
127
* @param btnm pointer to a button matrix object
128
* @param type which style should be set
129
* @param style pointer to a style
130
*/
131
void lv_btnm_set_style(lv_obj_t *btnm, lv_btnm_style_t type, lv_style_t *style);
132
133
/**
134
* Set whether recoloring is enabled
135
* @param btnm pointer to button matrix object
136
* @param en whether recoloring is enabled
137
*/
138
void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en);
139
140
/*=====================
141
* Getter functions
142
*====================*/
143
144
/**
145
* Get the current map of a button matrix
146
* @param btnm pointer to a button matrix object
147
* @return the current map
148
*/
149
const char ** lv_btnm_get_map(const lv_obj_t * btnm);
150
151
/**
152
* Get a the callback function of the buttons on a button matrix
153
* @param btnm: pointer to button matrix object
154
* @return pointer to the callback function
155
*/
156
lv_btnm_action_t lv_btnm_get_action(const lv_obj_t * btnm);
157
158
/**
159
* Get the pressed button
160
* @param btnm pointer to button matrix object
161
* @return index of the currently pressed button (LV_BTNM_PR_NONE: if unset)
162
*/
163
uint16_t lv_btnm_get_pressed(const lv_obj_t * btnm);
164
165
/**
166
* Get the toggled button
167
* @param btnm pointer to button matrix object
168
* @return index of the currently toggled button (LV_BTNM_PR_NONE: if unset)
169
*/
170
uint16_t lv_btnm_get_toggled(const lv_obj_t * btnm);
171
172
/**
173
* Get a style of a button matrix
174
* @param btnm pointer to a button matrix object
175
* @param type which style should be get
176
* @return style pointer to a style
177
*/
178
lv_style_t * lv_btnm_get_style(const lv_obj_t *btnm, lv_btnm_style_t type);
179
180
/**
181
* Find whether recoloring is enabled
182
* @param btnm pointer to button matrix object
183
* @return whether recoloring is enabled
184
*/
185
bool lv_btnm_get_recolor(const lv_obj_t * btnm);
186
187
/**********************
188
* MACROS
189
**********************/
190
191
#endif /*USE_LV_BTNM*/
192
193
#ifdef __cplusplus
194
} /* extern "C" */
195
#endif
196
197
#endif /*LV_BTNM_H*/
198
199