当前位置:网站首页>LVGL 8.2 Checkboxes as radio buttons
LVGL 8.2 Checkboxes as radio buttons
2022-06-30 10:53:00 【Fairy sword love】
Variable definitions
static lv_style_t style_radio;
static lv_style_t style_radio_chk;
static uint32_t active_index_1 = 0;
static uint32_t active_index_2 = 0;
Event handling callback function
static void radio_event_handler(lv_event_t* e)
{
uint32_t* active_id = lv_event_get_user_data(e); // Get user data
lv_obj_t* cont = lv_event_get_current_target(e); // Get the layout object of the current target event
lv_obj_t* act_cb = lv_event_get_target(e);// Get the object that generated the event
lv_obj_t* old_cb = lv_obj_get_child(cont, *active_id); // according to id Sequence number get sub object
/*Do nothing if the container was clicked*/
if (act_cb == cont) return; // Don't deal with layout Events generated by layout objects
lv_obj_clear_state(old_cb, LV_STATE_CHECKED); // Clear previous selection status
lv_obj_add_state(act_cb, LV_STATE_CHECKED); // Set the clicked object as selected
*active_id = lv_obj_get_index(act_cb); // Get the... Of the selected object id Serial number and save in active_id In the memory pointed to
LV_LOG_USER("Selected radio buttons: %d, %d", (int)active_index_1, (int)active_index_2); // Print active_index_1,active_index_2
}
radio establish
static void radiobutton_create(lv_obj_t* parent, const char* txt)
{
lv_obj_t* obj = lv_checkbox_create(parent); // stay parent Create on object checkbox object
lv_checkbox_set_text(obj, txt); // Set the text to txt What's in the pointer
lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE); // add to LV_OBJ_FLAG_EVENT_BUBBLE sign
lv_obj_add_style(obj, &style_radio, LV_PART_INDICATOR); //obj Object's LV_PART_INDICATO The Properties section uses style_radio
lv_obj_add_style(obj, &style_radio_chk, LV_PART_INDICATOR | LV_STATE_CHECKED); // obj Object's LV_PART_INDICATO and LV_STATE_CHECKED The Properties section uses style_radio_chk
}
Checkboxes as radio buttons
/** * Checkboxes as radio buttons */
static void lv_example_checkbox_2(void)
{
/* The idea is to enable `LV_OBJ_FLAG_EVENT_BUBBLE` on checkboxes and process the * `LV_EVENT_CLICKED` on the container. * A variable is passed as event user data where the index of the active * radiobutton is saved */
lv_style_init(&style_radio); // Initial timing style_radio
lv_style_set_radius(&style_radio, LV_RADIUS_CIRCLE); // Set chamfer to circular
lv_style_init(&style_radio_chk); // Initial timing style_radio_chk
lv_style_set_bg_img_src(&style_radio_chk, NULL); // Set the background icon resource to NULL
uint32_t i;
char buf[32];
lv_obj_t* cont1 = lv_obj_create(lv_scr_act()); // Create an object for layout
lv_obj_set_flex_flow(cont1, LV_FLEX_FLOW_COLUMN);// Set the layout to LV_FLEX_FLOW_COLUMN The way
lv_obj_set_size(cont1, lv_pct(40), lv_pct(80)); // Set size
lv_obj_add_event_cb(cont1, radio_event_handler, LV_EVENT_CLICKED, &active_index_1); // add to LV_EVENT_CLICKED event , User defined data is active_index_1
for (i = 0; i < 5; i++) {
lv_snprintf(buf, sizeof(buf), "A %d", (int)i + 1);
radiobutton_create(cont1, buf); // Co created 5 individual radio Key
}
/*Make the first checkbox checked*/
lv_obj_add_state(lv_obj_get_child(cont1, 0), LV_STATE_CHECKED); // Select the first 1 individual radio
lv_obj_t* cont2 = lv_obj_create(lv_scr_act()); // Create an object for layout
lv_obj_set_flex_flow(cont2, LV_FLEX_FLOW_COLUMN);// Set the layout to LV_FLEX_FLOW_COLUMN The way
lv_obj_set_size(cont2, lv_pct(40), lv_pct(80)); // Set size
lv_obj_set_x(cont2, lv_pct(50)); // Set up cont2 Layout x The position is screen mu 50% It's about
lv_obj_add_event_cb(cont2, radio_event_handler, LV_EVENT_CLICKED, &active_index_2);// add to LV_EVENT_CLICKED event , User defined data is active_index_2
for (i = 0; i < 3; i++) {
lv_snprintf(buf, sizeof(buf), "B %d", (int)i + 1);
radiobutton_create(cont2, buf); // Co created 3 individual radio Key
}
/*Make the first checkbox checked*/
lv_obj_add_state(lv_obj_get_child(cont2, 0), LV_STATE_CHECKED);// Select the first 1 individual radio
}
Running effect

take radiobutton_create Function lv_obj_add_flag Comment out
static void radiobutton_create(lv_obj_t* parent, const char* txt)
{
lv_obj_t* obj = lv_checkbox_create(parent);
lv_checkbox_set_text(obj, txt);
// lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_add_style(obj, &style_radio, LV_PART_INDICATOR);
lv_obj_add_style(obj, &style_radio_chk, LV_PART_INDICATOR | LV_STATE_CHECKED);
}
Running effect

边栏推荐
- The two e-commerce bigwigs' lacy news screens represent the return of e-commerce to normal, which will be beneficial to the real economy
- Voir le changement technologique à travers la Légion Huawei (5): Smart Park
- Sarsa笔记
- 程序员需知的 59 个网站
- LVGL 8.2 Image styling and offset
- Auto SEG loss: automatic loss function design
- Qt之实现动效导航栏
- pytorch 筆記 torch.nn.BatchNorm1d
- [STL source code analysis] container (to be supplemented)
- Dow Jones Industrial Average
猜你喜欢

7 大轻量易用的工具,给开发者减压提效,助力企业敏捷上云 | Techo Day 精彩回顾...

腾讯云数据库工程师能力认证重磅推出,各界共话人才培养难题

Musk has more than 100 million twitter fans, but he has been lost online for a week

科普达人丨漫画图解什么是eRDMA?

pytorch 筆記 torch.nn.BatchNorm1d

Sarsa笔记

Auto SEG loss: automatic loss function design

LVGL 8.2 Image

机器学习面试准备(一)KNN

The intelligent DNA molecular nano robot model is coming
随机推荐
scratch绘制正方形 电子学会图形化编程scratch等级考试二级真题和答案解析2022年6月
透过华为军团看科技之变(五):智慧园区
Q-Learning笔记
Using LVM to resize partitions
滴滴开源敏捷测试用例管理平台!
Pytorch notes torch nn. BatchNorm1d
Skill combing [email protected] voice module +stm32+nfc
机器学习面试准备(一)KNN
Dow Jones Industrial Average
LVGL8.2 Simple Checkboxes
My in-depth remote office experience | community essay solicitation
历史上的今天:微软收购 PowerPoint 开发商;SGI 和 MIPS 合并
Anhui "requirements for design depth of Hefei fabricated building construction drawing review" was printed and distributed; Hebei Hengshui city adjusts the pre-sale license standard for prefabricated
Memory escape analysis
June training (day 30) - topology sorting
Skill combing [email protected] control a dog's running on OLED
pytorch 筆記 torch.nn.BatchNorm1d
苹果高管公然“开怼”:三星抄袭 iPhone,只加了个大屏
Qt之实现动效导航栏
[STL source code analysis] iterator