112 int16_t total_height = 0;
113 int16_t max_width = 0;
115 bool scroll_menu_items =
false;
116 std::vector<display::Rect> menu_dimensions;
117 int number_items_fit_to_screen = 0;
120 for (
size_t i = 0; max_item_index >= 0 && i <= static_cast<size_t>(max_item_index); i++) {
125 menu_dimensions.push_back(item_dimensions);
126 total_height += item_dimensions.
h + (i == 0 ? 0 : y_padding);
127 max_width = std::max(max_width, item_dimensions.
w);
129 if (total_height <= bounds->
h) {
130 number_items_fit_to_screen++;
134 scroll_menu_items =
true;
140 int first_item_index = 0;
141 int last_item_index = max_item_index;
143 if (number_items_fit_to_screen <= 1) {
145 last_item_index = std::min(last_item_index, this->
cursor_index_ + 1);
148 if (scroll_menu_items) {
150 last_item_index = std::min(last_item_index, this->
cursor_index_ + 1);
153 int height_left_to_use = bounds->
h;
154 for (
int i = last_item_index; i >= 0; i--) {
156 height_left_to_use -= (item_dimensions.
h + y_padding);
158 if (height_left_to_use <= 0) {
160 first_item_index = i;
164 const int items_to_draw = last_item_index - first_item_index;
166 if ((this->
cursor_index_ == last_item_index) && (number_items_fit_to_screen <= items_to_draw) &&
167 (first_item_index < max_item_index)) {
176 display->
filled_rectangle(bounds->
x, bounds->
y, max_width, total_height, this->background_color_);
177 auto y_offset = bounds->
y;
178 for (
size_t i =
static_cast<size_t>(first_item_index);
179 last_item_index >= 0 && i <= static_cast<size_t>(last_item_index); i++) {
184 dimensions.
y = y_offset;
185 dimensions.
x = bounds->
x;
186 this->
draw_item_(display, item, &dimensions, selected);
188 y_offset += dimensions.
h + y_padding;
204 std::string label = item->
get_text();
217 dimensions.
w = std::min((int16_t) width, bounds->
w);
218 dimensions.
h = std::min((int16_t) height, bounds->
h);
229 int background_width = bounds->
w;
231 display->
filled_rectangle(bounds->
x, bounds->
y, background_width, bounds->
h, background_color);
233 std::string label = item->
get_text();