110 int16_t total_height = 0;
111 int16_t max_width = 0;
113 bool scroll_menu_items =
false;
114 std::vector<display::Rect> menu_dimensions;
115 int number_items_fit_to_screen = 0;
118 for (
size_t i = 0; max_item_index >= 0 && i <= static_cast<size_t>(max_item_index); i++) {
123 menu_dimensions.push_back(item_dimensions);
124 total_height += item_dimensions.
h + (i == 0 ? 0 : y_padding);
125 max_width = std::max(max_width, item_dimensions.
w);
127 if (total_height <= bounds->
h) {
128 number_items_fit_to_screen++;
132 scroll_menu_items =
true;
138 int first_item_index = 0;
139 int last_item_index = max_item_index;
141 if (number_items_fit_to_screen <= 1) {
143 last_item_index = std::min(last_item_index, this->
cursor_index_ + 1);
146 if (scroll_menu_items) {
148 last_item_index = std::min(last_item_index, this->
cursor_index_ + 1);
151 int height_left_to_use = bounds->
h;
152 for (
int i = last_item_index; i >= 0; i--) {
154 height_left_to_use -= (item_dimensions.
h + y_padding);
156 if (height_left_to_use <= 0) {
158 first_item_index = i;
162 const int items_to_draw = last_item_index - first_item_index;
164 if ((this->
cursor_index_ == last_item_index) && (number_items_fit_to_screen <= items_to_draw) &&
165 (first_item_index < max_item_index)) {
174 display->
filled_rectangle(bounds->
x, bounds->
y, max_width, total_height, this->background_color_);
175 auto y_offset = bounds->
y;
176 for (
size_t i =
static_cast<size_t>(first_item_index);
177 last_item_index >= 0 && i <= static_cast<size_t>(last_item_index); i++) {
182 dimensions.
y = y_offset;
183 dimensions.
x = bounds->
x;
184 this->
draw_item(display, item, &dimensions, selected);
186 y_offset += dimensions.
h + y_padding;
202 std::string label = item->
get_text();
215 dimensions.
w = std::min((int16_t) width, bounds->
w);
216 dimensions.
h = std::min((int16_t) height, bounds->
h);