ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
rect.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace esphome::display {
6
7static const int16_t VALUE_NO_SET = 32766;
8
9class Rect {
10 public:
11 int16_t x;
12 int16_t y;
13 int16_t w;
14 int16_t h;
15
16 Rect() : x(VALUE_NO_SET), y(VALUE_NO_SET), w(VALUE_NO_SET), h(VALUE_NO_SET) {} // NOLINT
17 inline Rect(int16_t x, int16_t y, int16_t w, int16_t h) ESPHOME_ALWAYS_INLINE : x(x), y(y), w(w), h(h) {}
18 inline int16_t x2() const { return this->x + this->w; };
19 inline int16_t y2() const { return this->y + this->h; };
20
21 inline bool is_set() const ESPHOME_ALWAYS_INLINE { return (this->h != VALUE_NO_SET) && (this->w != VALUE_NO_SET); }
22
23 void expand(int16_t horizontal, int16_t vertical);
24
25 void extend(Rect rect);
26 void shrink(Rect rect);
27
28 bool inside(Rect rect) const;
29 bool inside(int16_t test_x, int16_t test_y, bool absolute = true) const;
30 bool equal(Rect rect) const;
31 void info(const std::string &prefix = "rect info:");
32};
33
34} // namespace esphome::display
int16_t x2() const
Definition rect.h:18
int16_t x
X coordinate of corner.
Definition rect.h:11
int16_t h
Height of region.
Definition rect.h:14
int16_t y
Y coordinate of corner.
Definition rect.h:12
void shrink(Rect rect)
Definition rect.cpp:41
void info(const std::string &prefix="rect info:")
Definition rect.cpp:83
void expand(int16_t horizontal, int16_t vertical)
Definition rect.cpp:9
bool inside(Rect rect) const
Definition rect.cpp:76
Rect(int16_t x, int16_t y, int16_t w, int16_t h) ESPHOME_ALWAYS_INLINE
Definition rect.h:17
bool is_set() const ESPHOME_ALWAYS_INLINE
Y coordinate of corner.
Definition rect.h:21
void extend(Rect rect)
Definition rect.cpp:18
bool equal(Rect rect) const
Definition rect.cpp:62
int16_t y2() const
X coordinate of corner.
Definition rect.h:19
int16_t w
Width of region.
Definition rect.h:13