Hello,I had a problem recently。
I am currently using lvgl8.4 and 4.3-inch touch screen and it has a keyboard.
When I press a button on the keyboard, I use lv_group_focus_obj(obj) to change the focus of the textarea and draw the focus box, and it works fine. But then when I use touch to click on another textarea, it doesn’t work the first time, so I need to click on the blank space and then click on textarea. Is there any way to solve it?
Every time I manually changed the focus using lv_group_focus_obj(), the first touch focus didn’t work, I had to touch the blank space first
It seems working on my end. Please add a simplified code snippet to reproduce the issue.
Add touchpad and keypad to group.
void lv_add_all_input_devices_to_group(lv_group_t *group) {
if (!group) {
LV_LOG_WARN(
"The group object is NULL. Get the default group object instead.");
group = lv_group_get_default();
if (!group) {
LV_LOG_WARN(
"The default group object is NULL. Create a new group object " "and set it to default instead.");
group = lv_group_create();
if (group) {
lv_group_set_default(group);
}
}
}
ui_group = group;
LV_ASSERT_MSG(group, "Cannot obtain an available group object.");
lv_indev_set_group(indev_touchpad, group);
lv_indev_set_group(indev_keypad, group);
}
Set focus when button pressed.
void set_freq_gui(void) {
set_default_gui();
lv_label_set_text(ui_GuiTitle, "Frequency");
char btn_text[5][30] = {
"Freq Set",
"Incr Set",
"Freq Multi",
"Offset Set",
"More 1 of 2",
};
for (int i = 0; i < sizeof(ui_Button) / sizeof(ui_Button[0]); i++) {
set_button_label_text(i, btn_text[i]);
}
set_freq_incr_pannel();
enter_event_cb = enter_event_set_freq;
button_event_cb[0] = ui_event_set_freq;
button_event_cb[1] = ui_event_set_freq_incr;
button_event_cb[2] = ui_event_set_freq_multi;
button_event_cb[3] = ui_event_set_freq_offset;
button_event_cb[4] = set_freq_gui2;
lv_group_focus_obj(ui_Freq);
}
After the first key press to set focus, the touch was detected, but it did not draw a text box on the textarea, and it worked fine when I touched other locations
I’m testing it with lv_example_textarea_2()
, just added an extra line at the end.
I have a default group set, so the textareas are added to the group automatically. Can you modify this to reproduce the issue?
void lv_example_textarea_2(void)
{
/*Create the password box*/
lv_obj_t * pwd_ta = lv_textarea_create(lv_scr_act());
lv_textarea_set_text(pwd_ta, "");
lv_textarea_set_password_mode(pwd_ta, true);
lv_textarea_set_one_line(pwd_ta, true);
lv_obj_set_width(pwd_ta, lv_pct(40));
lv_obj_set_pos(pwd_ta, 5, 20);
lv_obj_add_event_cb(pwd_ta, ta_event_cb, LV_EVENT_ALL, NULL);
/*Create a label and position it above the text box*/
lv_obj_t * pwd_label = lv_label_create(lv_scr_act());
lv_label_set_text(pwd_label, "Password:");
lv_obj_align_to(pwd_label, pwd_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
/*Create the one-line mode text area*/
lv_obj_t * text_ta = lv_textarea_create(lv_scr_act());
lv_textarea_set_one_line(text_ta, true);
lv_textarea_set_password_mode(text_ta, false);
lv_obj_set_width(text_ta, lv_pct(40));
lv_obj_add_event_cb(text_ta, ta_event_cb, LV_EVENT_ALL, NULL);
lv_obj_align(text_ta, LV_ALIGN_TOP_RIGHT, -5, 20);
/*Create a label and position it above the text box*/
lv_obj_t * oneline_label = lv_label_create(lv_scr_act());
lv_label_set_text(oneline_label, "Text:");
lv_obj_align_to(oneline_label, text_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
/*Create a keyboard*/
kb = lv_keyboard_create(lv_scr_act());
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
lv_keyboard_set_textarea(kb, pwd_ta); /*Focus it on one of the text areas to start*/
lv_group_focus_obj(text_ta); //ADD THIS TO FOCUS THE SECOND TEXT AREA
}
I’m using an external keyboard, not a virtual keyboard.
void lv_port_indev_init(void) {
static lv_indev_drv_t indev_drv;
static lv_indev_drv_t keypad_drv;
static lv_indev_drv_t button_drv;
/*------------------
* touch screen
* -----------------*/
touchpad_init();
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = touchpad_read;
indev_touchpad = lv_indev_drv_register(&indev_drv);
/*------------------
/*------------------
* keyboard
* -----------------*/
keypad_init();
lv_indev_drv_init(&keypad_drv);
keypad_drv.type = LV_INDEV_TYPE_KEYPAD;
keypad_drv.read_cb = keypad_read;
indev_keypad = lv_indev_drv_register(&keypad_drv);
button_init();
lv_indev_drv_init(&button_drv);
button_drv.type = LV_INDEV_TYPE_BUTTON;
button_drv.read_cb = button_read;
indev_button = lv_indev_drv_register(&button_drv);
static const lv_point_t btn_points[8] = {
{ 710, 80 }, /*Button 0 -> x:710; y:80*/
{ 710, 160 }, /*Button 1 -> x:710; y:160*/
{ 710, 245 }, /*Button 2 -> x:710; y:245*/
{ 710, 330 }, /*Button 3 -> x:710; y:330*/
{ 710, 420 }, /*Button 4 -> x:710; y:420*/
};
lv_indev_set_button_points(indev_button, btn_points);
lv_add_all_input_devices_to_group(NULL);
}
void lv_add_all_input_devices_to_group(lv_group_t *group) {
if (!group) {
LV_LOG_WARN(
"The group object is NULL. Get the default group object instead.");
group = lv_group_get_default();
if (!group) {
LV_LOG_WARN(
"The default group object is NULL. Create a new group object " "and set it to default instead.");
group = lv_group_create();
if (group) {
lv_group_set_default(group);
}
}
}
ui_group = group;
LV_ASSERT_MSG(group, "Cannot obtain an available group object.");
lv_indev_set_group(indev_touchpad, group);
lv_indev_set_group(indev_keypad, group);
}
I had no problem pressing the physical button and changing the focus box using lv_group_focus_obj(ui_Freq).
Then I touch the other textarea with my hand and the focus doesn’t change.
I’ve also used my notebooks keyboard.
I will try again to find the problem,Thanks.