How to repurpose a widget


I would like to ask if its possible to repurpose widgets by changing them into different types. IE I created an image widget using lv_img_create and I would like to change this widget to a label widget. If its possible, what is the safest way to do this?

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

irrelevant to this question

What LVGL version are you using?


What do you want to achieve?

Reduce number of widgets by repurposing some based on the context

What have you tried so far?


Code to reproduce


The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

It’s not really possible to repurpose widgets like this, as they each have custom rendering handlers and private data. It would make more sense to delete the image and create a label in its place.

May I ask why you are trying to do this? Perhaps there is a more LVGL-friendly solution.

We are very memory limited on our project. On one screen we have 3 image labels and another 3 text labels, on another screen we have 6 text labels, naturally we can use the 3 text labels from the previous screen but it would be nice to not have the other 3 text labels around but rather repurpose the existing three image labels, but by the sound of it this is not possible which makes sense, but I figured asking does not hurt

That makes sense. The standard approach here is to delete the labels from the screen which is not in use, if that is possible. That way only the visible widgets take up memory.