当前位置:网站首页>LVGL 8.2 keyboard
LVGL 8.2 keyboard
2022-07-04 13:07:00 【仙剑情缘】
事件回调函数处理
static void ta_event_cb(lv_event_t* e)
{
lv_event_code_t code = lv_event_get_code(e); // 获取对象产生的事件码
lv_obj_t* ta = lv_event_get_target(e); // 获取产生事件的对象
lv_obj_t* kb = lv_event_get_user_data(e); // 获取对象关联的用户数据
if (code == LV_EVENT_FOCUSED) {
// 焦点事件处理
lv_keyboard_set_textarea(kb, ta); // 文本区与键盘关联
lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN); // 清除对象隐藏标志
LV_LOG_USER("%s","LV_EVENT_FOCUSED");
}
if (code == LV_EVENT_DEFOCUSED) {
// 失去焦点事件处理
lv_keyboard_set_textarea(kb, NULL); // 取消文本区与键盘关联
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN); // 添加对象隐藏标志
LV_LOG_USER("%s","LV_EVENT_DEFOCUSED");
}
}
创建文本区和键盘
static void lv_example_keyboard_1(void)
{
/*Create a keyboard to use it with an of the text areas*/
lv_obj_t* kb = lv_keyboard_create(lv_scr_act()); //创建键盘对象
/*Create a text area. The keyboard will write here*/
lv_obj_t* ta;
ta = lv_textarea_create(lv_scr_act()); // 创建文本输入框对象
lv_obj_align(ta, LV_ALIGN_TOP_LEFT, 10, 10); // LV_ALIGN_TOP_LEFT方式对齐
lv_obj_add_event_cb(ta, ta_event_cb, LV_EVENT_ALL, kb); // 文本输入框对象添加所有事件
lv_textarea_set_placeholder_text(ta, "Hello"); // 设置占位字符Hello
lv_obj_set_size(ta, 140, 80); // 设置大小
ta = lv_textarea_create(lv_scr_act()); // 创建文本输入框对象
lv_obj_align(ta, LV_ALIGN_TOP_RIGHT, -10, 10); // LV_ALIGN_TOP_RIGHT方式对齐
lv_obj_add_event_cb(ta, ta_event_cb, LV_EVENT_ALL, kb); // 文本输入框对象添加所有事件
lv_obj_set_size(ta, 140, 80); // 设置大小
lv_keyboard_set_textarea(kb, ta); // 文本区与键盘关联
}
运行效果
在lv_example_keyboard_1函数中添加一个按键测试失去焦点
static void lv_example_keyboard_1(void)
{
/*Create a keyboard to use it with an of the text areas*/
lv_obj_t* kb = lv_keyboard_create(lv_scr_act());
/*Create a text area. The keyboard will write here*/
lv_obj_t* ta;
ta = lv_textarea_create(lv_scr_act());
lv_obj_align(ta, LV_ALIGN_TOP_LEFT, 10, 10);
lv_obj_add_event_cb(ta, ta_event_cb, LV_EVENT_ALL, kb);
lv_textarea_set_placeholder_text(ta, "Hello");
lv_obj_set_size(ta, 140, 80);
ta = lv_textarea_create(lv_scr_act());
lv_obj_align(ta, LV_ALIGN_TOP_RIGHT, -10, 10);
lv_obj_add_event_cb(ta, ta_event_cb, LV_EVENT_ALL, kb);
lv_obj_set_size(ta, 140, 80);
lv_keyboard_set_textarea(kb, ta);
// 以下是新添加的
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN); // 添加键盘隐藏标志
lv_obj_t* btn = lv_btn_create(lv_scr_act()); // 创建按键
lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, 10); //LV_ALIGN_TOP_MID方式对齐
lv_obj_t* label = lv_label_create(btn); // 创建Label对象
lv_label_set_text(label, "Press me"); // 设置Label文本内容
}
运行效果
边栏推荐
- Test evaluation of software testing
- RK1126平台OSD的实现支持颜色半透明度多通道支持中文
- redis 日常笔记
- codeforce:C. Sum of Substrings【边界处理 + 贡献思维 + 灵光一现】
- 關於miui12.5 紅米k20pro用au或者povo2出現問題的解决辦法
- Learn kernel 3: use GDB to track the kernel call chain
- AI与生命科学
- Pandora IOT development board learning (RT thread) - Experiment 3 button experiment (learning notes)
- Detailed index of MySQL
- 卷积神经网络经典论文集合(深度学习分类篇)
猜你喜欢
What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?
商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
Digi restarts XBee Pro S2C production. Some differences need to be noted
flink sql-client. SH tutorial
数据湖(十三):Spark与Iceberg整合DDL操作
Pandora IOT development board learning (RT thread) - Experiment 3 button experiment (learning notes)
Leetcode T48: rotating images
【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程
Data warehouse interview question preparation
Nowcoder rearrange linked list
随机推荐
[algorithm leetcode] interview question 04.03 Specific depth node linked list (Multilingual Implementation)
GCC【6】- 编译的4个阶段
Leetcode T48:旋转图像
Leetcode t49: grouping of alphabetic words
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
Solutions to the problems of miui12.5 red rice k20pro using Au or povo2
第十七章 进程内存
2022游戏出海实用发行策略
C # WPF realizes the real-time screen capture function of screen capture box
Leetcode 61: rotating linked list
【信息检索】链接分析
docker-compose公网部署redis哨兵模式
Digi重启XBee-Pro S2C生产,有些差别需要注意
Rich text editing: wangeditor tutorial
Digi XBee 3 rf: 4 protocols, 3 packages, 10 major functions
Pandora IOT development board learning (RT thread) - Experiment 3 button experiment (learning notes)
gin集成支付宝支付
R language uses follow up of epidisplay package The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The col parameter specifies the
Map of mL: Based on Boston house price regression prediction data set, an interpretable case of xgboost model using map value