ESPHome 2025.5.0
Loading...
Searching...
No Matches
graphical_display_menu.h
Go to the documentation of this file.
1#pragma once
2
7#include <cstdlib>
8
9namespace esphome {
10
11// forward declare from display namespace
12namespace display {
13class Display;
14class DisplayPage;
15class BaseFont;
16class Rect;
17} // namespace display
18
19namespace graphical_display_menu {
20
21const Color COLOR_ON(255, 255, 255, 255);
22const Color COLOR_OFF(0, 0, 0, 0);
23
26 this->item = item;
27 this->is_item_selected = is_item_selected;
28 this->is_menu_editing = is_menu_editing;
29 }
30
34};
35
37 public:
38 void setup() override;
39 void dump_config() override;
40
41 void set_display(display::Display *display);
42 void set_font(display::BaseFont *font);
43 template<typename V> void set_menu_item_value(V menu_item_value) { this->menu_item_value_ = menu_item_value; }
44 void set_foreground_color(Color foreground_color);
45 void set_background_color(Color background_color);
46
47 void add_on_redraw_callback(std::function<void()> &&cb) { this->on_redraw_callbacks_.add(std::move(cb)); }
48
49 void draw(display::Display *display, const display::Rect *bounds);
50
51 protected:
52 void draw_and_update() override;
53 void draw_menu() override;
54 void draw_menu_internal_(display::Display *display, const display::Rect *bounds);
55 void draw_item(const display_menu_base::MenuItem *item, uint8_t row, bool selected) override;
57 const display::Rect *bounds, bool selected);
58 virtual void draw_item(display::Display *display, const display_menu_base::MenuItem *item,
59 const display::Rect *bounds, bool selected);
60 void update() override;
61
62 void on_before_show() override;
63 void on_before_hide() override;
64
65 std::unique_ptr<display::DisplayPage> display_page_{nullptr};
72
74};
75
76class GraphicalDisplayMenuOnRedrawTrigger : public Trigger<const GraphicalDisplayMenu *> {
77 public:
79 parent->add_on_redraw_callback([this, parent]() { this->trigger(parent); });
80 }
81};
82
83} // namespace graphical_display_menu
84} // namespace esphome
Class to display a hierarchical menu.
std::unique_ptr< display::DisplayPage > display_page_
TemplatableValue< std::string, const MenuItemValueArguments * > menu_item_value_
void draw_item(const display_menu_base::MenuItem *item, uint8_t row, bool selected) override
virtual display::Rect measure_item(display::Display *display, const display_menu_base::MenuItem *item, const display::Rect *bounds, bool selected)
void draw_menu_internal_(display::Display *display, const display::Rect *bounds)
const Color COLOR_OFF(0, 0, 0, 0)
const Color COLOR_ON(255, 255, 255, 255)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
MenuItemValueArguments(const display_menu_base::MenuItem *item, bool is_item_selected, bool is_menu_editing)