1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

widget tableview: add function lv_tabview_set_tab_name() to change a tab name

This commit is contained in:
Michael Katzenberger 2020-07-12 11:46:12 +02:00
parent 43a77d8699
commit 6cb79914a8
2 changed files with 38 additions and 0 deletions

View File

@ -448,6 +448,36 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t an
lv_btnmatrix_set_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNMATRIX_CTRL_CHECK_STATE);
}
/**
* Set the name of a tab.
* @param tabview pointer to Tab view object
* @param id index of a tab to load
* @param name new tab name
*/
void lv_tabview_set_tab_name(lv_obj_t *tabview, uint16_t id, char *name)
{
LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
// get tabview's ext pointer which contains the tab name pointer list
lv_tabview_ext_t *ext = lv_obj_get_ext_attr(tabview);
// check for valid tab index
if (ext->tab_cnt > id)
{
// reallocate memory for new tab name (use reallocate due to mostly the size didn't change much)
char *str = lv_mem_realloc((void *)ext->tab_name_ptr[id], strlen(name) + 1);
LV_ASSERT_MEM(str);
// store new tab name at allocated memory
strcpy(str, name);
// update pointer
ext->tab_name_ptr[id] = str;
// force redrawing of the tab headers
lv_obj_invalidate(ext->btns);
}
}
/**
* Set the animation time of tab view when a new tab is loaded
* @param tabview pointer to Tab view object

View File

@ -119,6 +119,14 @@ void lv_tabview_clean_tab(lv_obj_t * tab);
*/
void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t anim);
/**
* Set the name of a tab.
* @param tabview pointer to Tab view object
* @param id index of a tab to load
* @param name new tab name
*/
void lv_tabview_set_tab_name(lv_obj_t * tabview, uint16_t id, char * name);
/**
* Set the animation time of tab view when a new tab is loaded
* @param tabview pointer to Tab view object