mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-15 02:55:49 +00:00
Further optimize update_visible_items
This commit is contained in:
parent
c55c16ae38
commit
2f6d9b6d03
2 changed files with 9 additions and 20 deletions
|
@ -51,25 +51,24 @@ void Menu::update_visible_items()
|
||||||
this->visibleItems[i] = NULL;
|
this->visibleItems[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t newIndexSelectedItem = 0;
|
||||||
|
|
||||||
// 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) {
|
||||||
|
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:
|
||||||
if (currentlySelectedItem && this->visibleItems[this->selectedVisibleItem] != currentlySelectedItem) {
|
if (currentlySelectedItem && this->visibleItems[this->selectedVisibleItem] != currentlySelectedItem) {
|
||||||
int8_t delta = 0;
|
int8_t delta = this->selectedVisibleItem - newIndexSelectedItem;
|
||||||
// the index of our visible item has changed.
|
this->selectedVisibleItem = this->currentEditingVisibleItem = newIndexSelectedItem;
|
||||||
// go through the list of visible items and find it!
|
|
||||||
for (size_t i = 0; i < this->visibleItemCount; i++) {
|
|
||||||
if (this->visibleItems[i] == currentlySelectedItem) {
|
|
||||||
delta = this->selectedVisibleItem - i;
|
|
||||||
this->selectedVisibleItem = this->currentEditingVisibleItem = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this->currentVisibleScrollStart -= delta;
|
this->currentVisibleScrollStart -= delta;
|
||||||
CONSTRAIN(this->currentVisibleScrollStart, 0, this->visibleItemCount);
|
CONSTRAIN(this->currentVisibleScrollStart, 0, this->visibleItemCount);
|
||||||
CONSTRAIN(this->currentEditingVisibleItem, 0, this->visibleItemCount);
|
CONSTRAIN(this->currentEditingVisibleItem, 0, this->visibleItemCount);
|
||||||
|
|
|
@ -25,16 +25,6 @@ class Settings {
|
||||||
void SavePersistentData();
|
void SavePersistentData();
|
||||||
void SaveState();
|
void SaveState();
|
||||||
|
|
||||||
/*inline const ChannelCalibrationData& calibration_data(int channel) const
|
|
||||||
{
|
|
||||||
return persistent_data_.channel_calibration_data[channel];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline ChannelCalibrationData* mutable_calibration_data(int channel)
|
|
||||||
{
|
|
||||||
return &persistent_data_.channel_calibration_data[channel];
|
|
||||||
}*/
|
|
||||||
|
|
||||||
inline const State& state() const
|
inline const State& state() const
|
||||||
{
|
{
|
||||||
return state_;
|
return state_;
|
||||||
|
|
Loading…
Reference in a new issue