22#ifdef USE_GRAPHICAL_DISPLAY_MENU
177class DisplayOnPageChangeTrigger;
196 DisplayWriter(F f)
requires std::invocable<F, T &> && std::convertible_to<F, void (*)(T &)>
205 this->
f_ =
new std::function<void(T &)>(std::move(f));
210 if (type_ == LAMBDA) {
211 this->f_ =
new std::function<void(T &)>(*other.
f_);
212 }
else if (type_ == STATELESS_LAMBDA) {
219 if (type_ == LAMBDA) {
222 }
else if (type_ == STATELESS_LAMBDA) {
223 this->stateless_f_ = other.stateless_f_;
230 if (
this != &other) {
238 if (
this != &other) {
246 if (type_ == LAMBDA) {
255 switch (this->type_) {
256 case STATELESS_LAMBDA:
257 this->stateless_f_(display);
260 (*this->f_)(display);
283 std::function<void(T &)> *
f_;
284 void (*stateless_f_)(T &);
291#define LOG_DISPLAY(prefix, type, obj) \
292 if ((obj) != nullptr) { \
295 "%s Rotations: %d °\n" \
296 "%s Dimensions: %dpx x %dpx", \
297 prefix, (obj)->rotation_, prefix, (obj)->get_width(), (obj)->get_height()); \
315 virtual void measure(
const char *str,
int *width,
int *x_offset,
int *baseline,
int *height) = 0;
321 virtual void fill(
Color color);
323 virtual void clear();
326 virtual int get_width() {
return this->get_width_internal(); }
328 virtual int get_height() {
return this->get_height_internal(); }
360 virtual void draw_pixels_at(
int x_start,
int y_start,
int w,
int h,
const uint8_t *ptr,
ColorOrder order,
361 ColorBitness bitness,
bool big_endian,
int x_offset,
int y_offset,
int x_pad);
366 this->draw_pixels_at(x_start, y_start, w,
h, ptr, order, bitness, big_endian, 0, 0, 0);
370 void line(
int x1,
int y1,
int x2,
int y2,
Color color = COLOR_ON);
373 void line_at_angle(
int x,
int y,
int angle,
int length,
Color color = COLOR_ON);
377 void line_at_angle(
int x,
int y,
int angle,
int start_radius,
int stop_radius,
Color color = COLOR_ON);
380 void horizontal_line(
int x,
int y,
int width,
Color color = COLOR_ON);
383 void vertical_line(
int x,
int y,
int height,
Color color = COLOR_ON);
387 void rectangle(
int x1,
int y1,
int width,
int height,
Color color = COLOR_ON);
390 void filled_rectangle(
int x1,
int y1,
int width,
int height,
Color color = COLOR_ON);
393 void circle(
int center_x,
int center_xy,
int radius,
Color color = COLOR_ON);
396 void filled_circle(
int center_x,
int center_y,
int radius,
Color color = COLOR_ON);
400 void filled_ring(
int center_x,
int center_y,
int radius1,
int radius2,
Color color = COLOR_ON);
403 void filled_gauge(
int center_x,
int center_y,
int radius1,
int radius2,
int progress,
Color color = COLOR_ON);
406 void triangle(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
Color color = COLOR_ON);
409 void filled_triangle(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
Color color = COLOR_ON);
419 void get_regular_polygon_vertex(
int vertex_id,
int *vertex_x,
int *vertex_y,
int center_x,
int center_y,
int radius,
421 float rotation_degrees = ROTATION_0_DEGREES);
430 float rotation_degrees = ROTATION_0_DEGREES,
Color color = COLOR_ON,
434 void regular_polygon(
int x,
int y,
int radius,
int edges,
Color color,
441 void filled_regular_polygon(
int x,
int y,
int radius,
int edges,
443 float rotation_degrees = ROTATION_0_DEGREES,
Color color = COLOR_ON);
445 void filled_regular_polygon(
int x,
int y,
int radius,
int edges,
Color color);
458 Color background = COLOR_OFF);
667#ifdef USE_GRAPHICAL_DISPLAY_MENU
690 void get_text_bounds(
int x,
int y,
const char *text,
BaseFont *font,
TextAlign align,
int *x1,
int *y1,
int *width,
697 void show_next_page();
698 void show_prev_page();
700 void set_pages(std::vector<DisplayPage *> pages);
710 void set_auto_clear(
bool auto_clear_enabled) { this->auto_clear_enabled_ = auto_clear_enabled; }
725 void start_clipping(
Rect rect);
727 start_clipping(
Rect(left, top, right - left, bottom - top));
735 void extend_clipping(
Rect rect);
737 this->extend_clipping(
Rect(left, top, right - left, bottom - top));
745 void shrink_clipping(
Rect rect);
747 this->shrink_clipping(
Rect(left, top, right - left, bottom - top));
758 Rect get_clipping()
const;
760 bool is_clipping()
const {
return !this->clipping_rectangle_.empty(); }
764 bool clip(
int x,
int y);
770 bool clamp_x_(
int x,
int w,
int &min_x,
int &max_x);
771 bool clamp_y_(
int y,
int h,
int &min_y,
int &max_y);
776 void clear_clipping_();
787 void filled_flat_side_triangle_(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
Color color);
788 void sort_triangle_points_by_y_(
int *x1,
int *y1,
int *x2,
int *y2,
int *x3,
int *y3);
795 bool auto_clear_enabled_{
true};
797 bool show_test_card_{
false};
806 void set_parent(
Display *parent);
822 void play(
const Ts &...
x)
override {
823 auto *page = this->page_.value(
x...);
824 if (page !=
nullptr) {
834 void play(
const Ts &...
x)
override { this->buffer_->show_next_page(); }
843 void play(
const Ts &...
x)
override { this->buffer_->show_prev_page(); }
853 bool check(
const Ts &...
x)
override {
return this->parent_->get_active_page() == this->page_; }
872const LogString *text_align_to_string(TextAlign textalign);
Base class for all automation conditions.
This class simplifies creating components that periodically check a state.
virtual void measure(const char *str, int *width, int *x_offset, int *baseline, int *height)=0
virtual void print(int x, int y, Display *display, Color color, const char *text, Color background)=0
virtual int get_height() const =0
virtual int get_width() const =0
virtual void draw(int x, int y, Display *display, Color color_on, Color color_off)=0
void shrink_clipping(uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
const DisplayPage * get_active_page() const
int get_native_width()
Get the native (original) width of the display in pixels.
virtual int get_height()
Get the calculated height of the display in pixels with rotation applied.
void add_on_page_change_trigger(DisplayOnPageChangeTrigger *t)
virtual int get_width()
Get the calculated width of the display in pixels with rotation applied.
virtual void draw_pixel_at(int x, int y, Color color)=0
Set a single pixel at the specified coordinates to the given color.
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorOrder order, ColorBitness bitness, bool big_endian)
Convenience overload for base case where the pixels are packed into the buffer with no gaps (e....
virtual DisplayType get_display_type()=0
Get the type of display that the buffer corresponds to.
void start_clipping(int16_t left, int16_t top, int16_t right, int16_t bottom)
DisplayRotation get_rotation() const
virtual int get_width_internal()=0
void draw_pixel_at(int x, int y)
Set a single pixel at the specified coordinates to default color.
int get_native_height()
Get the native (original) height of the display in pixels.
virtual int get_height_internal()=0
void set_auto_clear(bool auto_clear_enabled)
std::vector< DisplayOnPageChangeTrigger * > on_page_change_triggers_
void extend_clipping(int16_t left, int16_t top, int16_t right, int16_t bottom)
std::vector< Rect > clipping_rectangle_
bool check(const Ts &...x) override
void set_page(DisplayPage *page)
DisplayIsDisplayingPageCondition(Display *parent)
void set_from(DisplayPage *p)
DisplayOnPageChangeTrigger(Display *parent)
void set_to(DisplayPage *p)
TEMPLATABLE_VALUE(DisplayPage *, page) void play(const Ts &...x) override
DisplayPageShowNextAction(Display *buffer)
void play(const Ts &...x) override
DisplayPageShowPrevAction(Display *buffer)
void play(const Ts &...x) override
Optimized display writer that uses function pointers for stateless lambdas.
DisplayWriter(DisplayWriter &&other) noexcept
std::function< void(T &)> * f_
DisplayWriter & operator=(DisplayWriter &&other) noexcept
void operator()(T &display) const
enum esphome::display::DisplayWriter::@73 type_
DisplayWriter & operator=(const DisplayWriter &other)
DisplayWriter(const DisplayWriter &other)
const DisplayWriter & operator*() const
DisplayWriter & operator*()
void call(T &display) const
void(* stateless_f_)(T &)
struct @65::@66 __attribute__
@ DISPLAY_ROTATION_0_DEGREES
@ DISPLAY_ROTATION_270_DEGREES
@ DISPLAY_ROTATION_180_DEGREES
@ DISPLAY_ROTATION_90_DEGREES
const Color COLOR_ON(255, 255, 255, 255)
Turn the pixel ON.
const int EDGES_PENTADECAGON
const int EDGES_HEXADECAGON
const int EDGES_DODECAGON
const float ROTATION_45_DEGREES
ImageAlign
ImageAlign is used to tell the display class how to position a image.
const int EDGES_QUADRILATERAL
const int EDGES_TETRADECAGON
const float ROTATION_270_DEGREES
const float ROTATION_180_DEGREES
const int EDGES_HENDECAGON
const int EDGES_TRIDECAGON
TextAlign
TextAlign is used to tell the display class how to position a piece of text.
const float ROTATION_90_DEGREES
const Color COLOR_OFF(0, 0, 0, 0)
Turn the pixel OFF.
const float ROTATION_0_DEGREES
Providing packet encoding functions for exchanging data with a remote host.
A more user-friendly version of struct tm from time.h.