From 9ddd099604b3259638ab7731e71bc6577a92ff87 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Wed, 26 Feb 2020 20:12:53 +0100 Subject: [PATCH] Fix bug when items are not visible on boot --- midi2cv/menu/menu.cc | 12 ++++++++---- midi2cv/menu/menu.h | 4 +++- midi2cv/ui/part_menu.cc | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/midi2cv/menu/menu.cc b/midi2cv/menu/menu.cc index a481e44..137a49f 100644 --- a/midi2cv/menu/menu.cc +++ b/midi2cv/menu/menu.cc @@ -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) { + if (this->visibility_dirty) { + this->update_visible_items(); + this->visibility_dirty = false; + } + this->width = width; 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. for (size_t i = 0; i < itemCount; i++) { if (this->items[i]->visible()) { - if(currentlySelectedItem && this->items[i] == currentlySelectedItem) { + if (currentlySelectedItem && this->items[i] == currentlySelectedItem) { newIndexSelectedItem = this->visibleItemCount; } this->visibleItems[this->visibleItemCount++] = this->items[i]; } - } // 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->update_visible_items(); + this->visibility_dirty = true; } void Menu::down() @@ -113,7 +117,7 @@ void Menu::down() this->selectedVisibleItem++; } } - this->update_visible_items(); + this->visibility_dirty = true; } bool Menu::enter() diff --git a/midi2cv/menu/menu.h b/midi2cv/menu/menu.h index 35783c2..4a873e0 100644 --- a/midi2cv/menu/menu.h +++ b/midi2cv/menu/menu.h @@ -15,6 +15,7 @@ class Menu { uint8_t selectedVisibleItem; uint8_t currentVisibleScrollStart; // index we start rendering the menu from (for scrolling) int8_t currentEditingVisibleItem; + bool visibility_dirty; uint8_t width, height; @@ -25,6 +26,7 @@ class Menu { : selectedVisibleItem(0) , currentVisibleScrollStart(0) , currentEditingVisibleItem(-1) + , visibility_dirty(true) , width(10) , height(10) {}; @@ -37,7 +39,7 @@ class Menu { if (itemCount < MAXIMUM_MENU_ITEM_COUNT) { 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); diff --git a/midi2cv/ui/part_menu.cc b/midi2cv/ui/part_menu.cc index 378b70d..5377555 100644 --- a/midi2cv/ui/part_menu.cc +++ b/midi2cv/ui/part_menu.cc @@ -31,12 +31,12 @@ PartMenu::PartMenu(Part* _part) { this->menu.add_item(&this->item_voice_count); 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_input); 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_thru_mode); + this->menu.add_item(&this->item_midi_filter_enabled); } void PartMenu::up()