It would be nice to be able to create a tabview that only has a single button.
The idea would be to have a default page and a settings page that opens when the button is pressed. It is similar to this post But for example the function lv_tabview_get_tab_btns
doesnt exist anymore.
I guess I could get the buttons with lv_obj_get_child(parent, idx) And modify the “default” button to not show.
I did get a similar effect by creating the tabs manually creating 2 buttons in the tab_bar and 2 pages in the tab_cont and creating myself the callback for the configuration button
In case someone searches for the same effect/function, this is how I did it:
static void setting_btn_click_cb(lv_event_t *e){
lv_obj_t *setting_btn = lv_event_get_current_target(e);
lv_obj_t *tab_cont = lv_tabview_get_content(tabview);
// Usually the task would be taken by
//lv_tabview_set_active(tabview, 1, LV_ANIM_OFF);
// But as teh creation of the tabs hasnt followed the standard procedure, switching has to be done "manually" too
int32_t gap = lv_obj_get_style_pad_column(tab_cont, LV_PART_MAIN);
int32_t w = lv_obj_get_content_width(tab_cont);
uint32_t tab_idx = lv_obj_get_child_count(tab_cont);
if(lv_obj_has_state(setting_btn, LV_STATE_CHECKED) == true){
lv_obj_scroll_to_x(tab_cont, 1 * (gap + w), false);
}else{
lv_obj_scroll_to_x(tab_cont, -1 * (gap + w), false);
}
}
static void header_create(void){
int32_t tab_h = 45;
tabview = lv_tabview_create(lv_screen_active());
lv_tabview_set_tab_bar_position(tabview, LV_DIR_TOP);
lv_tabview_set_tab_bar_size(tabview, tab_h);
// Now we retrieve the tab_bar. The tabview contains 2 elements
// 1. The tab_bar & 2. tab_conf
lv_obj_t * tab_bar = lv_tabview_get_tab_bar(tabview);
lv_obj_t * tab_cont = lv_tabview_get_content(tabview);
// And now comes the tricky thing. The "tabs" which are buttons with associated view in tab_conf
// As I only want a single button in this Tab view, the function
// lv_obj_t * tab_conf = lv_tabview_add_tab(tabview, "Configuration");
// Does not work out for me. I will have to create this by hand
// The plan is to add a single button (Settings), create two tab_confs, and associate the button press to one tab conf or the other
lv_obj_t *default_page = lv_obj_create(tab_cont);
lv_obj_t *setting_page = lv_obj_create(tab_cont);
lv_obj_set_size(default_page, lv_pct(100), lv_pct(100));
lv_obj_set_size(setting_page, lv_pct(100), lv_pct(100));
lv_obj_t *not_used = lv_button_create(tab_bar); // Not used but required for tabview to work as expected
lv_obj_t *setting_btn = lv_button_create(tab_bar); // Create selectable button for settings
lv_obj_set_size(setting_btn, lv_pct(100), lv_pct(100));
//lv_obj_set_state(setting_btn, LV_STATE_PRESSED, false);
lv_obj_add_flag(setting_btn, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_state(setting_btn, LV_STATE_CHECKED, false);
lv_obj_add_event_cb(setting_btn, setting_btn_click_cb, LV_EVENT_CLICKED, NULL);
lv_obj_t *setting_btn_lbl = lv_label_create(setting_btn);
lv_label_set_text(setting_btn_lbl, "Configuration");
lv_obj_center(setting_btn_lbl);
lv_tabview_set_active(tabview, 0, false);
// Create workspace
workspace_create(default_page);
// Set configuration options
settings_create(setting_page);
}