按钮矩阵 (lv_btnmatrix)¶
概述¶
按钮矩阵对象是一种轻量级的方式,用于以行和列的形式显示多个按钮。之所以轻量,是因为这些按钮实际上并未被创建,而是动态绘制的。这样,每个按钮仅使用额外的 8 字节内存,而不是普通按钮对象的约 100-150 字节加上标签对象的约 100 字节。
按钮矩阵会被添加到默认组(如果已设置)。此外,按钮矩阵是一个可编辑对象,允许通过编码器导航选择和点击按钮。
部件和样式¶
LV_PART_MAIN按钮矩阵的背景,使用典型的背景样式属性。pad_row和pad_column设置按钮之间的间距。LV_PART_ITEMS按钮使用文本和典型的背景样式属性,但不包括翻译和变换。
用法¶
按钮的文本¶
每个按钮上都有文本。需要使用一个描述字符串数组(称为 map)来指定它们。
可以通过 lv_btnmatrix_set_map(btnm, my_map) 设置 map。
map 的声明应如下所示:const char * map[] = {"btn1", "btn2", "btn3", NULL}。
注意,最后一个元素必须是 NULL 或空字符串("")!
在 map 中使用 "\n" 插入换行符。例如:{"btn1", "btn2", "\n", "btn3", ""}。每行按钮的宽度会自动计算。
因此,在示例中,第一行有两个按钮,每个按钮宽度为 50%,第二行有一个按钮,宽度为 100%。
控制按钮¶
按钮的宽度可以通过 lv_btnmatrix_set_btn_width(btnm, btn_id, width) 相对于同一行的其他按钮设置。
例如,在一行中有两个按钮:btnA, width = 1 和 btnB, width = 2,btnA 的宽度为 33%,btnB 的宽度为 66%。
这类似于 CSS 中的 flex-grow 属性。
宽度必须在 [1..7] 范围内,默认宽度为 1。
除了宽度,每个按钮还可以通过以下参数进行自定义:
LV_BTNMATRIX_CTRL_HIDDEN隐藏按钮(隐藏的按钮仍占用布局空间,但不可见或不可点击)LV_BTNMATRIX_CTRL_NO_REPEAT禁用按钮长按时的重复触发LV_BTNMATRIX_CTRL_DISABLED禁用按钮,类似于普通对象的LV_STATE_DISABLEDLV_BTNMATRIX_CTRL_CHECKABLE启用按钮的切换功能,即点击按钮时会添加/移除LV_STATE_CHECKEDLV_BTNMATRIX_CTRL_CHECKED将按钮设置为选中状态。它将使用LV_STATE_CHECKED样式。LV_BTNMATRIX_CTRL_CLICK_TRIG启用:在点击时发送LV_EVENT_VALUE_CHANGE,禁用:在按下时发送LV_EVENT_VALUE_CHANGELV_BTNMATRIX_CTRL_POPOVER按下此按钮时在弹出框中显示按钮标签LV_BTNMATRIX_CTRL_RECOLOR启用按钮文本的重新着色,使用#。例如:"It's #ff0000 red#"LV_BTNMATRIX_CTRL_CUSTOM_1自定义可用标志LV_BTNMATRIX_CTRL_CUSTOM_2自定义可用标志
默认情况下,所有标志均为禁用状态。
可以使用 lv_btnmatrix_set_btn_ctrl(btnm, btn_id, LV_BTNM_CTRL_...) 和 lv_btnmatrix_clear_btn_ctrl(btnm, btn_id, LV_BTNMATRIX_CTRL_...) 分别设置或清除按钮的控制属性。多个 LV_BTNM_CTRL_... 值可以通过 OR 运算符组合。
要为按钮矩阵的所有按钮设置/清除相同的控制属性,可以使用 lv_btnmatrix_set_btn_ctrl_all(btnm, LV_BTNM_CTRL_...) 和 lv_btnmatrix_clear_btn_ctrl_all(btnm, LV_BTNM_CTRL_...)。
要为按钮矩阵设置控制 map(类似于文本的 map),可以使用 lv_btnmatrix_set_ctrl_map(btnm, ctrl_map)。
ctrl_map 的元素应如下所示:ctrl_map[0] = width | LV_BTNM_CTRL_NO_REPEAT | LV_BTNM_CTRL_CHECKABLE。
元素的数量应与按钮的数量相等(不包括换行符)。
单选模式¶
可以通过 lv_btnmatrix_set_one_checked(btnm, true) 启用“单选”功能,以便一次只能选中一个按钮。
事件¶
LV_EVENT_VALUE_CHANGED当按钮被按下/释放或长按后重复时发送。事件参数设置为按下/释放按钮的 ID。LV_EVENT_DRAW_PART_BEGIN和LV_EVENT_DRAW_PART_END针对以下类型发送:LV_BTNMATRIX_DRAW_PART_BTN单个按钮。part:LV_PART_ITEMSid: 正在绘制的按钮的索引draw_area: 按钮的区域rect_dsc
另请参阅基础对象的事件。
lv_btnmatrix_get_selected_btn(btnm) 返回最近释放或聚焦的按钮的索引,如果没有则返回 LV_BTNMATRIX_BTN_NONE。
lv_btnmatrix_get_btn_text(btnm, btn_id) 返回 btn_id 按钮的文本指针。
了解更多关于事件的信息。
示例¶
简单按钮矩阵¶
C code
GitHub#include "../../lv_examples.h"
#if LV_USE_BTNMATRIX && LV_BUILD_EXAMPLES
static void event_handler(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if(code == LV_EVENT_VALUE_CHANGED) {
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
const char * txt = lv_btnmatrix_get_btn_text(obj, id);
LV_LOG_USER("%s was pressed\n", txt);
}
}
static const char * btnm_map[] = {"1", "2", "3", "4", "5", "\n",
"6", "7", "8", "9", "0", "\n",
"Action1", "Action2", ""
};
void lv_example_btnmatrix_1(void)
{
lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm1, btnm_map);
lv_btnmatrix_set_btn_width(btnm1, 10, 2); /*Make "Action1" twice as wide as "Action2"*/
lv_btnmatrix_set_btn_ctrl(btnm1, 10, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_CHECKED);
lv_obj_align(btnm1, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(btnm1, event_handler, LV_EVENT_ALL, NULL);
}
#endif
def event_handler(evt):
code = evt.get_code()
obj = evt.get_target()
if code == lv.EVENT.VALUE_CHANGED :
id = obj.get_selected_btn()
txt = obj.get_btn_text(id)
print("%s was pressed"%txt)
btnm_map = ["1", "2", "3", "4", "5", "\n",
"6", "7", "8", "9", "0", "\n",
"Action1", "Action2", ""]
btnm1 = lv.btnmatrix(lv.scr_act())
btnm1.set_map(btnm_map)
btnm1.set_btn_width(10, 2) # Make "Action1" twice as wide as "Action2"
btnm1.set_btn_ctrl(10, lv.btnmatrix.CTRL.CHECKABLE)
btnm1.set_btn_ctrl(11, lv.btnmatrix.CTRL.CHECKED)
btnm1.align(lv.ALIGN.CENTER, 0, 0)
btnm1.add_event_cb(event_handler, lv.EVENT.ALL, None)
#endif
自定义按钮¶
C code
GitHub#include "../../lv_examples.h"
#if LV_USE_BTNMATRIX && LV_BUILD_EXAMPLES
static void event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if(code == LV_EVENT_DRAW_PART_BEGIN) {
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
/*When the button matrix draws the buttons...*/
if(dsc->class_p == &lv_btnmatrix_class && dsc->type == LV_BTNMATRIX_DRAW_PART_BTN) {
/*Change the draw descriptor of the 2nd button*/
if(dsc->id == 1) {
dsc->rect_dsc->radius = 0;
if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_palette_darken(LV_PALETTE_BLUE, 3);
else dsc->rect_dsc->bg_color = lv_palette_main(LV_PALETTE_BLUE);
dsc->rect_dsc->shadow_width = 6;
dsc->rect_dsc->shadow_ofs_x = 3;
dsc->rect_dsc->shadow_ofs_y = 3;
dsc->label_dsc->color = lv_color_white();
}
/*Change the draw descriptor of the 3rd button*/
else if(dsc->id == 2) {
dsc->rect_dsc->radius = LV_RADIUS_CIRCLE;
if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_palette_darken(LV_PALETTE_RED, 3);
else dsc->rect_dsc->bg_color = lv_palette_main(LV_PALETTE_RED);
dsc->label_dsc->color = lv_color_white();
}
else if(dsc->id == 3) {
dsc->label_dsc->opa = LV_OPA_TRANSP; /*Hide the text if any*/
}
}
}
if(code == LV_EVENT_DRAW_PART_END) {
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
/*When the button matrix draws the buttons...*/
if(dsc->class_p == &lv_btnmatrix_class && dsc->type == LV_BTNMATRIX_DRAW_PART_BTN) {
/*Add custom content to the 4th button when the button itself was drawn*/
if(dsc->id == 3) {
LV_IMG_DECLARE(img_star);
lv_img_header_t header;
lv_res_t res = lv_img_decoder_get_info(&img_star, &header);
if(res != LV_RES_OK) return;
lv_area_t a;
a.x1 = dsc->draw_area->x1 + (lv_area_get_width(dsc->draw_area) - header.w) / 2;
a.x2 = a.x1 + header.w - 1;
a.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - header.h) / 2;
a.y2 = a.y1 + header.h - 1;
lv_draw_img_dsc_t img_draw_dsc;
lv_draw_img_dsc_init(&img_draw_dsc);
img_draw_dsc.recolor = lv_color_black();
if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30;
lv_draw_img(dsc->draw_ctx, &img_draw_dsc, &a, &img_star);
}
}
}
}
/**
* Add custom drawer to the button matrix to customize buttons one by one
*/
void lv_example_btnmatrix_2(void)
{
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act());
lv_obj_add_event_cb(btnm, event_cb, LV_EVENT_ALL, NULL);
lv_obj_center(btnm);
}
#endif
from imagetools import get_png_info, open_png
# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png
# Create an image from the png file
try:
with open('../../assets/img_star.png','rb') as f:
png_data = f.read()
except:
print("Could not find star.png")
sys.exit()
img_star_argb = lv.img_dsc_t({
'data_size': len(png_data),
'data': png_data
})
def event_cb(e):
code = e.get_code()
obj = e.get_target()
dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param())
if code == lv.EVENT.DRAW_PART_BEGIN:
# Change the draw descriptor the 2nd button
if dsc.id == 1:
dsc.rect_dsc.radius = 0
if obj.get_selected_btn() == dsc.id:
dsc.rect_dsc.bg_color = lv.palette_darken(lv.PALETTE.GREY, 3)
else:
dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE)
dsc.rect_dsc.shadow_width = 6
dsc.rect_dsc.shadow_ofs_x = 3
dsc.rect_dsc.shadow_ofs_y = 3
dsc.label_dsc.color = lv.color_white()
# Change the draw descriptor the 3rd button
elif dsc.id == 2:
dsc.rect_dsc.radius = lv.RADIUS.CIRCLE
if obj.get_selected_btn() == dsc.id:
dsc.rect_dsc.bg_color = lv.palette_darken(lv.PALETTE.RED, 3)
else:
dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.RED)
dsc.label_dsc.color = lv.color_white()
elif dsc.id == 3:
dsc.label_dsc.opa = lv.OPA.TRANSP # Hide the text if any
if code == lv.EVENT.DRAW_PART_END:
# Add custom content to the 4th button when the button itself was drawn
if dsc.id == 3:
# LV_IMG_DECLARE(img_star)
header = lv.img_header_t()
res = lv.img.decoder_get_info(img_star_argb, header)
if res != lv.RES.OK:
print("error when getting image header")
return
else:
a = lv.area_t()
a.x1 = dsc.draw_area.x1 + (dsc.draw_area.get_width() - header.w) // 2
a.x2 = a.x1 + header.w - 1
a.y1 = dsc.draw_area.y1 + (dsc.draw_area.get_height() - header.h) // 2
a.y2 = a.y1 + header.h - 1
img_draw_dsc = lv.draw_img_dsc_t()
img_draw_dsc.init()
img_draw_dsc.recolor = lv.color_black()
if obj.get_selected_btn() == dsc.id:
img_draw_dsc.recolor_opa = lv.OPA._30
dsc.draw_ctx.img(img_draw_dsc, a, img_star_argb)
#
# Add custom drawer to the button matrix to c
#
btnm = lv.btnmatrix(lv.scr_act())
btnm.add_event_cb(event_cb, lv.EVENT.ALL, None)
btnm.center()
分页¶
C code
GitHub#include "../../lv_examples.h"
#if LV_USE_BTNMATRIX && LV_BUILD_EXAMPLES
static void event_cb(lv_event_t * e)
{
lv_obj_t * obj = lv_event_get_target(e);
uint32_t id = lv_btnmatrix_get_selected_btn(obj);
bool prev = id == 0 ? true : false;
bool next = id == 6 ? true : false;
if(prev || next) {
/*Find the checked button*/
uint32_t i;
for(i = 1; i < 7; i++) {
if(lv_btnmatrix_has_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED)) break;
}
if(prev && i > 1) i--;
else if(next && i < 5) i++;
lv_btnmatrix_set_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED);
}
}
/**
* Make a button group (pagination)
*/
void lv_example_btnmatrix_3(void)
{
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_pad_all(&style_bg, 0);
lv_style_set_pad_gap(&style_bg, 0);
lv_style_set_clip_corner(&style_bg, true);
lv_style_set_radius(&style_bg, LV_RADIUS_CIRCLE);
lv_style_set_border_width(&style_bg, 0);
static lv_style_t style_btn;
lv_style_init(&style_btn);
lv_style_set_radius(&style_btn, 0);
lv_style_set_border_width(&style_btn, 1);
lv_style_set_border_opa(&style_btn, LV_OPA_50);
lv_style_set_border_color(&style_btn, lv_palette_main(LV_PALETTE_GREY));
lv_style_set_border_side(&style_btn, LV_BORDER_SIDE_INTERNAL);
lv_style_set_radius(&style_btn, 0);
static const char * map[] = {LV_SYMBOL_LEFT, "1", "2", "3", "4", "5", LV_SYMBOL_RIGHT, ""};
lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act());
lv_btnmatrix_set_map(btnm, map);
lv_obj_add_style(btnm, &style_bg, 0);
lv_obj_add_style(btnm, &style_btn, LV_PART_ITEMS);
lv_obj_add_event_cb(btnm, event_cb, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_set_size(btnm, 225, 35);
/*Allow selecting on one number at time*/
lv_btnmatrix_set_btn_ctrl_all(btnm, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_clear_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_clear_btn_ctrl(btnm, 6, LV_BTNMATRIX_CTRL_CHECKABLE);
lv_btnmatrix_set_one_checked(btnm, true);
lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED);
lv_obj_center(btnm);
}
#endif
def event_cb(e):
obj = e.get_target()
id = obj.get_selected_btn()
if id == 0:
prev = True
else:
prev = False
if id == 6:
next = True
else:
next = False
if prev or next:
# Find the checked butto
for i in range(7):
if obj.has_btn_ctrl(i, lv.btnmatrix.CTRL.CHECKED):
break
if prev and i > 1:
i-=1
elif next and i < 5:
i+=1
obj.set_btn_ctrl(i, lv.btnmatrix.CTRL.CHECKED)
#
# Make a button group
#
style_bg = lv.style_t()
style_bg.init()
style_bg.set_pad_all(0)
style_bg.set_pad_gap(0)
style_bg.set_clip_corner(True)
style_bg.set_radius(lv.RADIUS.CIRCLE)
style_bg.set_border_width(0)
style_btn = lv.style_t()
style_btn.init()
style_btn.set_radius(0)
style_btn.set_border_width(1)
style_btn.set_border_opa(lv.OPA._50)
style_btn.set_border_color(lv.palette_main(lv.PALETTE.GREY))
style_btn.set_border_side(lv.BORDER_SIDE.INTERNAL)
style_btn.set_radius(0)
map = [lv.SYMBOL.LEFT,"1","2", "3", "4", "5",lv.SYMBOL.RIGHT, ""]
btnm = lv.btnmatrix(lv.scr_act())
btnm.set_map(map)
btnm.add_style(style_bg, 0)
btnm.add_style(style_btn, lv.PART.ITEMS)
btnm.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None)
btnm.set_size(225, 35)
# Allow selecting on one number at time
btnm.set_btn_ctrl_all(lv.btnmatrix.CTRL.CHECKABLE)
btnm.clear_btn_ctrl(0, lv.btnmatrix.CTRL.CHECKABLE)
btnm.clear_btn_ctrl(6, lv.btnmatrix.CTRL.CHECKABLE)
btnm.set_one_checked(True)
btnm.set_btn_ctrl(1, lv.btnmatrix.CTRL.CHECKED)
btnm.center()
API¶
Typedefs
-
typedef uint16_t
lv_btnmatrix_ctrl_t¶
Enums
-
Type to store button control bits (disabled, hidden etc.) The first 3 bits are used to store the width
Values:
-
enumerator
_LV_BTNMATRIX_WIDTH¶ Reserved to stire the size units
-
enumerator
LV_BTNMATRIX_CTRL_HIDDEN¶ Button hidden
-
enumerator
LV_BTNMATRIX_CTRL_NO_REPEAT¶ Do not repeat press this button.
-
enumerator
LV_BTNMATRIX_CTRL_DISABLED¶ Disable this button.
-
enumerator
LV_BTNMATRIX_CTRL_CHECKABLE¶ The button can be toggled.
-
enumerator
LV_BTNMATRIX_CTRL_CHECKED¶ Button is currently toggled (e.g. checked).
-
enumerator
LV_BTNMATRIX_CTRL_CLICK_TRIG¶ 1: Send LV_EVENT_VALUE_CHANGE on CLICK, 0: Send LV_EVENT_VALUE_CHANGE on PRESS
-
enumerator
LV_BTNMATRIX_CTRL_POPOVER¶ Show a popover when pressing this key
-
enumerator
LV_BTNMATRIX_CTRL_RECOLOR¶ Enable text recoloring with
#color
-
enumerator
_LV_BTNMATRIX_CTRL_RESERVED¶ Reserved for later use
-
enumerator
LV_BTNMATRIX_CTRL_CUSTOM_1¶ Custom free to use flag
-
enumerator
LV_BTNMATRIX_CTRL_CUSTOM_2¶ Custom free to use flag
-
enumerator
Functions
-
LV_EXPORT_CONST_INT(LV_BTNMATRIX_BTN_NONE)¶
-
lv_obj_t *
lv_btnmatrix_create(lv_obj_t *parent)¶ Create a button matrix object
- Parameters
parent -- pointer to an object, it will be the parent of the new button matrix
- Returns
pointer to the created button matrix
-
void
lv_btnmatrix_set_map(lv_obj_t *obj, const char *map[])¶ Set a new map. Buttons will be created/deleted according to the map. The button matrix keeps a reference to the map and so the string array must not be deallocated during the life of the matrix.
- Parameters
obj -- pointer to a button matrix object
map -- pointer a string array. The last string has to be: "". Use "\n" to make a line break.
-
void
lv_btnmatrix_set_ctrl_map(lv_obj_t *obj, const lv_btnmatrix_ctrl_t ctrl_map[])¶ Set the button control map (hidden, disabled etc.) for a button matrix. The control map array will be copied and so may be deallocated after this function returns.
- Parameters
obj -- pointer to a button matrix object
ctrl_map -- pointer to an array of
lv_btn_ctrl_tcontrol bytes. The length of the array and position of the elements must match the number and order of the individual buttons (i.e. excludes newline entries). An element of the map should look like e.g.:ctrl_map[0] = width | LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_TGL_ENABLE
-
void
lv_btnmatrix_set_selected_btn(lv_obj_t *obj, uint16_t btn_id)¶ Set the selected buttons
- Parameters
obj -- pointer to button matrix object
btn_id -- 0 based index of the button to modify. (Not counting new lines)
-
void
lv_btnmatrix_set_btn_ctrl(lv_obj_t *obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl)¶ Set the attributes of a button of the button matrix
- Parameters
obj -- pointer to button matrix object
btn_id -- 0 based index of the button to modify. (Not counting new lines)
ctrl -- OR-ed attributs. E.g.
LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_CHECKABLE
-
void
lv_btnmatrix_clear_btn_ctrl(lv_obj_t *obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl)¶ Clear the attributes of a button of the button matrix
- Parameters
obj -- pointer to button matrix object
btn_id -- 0 based index of the button to modify. (Not counting new lines)
ctrl -- OR-ed attributs. E.g.
LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_CHECKABLE
-
void
lv_btnmatrix_set_btn_ctrl_all(lv_obj_t *obj, lv_btnmatrix_ctrl_t ctrl)¶ Set attributes of all buttons of a button matrix
- Parameters
obj -- pointer to a button matrix object
ctrl -- attribute(s) to set from
lv_btnmatrix_ctrl_t. Values can be ORed.
-
void
lv_btnmatrix_clear_btn_ctrl_all(lv_obj_t *obj, lv_btnmatrix_ctrl_t ctrl)¶ Clear the attributes of all buttons of a button matrix
- Parameters
obj -- pointer to a button matrix object
ctrl -- attribute(s) to set from
lv_btnmatrix_ctrl_t. Values can be ORed.en -- true: set the attributes; false: clear the attributes
-
void
lv_btnmatrix_set_btn_width(lv_obj_t *obj, uint16_t btn_id, uint8_t width)¶ Set a single button's relative width. This method will cause the matrix be regenerated and is a relatively expensive operation. It is recommended that initial width be specified using
lv_btnmatrix_set_ctrl_mapand this method only be used for dynamic changes.- Parameters
obj -- pointer to button matrix object
btn_id -- 0 based index of the button to modify.
width -- relative width compared to the buttons in the same row. [1..7]
-
void
lv_btnmatrix_set_one_checked(lv_obj_t *obj, bool en)¶ Make the button matrix like a selector widget (only one button may be checked at a time).
LV_BTNMATRIX_CTRL_CHECKABLEmust be enabled on the buttons to be selected usinglv_btnmatrix_set_ctrl()orlv_btnmatrix_set_btn_ctrl_all().- Parameters
obj -- pointer to a button matrix object
en -- whether "one check" mode is enabled
-
const char **
lv_btnmatrix_get_map(const lv_obj_t *obj)¶ Get the current map of a button matrix
- Parameters
obj -- pointer to a button matrix object
- Returns
the current map
-
uint16_t
lv_btnmatrix_get_selected_btn(const lv_obj_t *obj)¶ Get the index of the lastly "activated" button by the user (pressed, released, focused etc) Useful in the
event_cbto get the text of the button, check if hidden etc.- Parameters
obj -- pointer to button matrix object
- Returns
index of the last released button (LV_BTNMATRIX_BTN_NONE: if unset)
-
const char *
lv_btnmatrix_get_btn_text(const lv_obj_t *obj, uint16_t btn_id)¶ Get the button's text
- Parameters
obj -- pointer to button matrix object
btn_id -- the index a button not counting new line characters.
- Returns
text of btn_index` button
-
bool
lv_btnmatrix_has_btn_ctrl(lv_obj_t *obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl)¶ Get the whether a control value is enabled or disabled for button of a button matrix
- Parameters
obj -- pointer to a button matrix object
btn_id -- the index of a button not counting new line characters.
ctrl -- control values to check (ORed value can be used)
- Returns
true: the control attribute is enabled false: disabled
Variables
-
const lv_obj_class_t
lv_btnmatrix_class¶
-
struct
lv_btnmatrix_t¶