fixed crash when BtnGridView has more than one page (#993)

* fixed crash when BtnGridView has more than one page

* removed empty buttons from view
This commit is contained in:
Bernd Herzog 2023-05-15 00:08:48 +02:00 committed by GitHub
parent b4da86d491
commit e694e73a75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,14 +136,22 @@ void BtnGridView::update_items() {
more = false; more = false;
for (NewButton* item : menu_item_views) { for (NewButton* item : menu_item_views) {
if (i >= menu_items.size()) break; if ((i + offset) >= menu_items.size()) {
item->hidden(true);
// Assign item data to NewButtons according to offset item->set_text(" ");
item->set_text(menu_items[i + offset].text); item->set_bitmap(nullptr);
item->set_bitmap(menu_items[i + offset].bitmap); item->on_select = [](){};
item->set_color(menu_items[i + offset].color); item->set_dirty();
item->on_select = menu_items[i + offset].on_select; }
item->set_dirty(); else {
// Assign item data to NewButtons according to offset
item->hidden(false);
item->set_text(menu_items[i + offset].text);
item->set_bitmap(menu_items[i + offset].bitmap);
item->set_color(menu_items[i + offset].color);
item->on_select = menu_items[i + offset].on_select;
item->set_dirty();
}
i++; i++;
} }
@ -167,18 +175,21 @@ bool BtnGridView::set_highlighted(int32_t new_value) {
highlighted_item = new_value; highlighted_item = new_value;
offset = new_value - displayed_max + rows_; offset = new_value - displayed_max + rows_;
update_items(); update_items();
set_dirty();
} else if ((uint32_t)new_value < offset) { } else if ((uint32_t)new_value < offset) {
// Shift BtnGridView down // Shift BtnGridView down
highlighted_item = new_value; highlighted_item = new_value;
offset = (new_value / rows_) * rows_; offset = (new_value / rows_) * rows_;
update_items(); update_items();
set_dirty();
} else { } else {
// Just update highlight // Just update highlight
highlighted_item = new_value; highlighted_item = new_value;
if (visible())
item_view(highlighted_item - offset)->focus();
} }
if (visible())
item_view(highlighted_item - offset)->focus();
return true; return true;
} }