From b02a19d40da015f50cfd673e0c375651d15eac40 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 13 Sep 2021 22:12:59 +0200 Subject: [PATCH] Display: Add example how to use color (#1278) The docs mentioned only binary displays, but color works just fine. --- components/display/index.rst | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/components/display/index.rst b/components/display/index.rst index a3264dfd1..fcf63d50b 100644 --- a/components/display/index.rst +++ b/components/display/index.rst @@ -89,8 +89,7 @@ and circles: it.filled_circle(25, 25, 10); All the above methods can optionally also be called with an argument at the end which specifies in which -color to draw. Currently, only ``COLOR_ON`` (the default if color is not given) and ``COLOR_OFF`` are supported because -ESPHome only has implemented binary displays. +color to draw. For monochrome displays, only ``COLOR_ON`` (the default if color is not given) and ``COLOR_OFF`` are supported. .. code-block:: yaml @@ -109,6 +108,23 @@ ESPHome only has implemented binary displays. // Turn off a whole display portion. it.rectangle(50, 50, 30, 42, COLOR_OFF); +For color displays (e.g. TFT displays), you can use the Color class. + +.. code-block:: yaml + + display: + - platform: ... + # ... + lambda: |- + auto red = Color(255, 0, 0); + auto green = Color(0, 255, 0); + auto blue = Color(0, 0, 255); + auto white = Color(255, 255, 255); + it.rectangle(20, 50, 30, 30, white); + it.rectangle(25, 55, 30, 30, red); + it.rectangle(30, 60, 30, 30, green); + it.rectangle(35, 65, 30, 30, blue); + Additionally, you have access to two helper methods which will fetch the width and height of the display: .. code-block:: yaml