How to avoid click when screen changes

Hi Team,
I have 2 screens i.e., Screen1 and Screen2
from screen1 i am navigating to screen2 by calling screen2 function on button click
but in screen2 i am still able to click the screen1 button(screen1 is hiding back of screen2)
How to resolve this issue?

Thanks in Advance.

Is Screen 1’s button still visible when you are on Screen 2? Is Screen 2 smaller than Screen 1 (i.e. you want a modal effect)? I don’t completely understand the issue.

No the button in screen1 not visible in screen2
the 2 screens are same size

You could try lv_obj_set_click(screen2, true) to make sure clicks won’t go below the second screen - otherwise I don’t see how this is possible.

Sorry, this one not worked. Added lv_obj_set_click(obj, true) at all my click events in screen 2

Did you add it to screen 2 itself?

Yes Added to screen 2

Okay. Can you please send a screenshot and/or code sample, then? I’m not sure why this is happening.

Screen 1

void switch_list(void)
{

#if LV_IOTGIZMO_WALLPAPER
    lv_obj_t * wp = lv_img_create(lv_disp_get_scr_act(NULL), NULL);
    lv_img_set_src(wp, &white_bg);
    lv_obj_set_protect(wp, LV_PROTECT_POS);
#endif

    	title= lv_img_create(lv_scr_act(), NULL);
        lv_img_set_src(title, &logo);
        lv_obj_align(title, NULL, LV_ALIGN_IN_TOP_MID, 0, 30);

        static lv_style_t style_text;
        lv_style_copy(&style_text, &lv_style_plain);
        style_text.text.font = &roboto_regular_25;
        style_text.text.color=LV_COLOR_WHITE;

        /*Create a label and set new text*/
        message= lv_label_create(lv_disp_get_scr_act(NULL), NULL);
        lv_label_set_style(message, LV_LABEL_STYLE_MAIN, &style_text);
        lv_label_set_recolor(message,true);
        lv_label_set_text(message, "#000000  Switches List");
        lv_obj_align(message,title,LV_ALIGN_IN_BOTTOM_MID,0,40);
        //page_style
        static lv_style_t style_page,style_page1;
        lv_style_copy(&style_page,&lv_style_plain);
        style_page.body.main_color=LV_COLOR_WHITE;

        //page
         page= lv_page_create(lv_scr_act(), NULL);
        lv_obj_set_size(page, 450, 650);
        lv_page_set_style(page,LV_PAGE_STYLE_SCRL,&style_page);
        lv_page_set_style(page,LV_PAGE_STYLE_BG,&style_page);
        lv_obj_align(page, message, LV_ALIGN_OUT_BOTTOM_MID, 0, 30);

        //list_style
        static lv_style_t style_list;
        lv_style_copy(&style_list, &lv_style_plain);
        style_list.body.main_color=LV_COLOR_WHITE;
        style_list.body.radius=2;
        style_list.body.padding.bottom=20;
        style_list.body.padding.top=20;
        style_list.body.padding.left=20;
        style_list.body.padding.right=20;
        style_list.body.border.width=1;
        style_list.body.border.color=LV_COLOR_SILVER;
        static lv_style_t style_list1;
        lv_style_copy(&style_list1, &lv_style_plain);
        style_list1.body.main_color=LV_COLOR_WHITE;
        style_list1.body.radius=2;
        //list
         list= lv_list_create(page, NULL);
        lv_obj_set_width(list, 430);
        lv_obj_set_height(list,600);
        lv_list_set_style(list,LV_LIST_STYLE_BTN_REL,&style_list);
        lv_list_set_style(list,LV_LIST_STYLE_BTN_PR,&style_list);
        lv_list_set_style(list,LV_LIST_STYLE_SCRL,&style_list1);

        const char * txts[] = {&switch_icon, "04e4cc", &switch_icon, "04e4db",NULL};
        uint32_t i;
        for(i=0;txts[i]!=NULL;i+=2){
        	 button=lv_list_add_btn(list,txts[i],txts[i+1]);
        	 lv_obj_set_event_cb(button, event_handler);
        }


}
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
    if(event == LV_EVENT_CLICKED) {
        printf("Clicked: %s\n", lv_list_get_btn_text(obj));
        switches(lv_list_get_btn_text(obj)); //this is how i am redirecting to screen 2
    }
}

screen2

void switches(char *deviceName)
{

#if LV_IOTGIZMO_WALLPAPER
    lv_obj_t * wp = lv_img_create(lv_disp_get_scr_act(NULL), NULL);
    lv_img_set_src(wp, &black_backround);
    lv_obj_set_protect(wp, LV_PROTECT_POS);
#endif
    //style_title
                  lv_style_copy(&style_title, &lv_style_plain);
                  style_title.text.font = &roboto_bold;
                  style_title.text.color=LV_COLOR_WHITE;

                  //style_title_opa_30
                  lv_style_copy(&style_title_opa_30, &lv_style_plain);
                  style_title_opa_30.text.font = &roboto_bold;
                  style_title_opa_30.text.color=LV_COLOR_WHITE;
                  style_title_opa_30.text.opa=LV_OPA_30;
                  //style_title_opa_100
                  lv_style_copy(&style_title_opa_100, &lv_style_plain);
                  style_title_opa_100.text.font = &roboto_bold;
                  style_title_opa_100.text.color=LV_COLOR_WHITE;
                  style_title_opa_100.text.opa=LV_OPA_100;

                  //style_text
                  lv_style_copy(&style_text, &lv_style_plain);
                  style_text.text.font = &roboto_regular_25;
                  style_text.text.color=LV_COLOR_WHITE;

                  //style_img
                  lv_style_copy(&style_img, &lv_style_plain);
                  style_img.image.opa=LV_OPA_30;

                   title= lv_label_create(lv_scr_act(), NULL);
                  lv_label_set_style(title, LV_LABEL_STYLE_MAIN, &style_text);
                  lv_label_set_text(title, deviceName);
                  lv_obj_align(title,NULL,LV_ALIGN_IN_TOP_MID,0,30);

                  //image_button for back
                  lv_obj_t * back = lv_imgbtn_create(lv_scr_act(), NULL);
                  lv_imgbtn_set_src(back, LV_BTN_STATE_REL, &left_arrow);
                  lv_imgbtn_set_src(back, LV_BTN_STATE_PR, &left_arrow);
                  lv_imgbtn_set_src(back, LV_BTN_STATE_TGL_REL, &left_arrow);
                  lv_imgbtn_set_src(back, LV_BTN_STATE_TGL_PR, &left_arrow);
                  lv_obj_align(back, title, LV_ALIGN_CENTER, -200, 0);
                  lv_obj_set_event_cb(back, back_event_handler);
                  lv_obj_set_click(back, true);

                  static lv_point_t line_points[] = { {0, 0},{480,0}};

                  //style_line
                  lv_style_copy(&style_line, &lv_style_plain);
                  style_line.line.color = LV_COLOR_GRAY;
                  style_line.line.width = 3;
                  style_line.line.rounded = 1;

                  lv_obj_t * line1;
                  line1 = lv_line_create(lv_scr_act(), NULL);
                  lv_line_set_points(line1, line_points, 2);
                  lv_line_set_style(line1, LV_LINE_STYLE_MAIN, &style_line);
                  lv_obj_align(line1, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);

                  //style_img2
                  lv_style_copy(&style_img2, &lv_style_plain);
                  style_img2.image.opa=LV_OPA_100;

                  switch_power=lv_imgbtn_create(lv_scr_act(), NULL);
                  lv_imgbtn_set_src(switch_power,LV_BTN_STATE_REL,&turn_on);
                  lv_imgbtn_set_src(switch_power,LV_BTN_STATE_PR,&turn_on);
                  lv_imgbtn_set_src(switch_power, LV_BTN_STATE_TGL_REL, &turn_on);
                  lv_imgbtn_set_src(switch_power, LV_BTN_STATE_TGL_PR, &turn_on);
                  //lv_img_set_style(switch_power,LV_IMG_STYLE_MAIN,&style_img);
                  lv_imgbtn_set_style(switch_power, LV_BTN_STATE_PR, &style_img2);
                  lv_imgbtn_set_style(switch_power, LV_BTN_STATE_TGL_PR, &style_img2);
                  lv_imgbtn_set_style(switch_power, LV_BTN_STATE_REL, &style_img);
                  lv_imgbtn_set_style(switch_power, LV_BTN_STATE_TGL_REL, &style_img);
                  lv_imgbtn_set_toggle(switch_power, true);
                  lv_obj_align(switch_power,NULL,LV_ALIGN_CENTER,0,0);
                  lv_obj_set_event_cb(switch_power, event_handler);
                  lv_obj_set_click(switch_power, true);

                  on_off = lv_label_create(lv_scr_act(), NULL);
                  lv_label_set_style(on_off, LV_LABEL_STYLE_MAIN, &style_title_opa_30);
                  lv_label_set_text(on_off, "OFF");
                  lv_obj_align(on_off,switch_power,LV_ALIGN_OUT_BOTTOM_MID,0,60);

}

When i click on screen 2 at position of list on screen 1 the click event triggered
Example:i have a list in screen1 at top when i click on same position in screen2 the screen 1 list items are triggered

You will need to enable click events on the wallpaper images so that the clicks don’t filter through to the objects below.

May i know how to enable click events on wallpaper images ?

lv_obj_set_click(wp, true) should work. I’m not sure if you tried that yet.

Thanks it worked.

1 Like