当前位置:网站首页>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文本内容
}
运行效果
边栏推荐
- Leetcode t49: grouping of alphabetic words
- [information retrieval] link analysis
- Detailed explanation of visual studio debugging methods
- Opencv3.2 and opencv2.4 installation
- The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
- Test process arrangement (2)
- 软件测试之测试评估
- MySQL stored procedure exercise
- 架构方面的进步
- Abnormal value detection using shap value
猜你喜欢
Excel quickly merges multiple rows of data
[MySQL from introduction to proficiency] [advanced chapter] (V) SQL statement execution process of MySQL
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
Xcode 异常图片导致ipa包增大问题
Nowcoder reverse linked list
Chapter 17 process memory
【信息检索】链接分析
商业智能BI财务分析,狭义的财务分析和广义的财务分析有何不同?
Vscode common plug-ins summary
富文本编辑:wangEditor使用教程
随机推荐
GCC [6] - 4 stages of compilation
The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
MATLAB中tiledlayout函数使用
Abnormal value detection using shap value
MySQL stored procedure exercise
Test process arrangement (3)
ML之shap:基于boston波士顿房价回归预测数据集利用Shap值对LiR线性回归模型实现可解释性案例
R language uses bwplot function in lattice package to visualize box plot and par Settings parameter custom theme mode
LiveData
R language ggplot2 visualization: gganimate package creates dynamic line graph animation (GIF) and uses transition_ The reveal function displays data step by step along a given dimension in the animat
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
Digi XBee 3 RF: 4个协议,3种封装,10个大功能
AI与生命科学
Innovation and development of independent industrial software
ViewModel 初体验
按照功能对Boost库进行分类
One architecture to complete all tasks - transformer architecture is unifying the AI Jianghu on its own
Leetcode t47: full arrangement II
数据仓库面试问题准备
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]