mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-15 02:55:49 +00:00
Fix scrolling for invisible items
This commit is contained in:
parent
677898f9f9
commit
602faa5c8f
2 changed files with 53 additions and 10 deletions
|
@ -59,13 +59,29 @@ void Menu::update_visible_items()
|
|||
|
||||
void Menu::up()
|
||||
{
|
||||
this->update_visible_items();
|
||||
if (this->currentEditingVisibleItem >= 0) {
|
||||
// we store the amount of visible items before the counter before
|
||||
// changing and then compare afterwards to move the cursor back to
|
||||
// its intended position if necessary
|
||||
this->visibleItems[this->selectedVisibleItem]->decrease();
|
||||
this->update_visible_items();
|
||||
|
||||
AbstractMenuItem* item = this->visibleItems[this->selectedVisibleItem];
|
||||
|
||||
item->decrease();
|
||||
|
||||
this->update_visible_items();
|
||||
|
||||
if (this->visibleItems[this->selectedVisibleItem] != item) {
|
||||
int8_t delta = 0;
|
||||
// the index of our visible item has changed.
|
||||
// go through the list of visible items and find it!
|
||||
for (size_t i = 0; i < this->visibleItemCount; i++) {
|
||||
if (this->visibleItems[i] == item) {
|
||||
delta = this->selectedVisibleItem - i;
|
||||
this->selectedVisibleItem = this->currentEditingVisibleItem = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->currentVisibleScrollStart -= delta;
|
||||
CONSTRAIN(this->currentEditingVisibleItem, 0, this->visibleItemCount);
|
||||
}
|
||||
} else if (this->selectedVisibleItem > 0) {
|
||||
uint8_t newItem = this->selectedVisibleItem - 1;
|
||||
|
||||
|
@ -79,14 +95,35 @@ void Menu::up()
|
|||
this->currentVisibleScrollStart = 0;
|
||||
}
|
||||
}
|
||||
this->update_visible_items();
|
||||
}
|
||||
|
||||
void Menu::down()
|
||||
{
|
||||
this->update_visible_items();
|
||||
if (this->currentEditingVisibleItem >= 0) {
|
||||
this->visibleItems[this->selectedVisibleItem]->increase();
|
||||
this->update_visible_items();
|
||||
|
||||
AbstractMenuItem* item = this->visibleItems[this->selectedVisibleItem];
|
||||
|
||||
item->increase();
|
||||
|
||||
this->update_visible_items();
|
||||
|
||||
if (this->visibleItems[this->selectedVisibleItem] != item) {
|
||||
int8_t delta = 0;
|
||||
// the index of our visible item has changed.
|
||||
// go through the list of visible items and find it!
|
||||
for (size_t i = 0; i < this->visibleItemCount; i++) {
|
||||
if (this->visibleItems[i] == item) {
|
||||
delta = this->selectedVisibleItem - i;
|
||||
this->selectedVisibleItem = this->currentEditingVisibleItem = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->currentVisibleScrollStart -= delta;
|
||||
CONSTRAIN(this->currentEditingVisibleItem, 0, this->visibleItemCount);
|
||||
}
|
||||
|
||||
} else {
|
||||
uint8_t maxVisibleItems = height / kMenuItemHeight;
|
||||
if (this->selectedVisibleItem < this->visibleItemCount - 1) {
|
||||
|
|
|
@ -18,9 +18,15 @@ PartMenu::PartMenu(Part* _part)
|
|||
, item_midi_channel("MIDI channel", (uint8_t*)&_part->data.midi_filter_channel, kMidiChannelStrings, 17, [_part] {
|
||||
return _part->data.midi_filter_channel_enabled;
|
||||
})
|
||||
, item_midi_input("MIDI input", (uint8_t*)&_part->data.midi_filter_input, kMidiInputStrings, 3)
|
||||
, item_midi_lowest_note("MIDI lowest", (uint8_t*)&_part->data.midi_filter_lowest_note)
|
||||
, item_midi_highest_note("MIDI highest", (uint8_t*)&_part->data.midi_filter_highest_note)
|
||||
, item_midi_input("MIDI input", (uint8_t*)&_part->data.midi_filter_input, kMidiInputStrings, 3, [_part] {
|
||||
return _part->data.midi_filter_channel_enabled;
|
||||
})
|
||||
, item_midi_lowest_note("MIDI lowest", (uint8_t*)&_part->data.midi_filter_lowest_note, [_part] {
|
||||
return _part->data.midi_filter_channel_enabled;
|
||||
})
|
||||
, item_midi_highest_note("MIDI highest", (uint8_t*)&_part->data.midi_filter_highest_note, [_part] {
|
||||
return _part->data.midi_filter_channel_enabled;
|
||||
})
|
||||
, item_midi_thru_mode("MIDI thru", (uint8_t*)&_part->data.midi_thru_mode, kMidiThruStrings, 3)
|
||||
{
|
||||
this->menu.add_item(&this->item_voice_count);
|
||||
|
|
Loading…
Reference in a new issue