Nvds display clipping (#2659)

* Adding documentation about Clipping

* add example
This commit is contained in:
NP v/d Spek 2023-02-10 21:56:01 +01:00 committed by GitHub
parent 2b031e2a98
commit 6a6c876142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 56 additions and 0 deletions

View File

@ -391,6 +391,62 @@ Displaying Time
You can display current time using a time component. Please see the example :ref:`here <strftime>`.
.. _clipping:
Screen Clipping
***************
Screen clipping is a new set of methods since version 2023.2.0 of esphome. It could be useful when you just want to show
a part of an image or make sure that what you draw on the screen does not go outside a specific region on the screen.
With ``start_clipping(left, top, right, bottom);`` start you the clipping process and when you are done drawing in that region
you can stop the clipping process with ``end_clipping();`` . You can nest as many ``start_clipping();`` as you want as long
you end them as many times as well.
.. code-block:: yaml
binary_sensor:
- platform: ...
# ...
id: my_binary_sensor
color:
- name: my_red
red: 100%
display:
- platform: ...
# ...
lambda: |-
if (id(my_binary_sensor).state) {
it.print(0, 0, id(my_font), "state: ON");
} else {
it.print(0, 0, id(my_font), "state: OFF");
}
// Shorthand:
it.start_clipping(40,0,140,20);
it.printf(0, 0, id(my_font), id(my_red), "State: %s", id(my_binary_sensor).state ? "ON" : "OFF");
it.end_clipping();
After you started clipping you can manipulate the region with ``extend_clipping(left, top, right, bottom);``
and ``shrink_clipping(left, top, right, bottom);`` within previous set clipping region.
With ``get_clipping();`` you get a ``Rect`` object back with the latest set clipping region.
.. code-block:: cpp
class Rect {
int16_t x; ///< X/Left coordinate
int16_t y; ///< Y/Top coordinate
int16_t w; ///< Width
int16_t h; ///< Height
int16_t x2(); ///< Right coordinate
int16_t y2(); ///< bottom coordinate
};
With ``is_clipping();`` tells you if clipping is activated.
.. _config-color: