feat(tabview) add API to rename tab.

https://github.com/lvgl/lvgl/issues/3407#issue-1265916615
This commit is contained in:
pete-pjb 2022-06-13 12:56:37 +01:00
parent 9a48de0f8b
commit 2c9695afb4
3 changed files with 20 additions and 0 deletions

View File

@ -28,6 +28,10 @@ There are no special parts on the Tab view but the `lv_obj` and `lv_btnnmatrix`
New tabs can be added with `lv_tabview_add_tab(tabview, "Tab name")`. This will return a pointer to an [lv_obj](/widgets/obj) object where the tab's content can be created.
### Rename tabs
A tab can be renamed with `lv_tabview_rename_tab( tabview, tab_id, "New Name" )`.
### Change tab
To select a new tab you can:

View File

@ -121,6 +121,20 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name)
return page;
}
void lv_tabview_rename_tab( lv_obj_t *obj, uint32_t id, const char *new_name )
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_tabview_t * tabview = (lv_tabview_t *)obj;
if(id >= tabview->tab_cnt) return;
if( tabview->tab_pos & LV_DIR_HOR ) id *= 2;
lv_mem_free( tabview->map[id] );
tabview->map[id] = lv_mem_alloc(strlen( new_name )+1 );
strcpy( tabview->map[id], new_name );
lv_obj_invalidate(obj);
}
void lv_tabview_set_act(lv_obj_t * obj, uint32_t id, lv_anim_enable_t anim_en)
{
LV_ASSERT_OBJ(obj, MY_CLASS);

View File

@ -42,6 +42,8 @@ lv_obj_t * lv_tabview_create(lv_obj_t * parent, lv_dir_t tab_pos, lv_coord_t tab
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tv, const char * name);
void lv_tabview_rename_tab( lv_obj_t *obj, uint32_t tab_id, const char *new_name );
lv_obj_t * lv_tabview_get_content(lv_obj_t * tv);
lv_obj_t * lv_tabview_get_tab_btns(lv_obj_t * tv);