当前位置:网站首页>LVGL8.2 Simple Checkboxes
LVGL8.2 Simple Checkboxes
2022-06-30 10:08:00 【仙剑情缘】
事件回调函数
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) {
//处理值已改变事件
const char* txt = lv_checkbox_get_text(obj); //获取事件对象checkbox的文本内容
const char* state = lv_obj_get_state(obj) & LV_STATE_CHECKED ? "Checked" :"Unchecked"; // 获取事件对象是否选中的状态
LV_LOG_USER("%s: %s", txt, state); // 打印状态内容
}
}
创建多个checkbox
static void lv_example_checkbox_1(void)
{
lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN); // 当前活动界面设置LV_FLEX_FLOW_COLUMN方式布局
lv_obj_set_flex_align(lv_scr_act(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER); // main axis对齐LV_FLEX_ALIGN_CENTER,cross axis放置方式LV_FLEX_ALIGN_START,cross direction对齐LV_FLEX_ALIGN_CENTER
lv_obj_t* cb;
cb = lv_checkbox_create(lv_scr_act()); //创建checkbox对象
lv_checkbox_set_text(cb, "Apple"); //设置文本内容Apple
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL); //添加所有事件
cb = lv_checkbox_create(lv_scr_act()); //创建checkbox对象
lv_checkbox_set_text(cb, "Banana"); //设置文本内容Banana
lv_obj_add_state(cb, LV_STATE_CHECKED); //设置选中状态
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL); //添加所有事件
cb = lv_checkbox_create(lv_scr_act()); //创建checkbox对象
lv_checkbox_set_text(cb, "Lemon"); //设置文本内容Lemon
lv_obj_add_state(cb, LV_STATE_DISABLED); //设置Disabled状态
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL); //添加所有事件
cb = lv_checkbox_create(lv_scr_act()); //创建checkbox对象
lv_obj_add_state(cb, LV_STATE_CHECKED | LV_STATE_DISABLED); //设置CHECKEDTT和Disabled状态
lv_checkbox_set_text(cb, "Melon\nand a new line");//设置文本内容Melon\nand a new line"
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);//添加所有事件
lv_obj_update_layout(cb); // 更新layout
}
运行效果图

边栏推荐
- RobotFramework学习笔记:环境安装以及robotframework-browser插件的安装
- Arm新CPU性能提升22%,最高可组合12核,GPU首配硬件光追,网友:跟苹果的差距越来越大了...
- Robotframework learning notes: environment installation and robotframework browser plug-in installation
- Migrate full RT thread to gd32f4xx (detailed)
- 马斯克推特粉丝过亿了,但他在线失联已一周
- 【深度学习】深度学习检测小目标常用方法
- 前嗅ForeSpider教程:抽取数据
- DQN笔记
- 【Rust每周一库】num-bigint - 大整数
- 技能梳理[email protected]语音模块+stm32+nfc
猜你喜欢
[email protected]+adxl345+电机震动+串口输出"/>技能梳理[email protected]+adxl345+电机震动+串口输出
[email protected] control a dog's running on OLED"/>Skill combing [email protected] control a dog's running on OLED

RobotFramework学习笔记:环境安装以及robotframework-browser插件的安装

mysql数据库基础:存储过程和函数

Kernel linked list (general linked list) "list.h" simple version and individual comments

Qt之实现动效导航栏

GeoffreyHinton:我的五十年深度学习生涯与研究心法

CSDN blog operation team 2022 H1 summary

智能DNA分子纳米机器人模型来了

Machine learning interview preparation (I) KNN
随机推荐
Smith chart view of semi steel coaxial RF line and RF line matching calibration of network analyzer e5071c
R language plot visualization: use plot to visualize the prediction confidence of the multi classification model, the prediction confidence of each data point of the model in the 2D grid, and the conf
How to deploy deflationary combustion destruction contract code in BSC chain_ Deploy dividend and marketing wallet contract code
运动App如何实现端侧后台保活,让运动记录更完整?
Overview of currency
透過華為軍團看科技之變(五):智慧園區
JS FAQs
Leetcode question brushing (II) -- sorting (go Implementation)
Android 开发面试真题进阶版(附答案解析)
Use keil5 software to simulate and debug gd32f305 from 0
Dow Jones Industrial Average
LVGL 8.2 Simple Drop down list
LVGL 8.2 Simple Image button
From introduction to mastery of MySQL 50 lectures (32) -scylladb production environment cluster building
Es common curl finishing
The latest SCI impact factor release: the highest score of domestic journals is 46! Netizen: I understand if
CSDN博客运营团队2022年H1总结
7 大轻量易用的工具,给开发者减压提效,助力企业敏捷上云 | Techo Day 精彩回顾...
My in-depth remote office experience | community essay solicitation
Skill combing [email protected] somatosensory manipulator