Best practice for viewports to refresh text

I'm switching from code running on an LCD to code running on a TFT using the Bodmer TFT library (ESP32 CYD, but that's probably not important).

Let's say I'm displaying this using display.printf() on the LCD:

"temperature: 25.6 degrees C"
"humidity: 45%"
"speed: 14.5 kts"

I would like to update the numbers fairly frequently but I don't want to clear/redraw because I want to avoid flicker. Is the best way to create a single viewport, write/draw everything (including text) in the viewport, and redraw that? Or would it be better to create individual viewports for each number (which means figuring out exactly where they will be positioned) and redraw each number's viewport every time I refresh?
If the second way is better, it seems that the library supports one viewport at a time, so I need to recreate each viewport each cycle, correct? (As opposed to creating three and then setting the tft viewport to each one of the three sequentially).

What advantages are there to using viewports as opposed to simply positioning the cursor in the screen and printing the value ?

You have to erase what's already there or the library will just overwrite it and make a bloody mess. ISTR that display.print works fine with the default font, but for any others, you get the big blob of overwritten text.

I ran into this problem but I don't remember how I solved it because all my TFT code these days uses LVGL which takes care of it.

I know, but what does using a viewport bring to the party ? Do you not need to erase what was previously printed when using a viewport ?

Thanks for the tip. I didn't know about LVGL. Looks like I can just update a label and use lv_label_set_text() and it updates with no extra redraw, etc.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.