Keyboard LV_EVENT_READY on press ok button does not defocus textarea

Description

Properly usage of one keyboard for the complete program.
When i hit the ok button from keyboard we get a LV_EVENT_READY on textarea that does not do what defocus event do.

Assuming that we have 2 textareas When i select the seconde textarea the DEFOCUS event happens to the first one and then i can select the first again.
But when i just hit the OK button from keyboard object, the keyboard is closed and the state of the textarea is back to DEFAULT (cause i call the clear_state to remove the FOCUSED state from the text area), but i can not select again the same textarea to reenable the keyboard. I have to select another textarea so the defocus event to happen first.

What LVGL version are you using?

8.3

What do you want to achieve?

Proper defocus of textarea to able to be reselected immediately when keyboard is closed

What have you tried so far?

Placed some code to identify the state of the obj. I have a keyboard and a textarea event handler to do basic things of hide/show keyboard, remove focus state on closing of the keyboard but re opening of keyboard from the same textarea after it is closed it does not work. Base on another topic the value 34 that i get on selection is hex of pressed and focused which when we have ready event and i remove the focused the textarea is left to default is log shows. In this case i do not know why the defocus event allows the textarea to be selected again.

Code to reproduce



static lv_obj_t* keyboards;

void str_keyboard_event_handler(lv_event_t* e){

//	lv_keyboard_def_event_cb(e);


	lv_obj_t * obj = lv_event_get_target(e);
	lv_keyboard_t * kb = (lv_keyboard_t *)obj;
	const char * txt = lv_keyboard_get_btn_text(kb, lv_keyboard_get_selected_btn(kb));

	if(strcmp(txt, LV_SYMBOL_KEYBOARD) == 0) {
		LV_LOG_USER("keyboard found...");
		lv_event_send(kb->ta, LV_EVENT_READY, NULL);
	};
}

void str_create_keyboard(){

	keyboards=lv_keyboard_create(stringerConf.main_page);
	lv_obj_set_size(keyboards,  LV_HOR_RES, LV_VER_RES / 4);
	lv_keyboard_set_mode(keyboards, LV_KEYBOARD_MODE_TEXT_UPPER);
	lv_obj_add_flag(keyboards, LV_OBJ_FLAG_HIDDEN);
	lv_obj_add_event_cb(keyboards, str_keyboard_event_handler, LV_EVENT_VALUE_CHANGED, NULL);

}
void str_textarea_event_handler(lv_event_t* e){

	lv_event_code_t code = lv_event_get_code(e);
	lv_obj_t * ta = lv_event_get_target(e);
	lv_keyboard_mode_t mode = (lv_keyboard_mode_t)lv_event_get_user_data(e);
	lv_keyboard_set_mode(keyboards, mode);

	switch (code){
		case LV_EVENT_FOCUSED:
			{
			lv_keyboard_set_textarea(keyboards, ta);
			lv_obj_clear_flag(keyboards, LV_OBJ_FLAG_HIDDEN);
			LV_LOG_USER("state in focus: %s",str_get_obj_state(ta));
			}
			break;
		case LV_EVENT_DEFOCUSED:
			{
			lv_keyboard_set_textarea(keyboards, NULL);
			lv_obj_add_flag(keyboards, LV_OBJ_FLAG_HIDDEN);
			LV_LOG_USER("state in defocus: %s",str_get_obj_state(ta));
			}
			break;
		case LV_EVENT_READY:
			{
			LV_LOG_USER("LV_EVENT_READY");
			lv_keyboard_set_textarea(keyboards, NULL);
			lv_obj_add_flag(keyboards, LV_OBJ_FLAG_HIDDEN);
//			lv_state_t taState=lv_obj_get_state(ta);
			LV_LOG_USER("state is: %s",str_get_obj_state(ta));
			lv_obj_clear_state(ta, LV_STATE_FOCUSED);
			LV_LOG_USER("state is: %s",str_get_obj_state(ta));
			lv_obj_clear_state(ta, LV_STATE_EDITED);
			LV_LOG_USER("state is: %s",str_get_obj_state(ta));
                        lv_event_send(ta, LV_EVENT_DEFOCUSED, NULL);
			}
			break;
		case LV_EVENT_VALUE_CHANGED:
			{
				LV_LOG_USER("LV_EVENT_VALUE_CHANGED");
				LV_LOG_USER("key pressed: %s",lv_keyboard_get_btn_text(keyboards, lv_keyboard_get_selected_btn(keyboards)));

			}
			break;
		default:
			LV_LOG_USER("event not on default case: %s",code);
			break;
	}
}

LOG

The next logs are in 3 sections.

  • Initial select of first textarea ,
  • switch on second text area,
  • hit OK button of lv_keyboard in the second textarea
//1 section : Next 2 lines happen On focus of text area (uidentified 34 state will be discussion of another topic is about custom function that i try to return text of the current state of object)
[User]	(4.905, +4905)	 str_get_obj_state: unIdentified state: 34 	(in global_vars.c line #141)
[User]	(4.905, +0)	 str_textarea_event_handler: state in focus: Will check the rest 	(in str_input.c line #118)
// 2 section: Next line happens when i select the second textarea so it defocusses the first
[User]	(8.302, +3397)	 str_textarea_event_handler: state in defocus: LV_STATE_DEFAULT 	(in str_input.c line #125)
// Next 2 lines are the same for the second textarea as in the first
[User]	(8.303, +1)	 str_get_obj_state: unIdentified state: 34 	(in global_vars.c line #141)
[User]	(8.303, +0)	 str_textarea_event_handler: state in focus: Will check the rest 	(in str_input.c line #118)
// 3 section: The next is pressing OK button from lv_keyboard
[User]	(10.556, +2253)	 str_textarea_event_handler: LV_EVENT_READY 	(in str_input.c line #130)
// This row is inside the LV_EVENT_READY from the previous line. I am printing the state of the textarea at that time
[User]	(10.556, +0)	 str_textarea_event_handler: state is: LV_STATE_FOCUSED 	(in str_input.c line #134)
// This row is inside the LV_EVENT_READY from the previous line. I called clear of focus state and I am printing the state of the textarea at that time
[User]	(10.557, +1)	 str_textarea_event_handler: state is: LV_STATE_DEFAULT 	(in str_input.c line #136)
// This row is inside the LV_EVENT_READY from the previous line. I called clear of EDITED state of the textarea at that time
[User]	(10.557, +0)	 str_textarea_event_handler: state is: LV_STATE_DEFAULT 	(in str_input.c line #138)

This was the initial log in code you will see that i have also tried to send defocus on textarea but i also does not fix the issue.

lv_indev_reset(NULL, ta); as someone else in one post has written this is what is needed