Align or set position of a screen?

Is it possible to align or set position of a screen? I am designing a UI which consist of a status-bar on the top, and it should be visible on all screens. So I wanted to keep it fixed, and declare everything else on different screens. That is why in the below code i have set the height of a 240x240 screen to 240-20. But then I have to align it. I have tried to set the position as below but it has no effect.
Is there any way to achieve that?

main_menu_scr = lv_obj_create(NULL, NULL);
lv_obj_set_size(main_menu_scr, 240, 240-20); 
lv_obj_set_pos(main_menu_scr, 0, 20);

The screens shouldn’t be positioned manually.

You can create an lv_obj the has a smaller size and the offseted positioned and create the objects of the screen there instead of the screen.

Thanks for your reply. I have realized it after experimenting a bit.
So, can you suggest me how can i achieve the above requirement?
I think I should go with tab_view, will remove the header (is it possible?) but I am not sure.

There are 2 special layers in lvgl: Top and sys layers that are always drawn on top of the active screen. The lv_layer_top() and lv_layer_sys() functions gives a pointer to the top or system layer.

Add your status-bar as a child of the top layer to display that object on all screens:

my_status_bar = lv_obj_create(lv_layer_top(), NULL);
1 Like

That’s great, thanks. I will try your suggestion and will report back.

EDIT: yup it worked! Thanks.

1 Like

@fvanroie @kisvegabor is there a way to put an object always behind all the screens? just opposite to what I did with the statusbar?

You can move objects to the foreground or background on a screen.

lv_obj_move_background(my_status_bar);

will move the statusbar behind any other object on the screen (or layer).

1 Like