mirror of
https://github.com/esphome/esphome-docs.git
synced 2024-09-27 04:13:07 +02:00
Nvds display clipping (#2659)
* Adding documentation about Clipping * add example
This commit is contained in:
parent
5dbd8210ee
commit
eed3d41024
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user