Anyone know how to rename a tabview tab after its been created?

Description

Id like to rename a tabview tab after it has been created

What MCU/Processor/Board and compiler are you using?

Arduino/ESP32

What LVGL version are you using?

8.2

What do you want to achieve?

As description

What have you tried so far?

    //Update Tab name and Light Label
    lv_obj_t * tab_btns = lv_tabview_get_tab_btns(tv);

    char __lightName[sizeof(lightName)];
    lightName.toCharArray(__lightName, sizeof(lightName));

    const char * map[] = {LV_SYMBOL_HOME, "Temps", "Heating", "Backlight", __lightName, "Info", ""};
    lv_btnmatrix_set_map(tab_btns, map);

Code to reproduce

As above

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.
The commented out section caused a reset, not really what I was hoping for…

Any help would be appreciated

Hi @elgerg ,

I’m sorry but I don’t think there is a way currently to do this unfortunately. Unless @kisvegabor or @embeddedt have any suggestions? The reason it is crashing is because the map[] array needs to be static or global as it is used by reference and not copied to the widgets internals. It’s not elegant but if you have a finite number of ‘__lightNames’ you could define multiple static maps and assign those?

For example:

static const char * map1[] = {LV_SYMBOL_HOME, "Temps", "Heating", "Backlight", "Light 1", "Info", ""};
static const char * map2[] = {LV_SYMBOL_HOME, "Temps", "Heating", "Backlight", "Light 2", "Info", ""};
static const char * map3[] = {LV_SYMBOL_HOME, "Temps", "Heating", "Backlight", "Light 3", "Info", ""};
static const char * map4[] = {LV_SYMBOL_HOME, "Temps", "Heating", "Backlight", "Light 4", "Info", ""};

Apart from that it might be worth considering a different approach maybe?

I hope that is helpful!

Kind Regards,

Pete

Hi Pete,

Thanks for looking into this for me. Unfortunately I do not know beforehand what these names might be. They are supplied by the user using a web form and can be anything. I’d rather not have to pre-think of all of the names and create arrays for every possibility and then re-compile when another name comes up.

If the only option I have would be on initialization then when the form is saved I can reboot the ESP but being able to change the names dynamically would be great.

Thanks
Alex

Hi Alex (@elgerg ),

Here is a real hacky solution but it might get you out of trouble!

    /* Create tabview  */
    tv = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 50);

    lv_obj_t * tab1 = lv_tabview_add_tab(tabview, LV_SYMBOL_HOME);
    lv_obj_t * tab2 = lv_tabview_add_tab(tabview, "Temps");
    lv_obj_t * tab3 = lv_tabview_add_tab(tabview, "Heating");
    lv_obj_t * tab4 = lv_tabview_add_tab(tabview, "Backlight");
    lv_obj_t * tab5 = lv_tabview_add_tab(tabview, __lightName);
    lv_obj_t * tab6 = lv_tabview_add_tab(tabview, "Info");

    /* Code to update tab when __lightName is changed... */
	lv_tabview_t *tvp = (lv_tabview_t *)tv;

	tvp->map[4] = __lightName;
	lv_obj_invalidate(tv);

I hope this works for you!

Kind Regards,

Pete

1 Like

Hi Pete,

I love a good hack!

So the solution is mostly working but I have a slight problem in that I end up with C? instead of the string > char that is specified. It’s probably something I’m missing.

I’m using the Arduino environment for the ESP32 and have the following:

    char __lightName[sizeof(lightName)];
    lightName.toCharArray(__lightName, sizeof(lightName));

    /* Code to update tab when __lightName is changed... */
    lv_tabview_t *tvp = (lv_tabview_t *)tv;

    tvp->map[4] = __lightName;
    lv_obj_invalidate(tv);

Where lightname is a String…

Any idea what stupid mistake I’ve made?

Thanks in advance!
Alex

Ok,

After much messing around I found the solution:

    tvp->map[4] = (char *)lightName.c_str();

Thanks for the help!!

1 Like

Hi Alex,

Glad you solved the problem. :slight_smile:

No worries…

Cheers,

Pete

FYI, in v9 I’m considering to use real buttons (not button matrix) for the tab buttons which will provide much more flexibility. (Even the opportunity to add icons).

2 Likes

Very nice, I look forward to it.

Hi @kisvegabor ,

Can you see here and let me know what you think please :slight_smile:

Cheers,

Pete
cc @elgerg