9 namespace graphical_display_menu {
11 static const char *
const TAG =
"graphical_display_menu";
16 this->
display_page_ = make_unique<display::DisplayPage>(writer);
21 std::string label =
" ";
22 if (it->is_item_selected && it->is_menu_editing) {
24 label.append(it->item->get_value_text());
28 label.append(it->item->get_value_text());
39 ESP_LOGCONFIG(TAG,
"Graphical Display Menu");
40 ESP_LOGCONFIG(TAG,
"Has Display: %s", YESNO(this->
display_ !=
nullptr));
41 ESP_LOGCONFIG(TAG,
"Popup Mode: %s", YESNO(this->
display_ !=
nullptr));
42 ESP_LOGCONFIG(TAG,
"Advanced Drawing Mode: %s", YESNO(this->
display_ ==
nullptr));
43 ESP_LOGCONFIG(TAG,
"Has Font: %s", YESNO(this->
font_ !=
nullptr));
45 ESP_LOGCONFIG(TAG,
"Active: %s", YESNO(this->
active_));
46 ESP_LOGCONFIG(TAG,
"Menu items:");
49 ESP_LOGCONFIG(TAG,
" %i: %s (Type: %s, Immediate Edit: %s)", i, item->get_text().c_str(),
51 YESNO(item->get_immediate_edit()));
77 this->previous_display_page_ =
nullptr;
95 ESP_LOGE(TAG,
"draw_menu() called without a display_. This is only available when using the menu in pop up mode");
107 int16_t total_height = 0;
108 int16_t max_width = 0;
110 bool scroll_menu_items =
false;
111 std::vector<display::Rect> menu_dimensions;
112 int number_items_fit_to_screen = 0;
115 for (
size_t i = 0; i <= max_item_index; i++) {
120 menu_dimensions.push_back(item_dimensions);
121 total_height += item_dimensions.
h + (i == 0 ? 0 : y_padding);
122 max_width = std::max(max_width, item_dimensions.
w);
124 if (total_height <= bounds->
h) {
125 number_items_fit_to_screen++;
129 scroll_menu_items =
true;
135 int first_item_index = 0;
136 int last_item_index = max_item_index;
138 if (number_items_fit_to_screen <= 1) {
140 last_item_index = std::min(last_item_index, this->
cursor_index_ + 1);
143 if (scroll_menu_items) {
145 last_item_index = std::min(last_item_index, this->
cursor_index_ + 1);
148 int height_left_to_use = bounds->
h;
149 for (
int i = last_item_index; i >= 0; i--) {
151 height_left_to_use -= (item_dimensions.
h + y_padding);
153 if (height_left_to_use <= 0) {
155 first_item_index = i;
159 const int items_to_draw = last_item_index - first_item_index;
161 if ((this->
cursor_index_ == last_item_index) && (number_items_fit_to_screen <= items_to_draw) &&
162 (first_item_index < max_item_index)) {
171 display->
filled_rectangle(bounds->
x, bounds->
y, max_width, total_height, this->background_color_);
172 auto y_offset = bounds->
y;
173 for (
size_t i = first_item_index; i <= last_item_index; i++) {
178 dimensions.
y = y_offset;
179 dimensions.
x = bounds->
x;
180 this->
draw_item(display, item, &dimensions, selected);
182 y_offset += dimensions.
h + y_padding;
198 std::string label = item->
get_text();
211 dimensions.
w = std::min((int16_t) width, bounds->
w);
212 dimensions.
h = std::min((int16_t) height, bounds->
h);
223 int background_width = bounds->
w;
225 display->
filled_rectangle(bounds->
x, bounds->
y, background_width, bounds->
h, background_color);
227 std::string label = item->
get_text();
238 ESP_LOGE(TAG,
"draw_item(MenuItem *item, uint8_t row, bool selected) called. The graphical_display_menu specific " 239 "draw_item should be called.");
void get_text_bounds(int x, int y, const char *text, BaseFont *font, TextAlign align, int *x1, int *y1, int *width, int *height)
Get the text bounds of the given string.
int16_t x
X coordinate of corner.
void filled_rectangle(int x1, int y1, int width, int height, Color color=COLOR_ON)
Fill a rectangle with the top left point at [x1,y1] and the bottom right point at [x1+width...
const DisplayPage * get_active_page() const
int16_t h
Height of region.
virtual int get_width()
Get the calculated width of the display in pixels with rotation applied.
int16_t y
Y coordinate of corner.
std::function< void(Display &)> display_writer_t
virtual void setup()
Where the component's initialization should happen.
void start_clipping(Rect rect)
Set the clipping rectangle for further drawing.
void clear()
Clear the entire screen by filling it with OFF pixels.
void print(int x, int y, BaseFont *font, Color color, TextAlign align, const char *text, Color background=COLOR_OFF)
Print text with the anchor point at [x,y] with font.
void end_clipping()
Reset the invalidation region.
virtual int get_height()
Get the calculated height of the display in pixels with rotation applied.
Implementation of SPI Controller mode.
void show_page(DisplayPage *page)
int16_t w
Width of region.