Further optimize update_visible_items

This commit is contained in:
Jan-Henrik 2020-02-26 20:03:41 +01:00
parent c55c16ae38
commit 2f6d9b6d03
2 changed files with 9 additions and 20 deletions

View file

@ -51,25 +51,24 @@ void Menu::update_visible_items()
this->visibleItems[i] = NULL;
}
uint8_t newIndexSelectedItem = 0;
// 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) {
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:
if (currentlySelectedItem && this->visibleItems[this->selectedVisibleItem] != currentlySelectedItem) {
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] == currentlySelectedItem) {
delta = this->selectedVisibleItem - i;
this->selectedVisibleItem = this->currentEditingVisibleItem = i;
break;
}
}
int8_t delta = this->selectedVisibleItem - newIndexSelectedItem;
this->selectedVisibleItem = this->currentEditingVisibleItem = newIndexSelectedItem;
this->currentVisibleScrollStart -= delta;
CONSTRAIN(this->currentVisibleScrollStart, 0, this->visibleItemCount);
CONSTRAIN(this->currentEditingVisibleItem, 0, this->visibleItemCount);

View file

@ -25,16 +25,6 @@ class Settings {
void SavePersistentData();
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
{
return state_;