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();