24#ifdef USE_GRAPHICAL_DISPLAY_MENU
202 requires std::invocable<F, T &> && std::convertible_to<F, void (*)(T &)>
211 requires std::invocable<F, T &> && (!std::convertible_to<F, void (*)(T &)>)
213 this->
f_ =
new std::function<void(T &)>(std::move(f));
218 if (type_ == LAMBDA) {
219 this->f_ =
new std::function<void(T &)>(*other.
f_);
220 }
else if (type_ == STATELESS_LAMBDA) {
227 if (type_ == LAMBDA) {
230 }
else if (type_ == STATELESS_LAMBDA) {
231 this->stateless_f_ = other.stateless_f_;
238 if (
this != &other) {
246 if (
this != &other) {
254 if (type_ == LAMBDA) {
263 switch (this->type_) {
264 case STATELESS_LAMBDA:
265 this->stateless_f_(display);
268 (*this->f_)(display);
291 std::function<void(T &)> *
f_;
292 void (*stateless_f_)(T &);
300#define LOG_DISPLAY(prefix, type, obj) \
301 if (auto *log_display_obj = (obj); log_display_obj != nullptr) { \
304 "%s Rotations: %d °\n" \
305 "%s Dimensions: %dpx x %dpx", \
306 prefix, log_display_obj->get_rotation(), prefix, log_display_obj->get_width(), \
307 log_display_obj->get_height()); \
325 virtual void measure(
const char *str,
int *width,
int *x_offset,
int *baseline,
int *height) = 0;
331 virtual void fill(
Color color);
333 virtual void clear();
336 virtual int get_width() {
return this->get_width_internal(); }
338 virtual int get_height() {
return this->get_height_internal(); }
371 int x_offset,
int y_offset,
int x_pad) {
388 "Pixels are always RGB: call draw_pixels_at() without the ColorOrder, and override draw_pixels_internal() "
389 "to copy blocks. Removed in 2027.5.0",
391 virtual
void draw_pixels_at(
int x_start,
int y_start,
int w,
int h, const uint8_t *ptr,
ColorOrder order,
392 ColorBitness bitness,
bool big_endian,
int x_offset,
int y_offset,
int x_pad);
395 ESPDEPRECATED("Pixels are always RGB, drop the
ColorOrder argument. Removed in 2027.5.0", "2026.11.0")
396 void draw_pixels_at(
int x_start,
int y_start,
int w,
int h, const uint8_t *ptr,
ColorOrder order,
398#pragma GCC diagnostic push
399#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
400 this->draw_pixels_at(
x_start,
y_start,
w,
h,
ptr,
order,
bitness,
big_endian, 0, 0, 0);
401#pragma GCC diagnostic pop
405 void line(
int x1,
int y1,
int x2,
int y2,
Color color = COLOR_ON);
408 void line_at_angle(
int x,
int y,
int angle,
int length,
Color color = COLOR_ON);
412 void line_at_angle(
int x,
int y,
int angle,
int start_radius,
int stop_radius,
Color color = COLOR_ON);
415 void horizontal_line(
int x,
int y,
int width,
Color color = COLOR_ON);
418 void vertical_line(
int x,
int y,
int height,
Color color = COLOR_ON);
422 void rectangle(
int x1,
int y1,
int width,
int height,
Color color = COLOR_ON);
425 void filled_rectangle(
int x1,
int y1,
int width,
int height,
Color color = COLOR_ON);
428 void circle(
int center_x,
int center_xy,
int radius,
Color color = COLOR_ON);
431 void filled_circle(
int center_x,
int center_y,
int radius,
Color color = COLOR_ON);
435 void filled_ring(
int center_x,
int center_y,
int radius1,
int radius2,
Color color = COLOR_ON);
438 void filled_gauge(
int center_x,
int center_y,
int radius1,
int radius2,
int progress,
Color color = COLOR_ON);
441 void triangle(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
Color color = COLOR_ON);
444 void filled_triangle(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
Color color = COLOR_ON);
454 void get_regular_polygon_vertex(
int vertex_id,
int *vertex_x,
int *vertex_y,
int center_x,
int center_y,
int radius,
456 float rotation_degrees = ROTATION_0_DEGREES);
465 float rotation_degrees = ROTATION_0_DEGREES,
Color color = COLOR_ON,
469 void regular_polygon(
int x,
int y,
int radius,
int edges,
Color color,
476 void filled_regular_polygon(
int x,
int y,
int radius,
int edges,
478 float rotation_degrees = ROTATION_0_DEGREES,
Color color = COLOR_ON);
480 void filled_regular_polygon(
int x,
int y,
int radius,
int edges,
Color color);
493 Color background = COLOR_OFF);
702#ifdef USE_GRAPHICAL_DISPLAY_MENU
725 void get_text_bounds(
int x,
int y,
const char *text,
BaseFont *font,
TextAlign align,
int *x1,
int *y1,
int *width,
732 void show_next_page();
733 void show_prev_page();
735 void set_pages(std::vector<DisplayPage *> pages);
739#ifdef DISPLAY_PAGE_CHANGE_CALLBACK_COUNT
741 this->page_change_callback_.add(std::forward<F>(callback));
749 void set_auto_clear(
bool auto_clear_enabled) { this->auto_clear_enabled_ = auto_clear_enabled; }
770 void start_clipping(
Rect rect);
772 start_clipping(
Rect(left, top, right - left, bottom - top));
780 void extend_clipping(
Rect rect);
782 this->extend_clipping(
Rect(left, top, right - left, bottom - top));
790 void shrink_clipping(
Rect rect);
792 this->shrink_clipping(
Rect(left, top, right - left, bottom - top));
803 Rect get_clipping()
const;
805 bool is_clipping()
const {
return !this->clipping_rectangle_.empty(); }
811 return this->is_clipping() && !this->clipping_rectangle_.back().inside(
x,
y);
816 bool clip(
int x,
int y);
830 virtual void draw_pixels_internal(
int x_start,
int y_start,
int w,
int h,
const uint8_t *ptr,
ColorBitness bitness,
831 bool big_endian,
int x_offset,
int y_offset,
int x_pad);
832 bool clamp_x_(
int x,
int w,
int &min_x,
int &max_x);
833 bool clamp_y_(
int y,
int h,
int &min_y,
int &max_y);
838 void clear_clipping_();
846 if (++this->wdt_pixel_counter_ == 0)
847 this->feed_wdt_pixel_slow_();
849 void feed_wdt_pixel_slow_();
860 void filled_flat_side_triangle_(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
Color color);
861 void sort_triangle_points_by_y_(
int *x1,
int *y1,
int *x2,
int *y2,
int *x3,
int *y3);
866#ifdef DISPLAY_PAGE_CHANGE_CALLBACK_COUNT
869 bool auto_clear_enabled_{
true};
871 uint8_t wdt_pixel_counter_{0};
872 bool show_test_card_{
false};
893inline void Display::show_next_page() { this->page_->
show_next(); }
894inline void Display::show_prev_page() { this->page_->show_prev(); }
900 void play(
const Ts &...
x)
override {
901 auto *page = this->page_.value(
x...);
902 if (page !=
nullptr) {
908const LogString *text_align_to_string(TextAlign textalign);
This class simplifies creating components that periodically check a state.
CallbackManager backed by StaticVector for compile-time-known callback counts.
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
virtual bool pixel_axes_swapped() const
True when draw_pixel_at() swaps x and y before writing, so pixels that are neighbours along x land a ...
StaticCallbackManager< DISPLAY_PAGE_CHANGE_CALLBACK_COUNT, void(DisplayPage *, DisplayPage *)> page_change_callback_
void shrink_clipping(uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
void ESPHOME_ALWAYS_INLINE feed_wdt_per_pixel_()
Watchdog feed for per pixel loops.
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.
virtual DisplayRotation get_rotation() const
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorBitness bitness, bool big_endian)
Convenience overload for base case where the pixels are packed into the buffer with no gaps (e....
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.
bool ESPHOME_ALWAYS_INLINE is_point_clipped(int x, int y) const
Whether (x, y) falls outside the active clipping rectangle.
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)
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.
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad)
Given an array of pixels encoded in the nominated format, draw these into the display's buffer.
int get_native_height()
Get the native (original) height of the display in pixels.
virtual int get_height_internal()=0
void add_on_page_change_callback(F &&callback)
void set_auto_clear(bool auto_clear_enabled)
void extend_clipping(int16_t left, int16_t top, int16_t right, int16_t bottom)
std::vector< Rect > clipping_rectangle_
ESPDEPRECATED("Pixels are always RGB: call draw_pixels_at() without the ColorOrder, and override draw_pixels_internal() " "to copy blocks. Removed in 2027.5.0", "2026.11.0") virtual void draw_pixels_at(int x_start
The block form above with a color order.
void set_next(DisplayPage *next)
void set_parent(Display *parent)
void set_prev(DisplayPage *prev)
TEMPLATABLE_VALUE(DisplayPage *, page) 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::@74 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 &)
@ DISPLAY_ROTATION_0_DEGREES
@ DISPLAY_ROTATION_270_DEGREES
@ DISPLAY_ROTATION_180_DEGREES
@ DISPLAY_ROTATION_90_DEGREES
constexpr Color COLOR_ON(255, 255, 255, 255)
Turn the pixel ON.
constexpr Color COLOR_OFF(0, 0, 0, 0)
Turn the pixel OFF.
static void int int int int const uint8_t ColorOrder ColorBitness bool big_endian
static void int int int int const uint8_t ColorOrder ColorBitness bitness
const int EDGES_PENTADECAGON
const int EDGES_HEXADECAGON
const int EDGES_DODECAGON
const float ROTATION_45_DEGREES
constexpr bool rotation_swaps_axes(DisplayRotation rotation)
Whether a rotation swaps the x and y axes.
ImageAlign
ImageAlign is used to tell the display class how to position a image.
static void int int int int const uint8_t int x_offset
const int EDGES_QUADRILATERAL
static void int int y_start
static void int int int int const uint8_t ColorOrder order
const int EDGES_TETRADECAGON
const float ROTATION_270_DEGREES
static void int int int int const uint8_t int int y_offset
const float ROTATION_180_DEGREES
static void int int int w
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
static void int int int int const uint8_t * ptr
static void int int int int const uint8_t int int int x_pad
const float ROTATION_0_DEGREES
A more user-friendly version of struct tm from time.h.