Make debug view scrollable

This commit is contained in:
2023-05-24 00:44:32 +02:00
parent 58dd4ae8d3
commit 9466290ff3
5 changed files with 95 additions and 8 deletions

View File

@ -13,9 +13,16 @@ public:
virtual void listUpdateItem(DebugViewLine &line, int16_t itemIndex) override;
void scrollUp() override;
void scrollDown() override;
void updateFieldValues();
protected:
private:
void updateScrollIndex(size_t index);
size_t scrollIndex;
};
#endif // DEBUGVIEWVIEW_HPP

View File

@ -32,3 +32,26 @@ void DebugViewView::updateFieldValues() {
el.updateFieldValues();
}
}
void DebugViewView::scrollUp() {
if (scrollIndex == 0) {
updateScrollIndex(list.getNumberOfItems() - 1);
} else {
updateScrollIndex(scrollIndex - 1);
}
}
void DebugViewView::scrollDown() {
updateScrollIndex((scrollIndex + 1) % list.getNumberOfItems());
}
void DebugViewView::updateScrollIndex(size_t index) {
scrollIndex = index;
if (scrollIndex == 0) {
// Just animating to 0 looks very broken when scrolling forwards. Animating
// to numItems looks good in both directions.
list.animateToItem(list.getNumberOfItems(), 2);
} else {
list.animateToItem(scrollIndex, 2);
}
}