当前位置:网站首页>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文本内容
}
运行效果
边栏推荐
- Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on GPIO)
- One architecture to complete all tasks - transformer architecture is unifying the AI Jianghu on its own
- Excel快速合并多行数据
- nowcoder重排链表
- Practical puzzle solving | how to extract irregular ROI regions in opencv
- GCC【6】- 编译的4个阶段
- leetcode:6109. 知道秘密的人数【dp的定义】
- 商业智能BI财务分析,狭义的财务分析和广义的财务分析有何不同?
- Respect others' behavior
- Real time data warehouse
猜你喜欢
随机推荐
ViewModel 初体验
Redis daily notes
Nowcoder reverse linked list
[MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control
Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
2022 game going to sea practical release strategy
Some problems and ideas of data embedding point
leetcode:6110. 网格图中递增路径的数目【dfs + cache】
Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
The game goes to sea and operates globally
【云原生】我怎么会和这个数据库杠上了?
Codeforce:c. sum of substrings
LiveData
Industrial Internet has greater development potential and more industry scenarios
RK1126平台OSD的实现支持颜色半透明度多通道支持中文
【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程
SqlServer函数,存储过程的创建和使用
Chapter 16 string localization and message Dictionary (2)
Ruiji takeout notes
Digi restarts XBee Pro S2C production. Some differences need to be noted