Navigation problem after closing window

Description

I am using encoder for my UI, i have several buttons that create new window when clicked. Window contains lv_slider widget only. My goal is , to close window when user has finished editing. But i do not see any events that can help me.
For example, flow is :
Window is opened - > focus is moved to slider - > catching LV_EVENT_VALUE_CHANGED -> editing finished -> send enter->close window.

What MCU/Processor/Board and compiler are you using?

STM32F407 custom board

What LVGL version are you using?

v6

What do you want to achieve?

What have you tried so far?

I tried to catch FOCUS events and check if object is in editing or navigation mode.
see code below.
It works partially, when window is closed navigation “stuck” on button

Code to reproduce

static void add_settings_to_input_group()
{
	lv_group_add_obj(g,sens_btn);
	lv_group_add_obj(g,brightness_btn);
	
	lv_group_add_obj(g,back_btn);
}
.....
static void sens_slider_event_cb(lv_obj_t * slider, lv_event_t event)
{

    if(event == LV_EVENT_VALUE_CHANGED) {
        static char buf[5];
        snprintf(buf, 5, "x%u", lv_slider_get_value(slider));
        lv_label_set_text(slider_label, buf);
    }

    if(event == LV_EVENT_FOCUSED) {
    	if ((lv_group_get_editing(lv_obj_get_group(slider)) == false))
           {
           	    	lv_group_remove_all_objs(g);
           	    	     	lv_obj_del_async(sens_win);
           	    	    	add_settings_to_input_group();           	    	  
           }
    }
}
.........
void draw_sensitivity_window()
{
	lv_group_remove_all_objs(g);
	sens_win = lv_win_create(settings_scr, NULL);
	lv_win_set_title(sens_win, "Sensitivity");

	sens_slider = lv_slider_create(sens_win, NULL);

	lv_obj_set_width(sens_slider, LV_DPI * 2);
	lv_obj_align(sens_slider, NULL, LV_ALIGN_CENTER, 0, -30);
	lv_obj_set_event_cb(sens_slider, sens_slider_event_cb);
	lv_slider_set_range(sens_slider, 0, 32);

	slider_label = lv_label_create(sens_win, NULL);
	lv_label_set_text(slider_label, "0");
	lv_obj_set_auto_realign(slider_label, true);
	lv_obj_align(slider_label, sens_slider, LV_ALIGN_OUT_TOP_MID, 0, 10);
	lv_group_add_obj(g, sens_slider);
	lv_group_set_editing(g,true);

}
void draw_settings_menu()
{
            settings_scr  = lv_obj_create(NULL, NULL);
            lv_scr_load(settings_scr);
	    lv_group_remove_all_objs(g);

   	    sens_btn = lv_btn_create(settings_scr, NULL);
	    lv_obj_align(sens_btn, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 0);
	    label = lv_label_create(sens_btn, NULL);
	    lv_label_set_text(label, "Sensitivity - x2");
	    lv_obj_set_size(sens_btn, 300, 30);
	    lv_obj_set_event_cb(sens_btn, settings_sensitivity_handler);
	    lv_group_add_obj(g, sens_btn);
//


	    brightness_btn = lv_btn_create(settings_scr, NULL);
	    lv_obj_align(brightness_btn, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 32);
            label = lv_label_create(brightness_btn, NULL);
	    lv_label_set_text(label, "Brightness - 10");
	    lv_obj_set_size(brightness_btn, 300, 30);
	    lv_obj_set_event_cb(brightness_btn, settings_brightness_handler);
	    lv_group_add_obj(g, brightness_btn);
.....
}

Screenshot and/or video

https://drive.google.com/file/d/1d9A5f1jYTnlkur27tP8VEwJfFYlkxLtf/view?usp=sharing

Hi,

You can fix it like this:

static void sens_slider_event_cb(lv_obj_t * slider, lv_event_t event)
{

    if(event == LV_EVENT_VALUE_CHANGED) {
        static char buf[5];
        snprintf(buf, 5, "x%u", lv_slider_get_value(slider));
        lv_label_set_text(slider_label, buf);
    }

    if(event == LV_EVENT_FOCUSED) {
        if ((lv_group_get_editing(lv_obj_get_group(slider)) == false))
        {
            lv_group_remove_all_objs(g);
            lv_obj_del_async(sens_win);
            add_settings_to_input_group();
            lv_indev_wait_release(lv_indev_get_act());  //add this
        }
    }
}

The problem was that when you delete the slider window while pressing the encoder, the pressing will be sent to the new focused object (the button in the list) and it will go to edit mode. It can be fixed by telling the input device handler to wait until release.

Hi,
sorry for late reply, i am missed your message.
I have redesigned menu, but i am facing another issue using this code.
LV_EVENT_FOCUSED is fired on object create, so my window is closing automatically after showing up.
I read documentation , but i can not find a way to prevent capturing focused event by callback function

Best regards

One approach might be to ignore the first LV_EVENT_FOCUSED.

Hi,
i came to the same conclusion, but i have no idea how to do it

Best Regards

Just create a boolean flag with a default value of true, and set it to false the first time you go into LV_EVENT_FOCUSED.