Fix bug when items are not visible on boot

This commit is contained in:
Jan-Henrik 2020-02-26 20:12:53 +01:00
parent 2f6d9b6d03
commit 9ddd099604
3 changed files with 12 additions and 6 deletions

View file

@ -5,6 +5,11 @@ const int kMenuItemHeight = 12;
void Menu::render(U8G2* u8g2_, uint8_t xStart, uint8_t yStart, uint8_t width, uint8_t height) void Menu::render(U8G2* u8g2_, uint8_t xStart, uint8_t yStart, uint8_t width, uint8_t height)
{ {
if (this->visibility_dirty) {
this->update_visible_items();
this->visibility_dirty = false;
}
this->width = width; this->width = width;
this->height = height; this->height = height;
@ -56,12 +61,11 @@ void Menu::update_visible_items()
// find out which items are visible and only add these to the list. // find out which items are visible and only add these to the list.
for (size_t i = 0; i < itemCount; i++) { for (size_t i = 0; i < itemCount; i++) {
if (this->items[i]->visible()) { if (this->items[i]->visible()) {
if(currentlySelectedItem && this->items[i] == currentlySelectedItem) { if (currentlySelectedItem && this->items[i] == currentlySelectedItem) {
newIndexSelectedItem = this->visibleItemCount; newIndexSelectedItem = this->visibleItemCount;
} }
this->visibleItems[this->visibleItemCount++] = this->items[i]; this->visibleItems[this->visibleItemCount++] = this->items[i];
} }
} }
// if our visibleitem changed, chances are that the index of the selected item has changed: // if our visibleitem changed, chances are that the index of the selected item has changed:
@ -94,7 +98,7 @@ void Menu::up()
this->currentVisibleScrollStart = 0; this->currentVisibleScrollStart = 0;
} }
} }
this->update_visible_items(); this->visibility_dirty = true;
} }
void Menu::down() void Menu::down()
@ -113,7 +117,7 @@ void Menu::down()
this->selectedVisibleItem++; this->selectedVisibleItem++;
} }
} }
this->update_visible_items(); this->visibility_dirty = true;
} }
bool Menu::enter() bool Menu::enter()

View file

@ -15,6 +15,7 @@ class Menu {
uint8_t selectedVisibleItem; uint8_t selectedVisibleItem;
uint8_t currentVisibleScrollStart; // index we start rendering the menu from (for scrolling) uint8_t currentVisibleScrollStart; // index we start rendering the menu from (for scrolling)
int8_t currentEditingVisibleItem; int8_t currentEditingVisibleItem;
bool visibility_dirty;
uint8_t width, height; uint8_t width, height;
@ -25,6 +26,7 @@ class Menu {
: selectedVisibleItem(0) : selectedVisibleItem(0)
, currentVisibleScrollStart(0) , currentVisibleScrollStart(0)
, currentEditingVisibleItem(-1) , currentEditingVisibleItem(-1)
, visibility_dirty(true)
, width(10) , width(10)
, height(10) {}; , height(10) {};
@ -37,7 +39,7 @@ class Menu {
if (itemCount < MAXIMUM_MENU_ITEM_COUNT) { if (itemCount < MAXIMUM_MENU_ITEM_COUNT) {
items[itemCount++] = item; items[itemCount++] = item;
} }
this->update_visible_items(); this->visibility_dirty = true;
} }
void render(U8G2* u8g2_, uint8_t x, uint8_t y, uint8_t width, uint8_t height); void render(U8G2* u8g2_, uint8_t x, uint8_t y, uint8_t width, uint8_t height);

View file

@ -31,12 +31,12 @@ PartMenu::PartMenu(Part* _part)
{ {
this->menu.add_item(&this->item_voice_count); this->menu.add_item(&this->item_voice_count);
this->menu.add_item(&this->item_voice_detail); this->menu.add_item(&this->item_voice_detail);
this->menu.add_item(&this->item_midi_filter_enabled);
this->menu.add_item(&this->item_midi_channel); this->menu.add_item(&this->item_midi_channel);
this->menu.add_item(&this->item_midi_input); this->menu.add_item(&this->item_midi_input);
this->menu.add_item(&this->item_midi_lowest_note); this->menu.add_item(&this->item_midi_lowest_note);
this->menu.add_item(&this->item_midi_highest_note); this->menu.add_item(&this->item_midi_highest_note);
this->menu.add_item(&this->item_midi_thru_mode); this->menu.add_item(&this->item_midi_thru_mode);
this->menu.add_item(&this->item_midi_filter_enabled);
} }
void PartMenu::up() void PartMenu::up()