Display Component - Highlighting text

Using the ESPHome Display component for a ssd1306, I’ve worked out how to print white text on a black background, but now wish to be able to print highlighted text (black text on a white back ground). How can this be done?
Background Info: this is to display a temperature reading from a DHT11 (white on black), then highlight the number (black on white) if it is too cold ( e.g. heating is ON).
Any help would be much appreciated.:slight_smile:

I’m assuming you don’t want to just clear/fill the whole display, every time you print a value, so I would find the rectangle (x,y,w,h) covering the printed text and just fill the background before printing the text. I haven’t tested this, but something like:

White text on Black background

it.filled_rectangle(0, 0, 80, 20, COLOR_OFF);
it.printf(0, 0, id(my_font), COLOR_ON, "Temperature: %.1f", id(dht11).state);

Black text on white background

it.filled_rectangle(0, 0, 80, 20, COLOR_ON);
it.printf(0, 0, id(my_font), COLOR_OFF, "Temperature: %.1f", id(dht11).state);

@zenzay42 - Thank you. Spot on, it worked just how I want it. :slight_smile:

I happy it worked for you. I happen to be fiddling with displays in ESPHome at the moment myself :slight_smile:

Don’t forget that you can also use images. I use images on my latest project to good effect. I have quite a lot on the screen and can’t be bothered to draw every line, so I’ve created some transparent ‘framing’ images in GIMP and use those as background.