"Back" button and "Menu" button

Hello everyone,
I’m quite new to this lib and I have some questions like this. I have 2 button as matrix button: “Menu” and “Back”.

  1. How can I create callback for each button in the matrix button?
  2. How can I click a button and my screen can update new screen?
  3. How can I click the “Back” button work??

I’m simulating on PC by using visual studio and my LVGL version is 7.9.
I’m looking forward to seeing your reply as soon as possible.
Thanks,
Best reagards,

there is a demo

on btnmatrix, a button pressed’s event is LV_EVENT_VALUE_CHANGED

lv_obj_t * btn_mx;
int_8 btn_index;
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
    if(event == LV_EVENT_VALUE_CHANGED) 
    {
          btn_index=lv_btnmatrix_get_active_btn(btn_mx);

          printf("%d of btn_mx was pressed\n",btn_index );
    }
}

tks. I get it. Do you have any ideas about 2questions left??

the last two question in fact is how to load page.
lv_scr_load(scr),lv_layer_top(),lv_layer_sys()
If you have enough memory, you can pre-create all the pages and then use lv_scr_load(SCR) to switch between them.

If memory is limited, you can use the method of creating the page dynamically, that is, delete the content on the screen first, and then create the page.

I understand your Idea But:

  1. How can I delete all the screen?
  2. My memory is quite small, but It’s enough to run LVGL. If I understand your idea right, in order to use “back” button, I save my last screen into a buffer and when I press this button I load the screen on that buffer right???

I suggest that you should read the documentation carefully first. There are solutions to all of your problems.

1 There is a common delete function for all object types. It deletes the object and all of its children.

void lv_obj_del(lv_obj_t * obj);

lv_obj_del will delete the object immediately. If for any reason you can’t delete the object immediately you can use lv_obj_del_async(obj) . It is useful e.g. if you want to delete the parent of an object in the child’s LV_EVENT_DELETE signal.

You can remove all the children of an object (but not the object itself) using lv_obj_clean :

void lv_obj_clean(lv_obj_t * obj); 

2 you can use lv_src_load() to load last screen in the event callback of back button

1 Like

So I have to delete each object, right? Are there any function that I can delete the whole screen at a time??

screen is object too;

oh okay I get it. Really thanks for your help!!!