108 int16_t total_height = 0;
109 int16_t max_width = 0;
111 bool scroll_menu_items =
false;
112 std::vector<display::Rect> menu_dimensions;
113 int number_items_fit_to_screen = 0;
116 for (
size_t i = 0; max_item_index >= 0 && i <= static_cast<size_t>(max_item_index); i++) {
121 menu_dimensions.push_back(item_dimensions);
122 total_height += item_dimensions.
h + (i == 0 ? 0 : y_padding);
123 max_width = std::max(max_width, item_dimensions.
w);
125 if (total_height <= bounds->
h) {
126 number_items_fit_to_screen++;
130 scroll_menu_items =
true;
136 int first_item_index = 0;
137 int last_item_index = max_item_index;
139 if (number_items_fit_to_screen <= 1) {
141 last_item_index = std::min(last_item_index, this->
cursor_index_ + 1);
144 if (scroll_menu_items) {
146 last_item_index = std::min(last_item_index, this->
cursor_index_ + 1);
149 int height_left_to_use = bounds->
h;
150 for (
int i = last_item_index; i >= 0; i--) {
152 height_left_to_use -= (item_dimensions.
h + y_padding);
154 if (height_left_to_use <= 0) {
156 first_item_index = i;
160 const int items_to_draw = last_item_index - first_item_index;
162 if ((this->
cursor_index_ == last_item_index) && (number_items_fit_to_screen <= items_to_draw) &&
163 (first_item_index < max_item_index)) {
172 display->
filled_rectangle(bounds->
x, bounds->
y, max_width, total_height, this->background_color_);
173 auto y_offset = bounds->
y;
174 for (
size_t i =
static_cast<size_t>(first_item_index);
175 last_item_index >= 0 && i <= static_cast<size_t>(last_item_index); i++) {
180 dimensions.
y = y_offset;
181 dimensions.
x = bounds->
x;
182 this->
draw_item_(display, item, &dimensions, selected);
184 y_offset += dimensions.
h + y_padding;
200 std::string label = item->
get_text();
213 dimensions.
w = std::min((int16_t) width, bounds->
w);
214 dimensions.
h = std::min((int16_t) height, bounds->
h);
225 int background_width = bounds->
w;
227 display->
filled_rectangle(bounds->
x, bounds->
y, background_width, bounds->
h, background_color);
229 std::string label = item->
get_text();