Composite Objects or copy Objects


How can I or what is a good practice for composite objects? E.g., three labels that are used for name, value, unit and have some common styles like font, but also different for value with different background color.

I can create an object as parent, then add three labels and styles. Is it possible to copy this parent and its childs to create new objects with same style but different text/values?

In v6, the obj_create had two arguments, one for the parent and one as a copy template. I’m not sure if this was only for a copy of styles or copy the whole object tree.

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

general question

What LVGL version are you using?


What do you want to achieve?

simplify screen building with same elements

do you know that you can apply more than one style to a control? so you can make one common style any an other one per label for the differences.

see: using multiple styles

A composite object is in fact a new widget.
You can enhance LVGL by defining custom widgets. Actually some of the core LVGL widgets are “composite objects”. For example, a msgbox is composed from labels, buttons etc.

LVGL docs have a “placeholder” for creating custom widgets, hopefully it will be filled in the future.


thanks for your fast replies.
I have read about multiple styles and this was also my first approach. But this does not solve all, I need to create multiple objects.
Now I will start with using create functions that work like @amirgon showed with the msgbox code, that sounds easier than a copy function.
However, a copy should be also possible. It must do a deep copy and check the class of a type and then call the appropriate create function. And the newly created objects must be found, so that e.g. texts can be changed on labels. I don’t know if this is easier than adding a create function for some composed objects.