General (lvgl) programming question

I have a very busy screen (2 vertical tank level displays, 2 voltage, 2 current, one arc tank level paired with a water flow fill level, 9 temperature sensors and maybe a few indicators for things like relay open/close…)

I have two groups of temperature sensors, inside and outside. I’m thinking of using “something that looks like a button” (box or actual button), and place several small “LED” indicators inside. That way you can see status at a glance (not actual temperature, just if it’s in range).

So the question is, in lvgl, when you’re adding an object (like the LED) to be placed inside another object (like the box/button), is it better to build them all inside one routine? Or better to have a routine that draws the box/button, then others that create the LEDs?

Sorta like…

draw_box(){
draw_led_1()
draw_led_2()
…}

or
draw_box()
draw_led_1()
draw_led_2()
etc…

It’s probable, that the box/button will be a button, so you can click on it and open up a screen that shows the individual temperature sensors and possibly a graph. But at the moment, it’s going to be just a simple indicator display (one step at a time…)

or am I doing it all wrong and everything should be in one routine?
(I currently have one routine for just about everything, as it makes editing it easier, easier to find items etc…)
Here’s a photo of what I have so far. I still need to add things, and clean it up and make the gradients a bit better looking. But it works, next is connecting all the remote devices (via WiFi and or ESP-NOW, something like 5 more esp32/8266’s).

Hello,

The two options you present do not really matter that much, considering you already have different functions for drawing the box and the leds. That said, I would have a draw_box() function that draws the LEDs inside the box as well.

In my opinion it is more important to have one general draw_led() function that you can reuse. You probably want them all to act sort of similarly.

This may be easier now, but will make your code really hard to read later on, I suggest creating differentes routines (functions) for setting up the different meters.

I see the two meters on either side of the arc are identical, this could be one reusable function already for instance. As well as the two meters on the left hand side, that are stacked onto each other.

Good luck!

Thanks!
I see what you’re saying. I do have “reusable” routines, like update_meter(meter, value). I should have been more clear about that. I do need to clean up a few things, I just realized I could do the same thing with creating the LEDs.

I was more concerned if drawing an object, from inside another object drawing would create issues.

LVGL does not care as long as the pointers when creating the objects are valid.
It should not really matter unless you have a very limited stack size on your device. I would not worry about it too much, generally when drawing something complicated (i.e. multiple objects in one container) I would suggest putting it in one function.

Try start with understanding in LVGL you draw nothing. You add object to screen database, and LVGL in handler render it . On state change rerender usw.