Make debug view scrollable

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

View File

@ -8,7 +8,7 @@
#include <mvp/View.hpp>
#include <gui/debugview_screen/DebugViewPresenter.hpp>
#include <touchgfx/widgets/Box.hpp>
#include <touchgfx/containers/scrollers/ScrollList.hpp>
#include <touchgfx/containers/scrollers/ScrollWheel.hpp>
#include <gui/containers/DebugViewLine.hpp>
#include <touchgfx/widgets/canvas/Line.hpp>
#include <touchgfx/widgets/canvas/PainterRGB565.hpp>
@ -24,6 +24,19 @@ public:
{
// Override and implement this function in DebugView
}
virtual void handleKeyEvent(uint8_t key);
/*
* Virtual Action Handlers
*/
virtual void scrollUp()
{
// Override and implement this function in DebugView
}
virtual void scrollDown()
{
// Override and implement this function in DebugView
}
protected:
FrontendApplication& application() {
@ -34,7 +47,7 @@ protected:
* Member Declarations
*/
touchgfx::Box __background;
touchgfx::ScrollList list;
touchgfx::ScrollWheel list;
touchgfx::DrawableListItems<DebugViewLine, 13> listListItems;
touchgfx::Line line1;
touchgfx::PainterRGB565 line1Painter;

View File

@ -17,14 +17,14 @@ DebugViewViewBase::DebugViewViewBase() :
list.setPosition(15, 15, 450, 290);
list.setHorizontal(false);
list.setCircular(true);
list.setEasingEquation(touchgfx::EasingEquations::backEaseOut);
list.setEasingEquation(touchgfx::EasingEquations::linearEaseOut);
list.setSwipeAcceleration(10);
list.setDragAcceleration(10);
list.setNumberOfItems(1);
list.setPadding(0, 0);
list.setSnapping(false);
list.setSelectedItemOffset(0);
list.setDrawableSize(26, 0);
list.setDrawables(listListItems, updateItemCallback);
list.animateToItem(0, 0);
add(list);
line1.setPosition(15, 15, 1, 290);
@ -69,6 +69,27 @@ void DebugViewViewBase::setupScreen()
}
}
void DebugViewViewBase::handleKeyEvent(uint8_t key)
{
if(104 == key)
{
//ScrollUp
//When hardware button 104 clicked call virtual function
//Call scrollUp
scrollUp();
}
if(108 == key)
{
//ScrollDown
//When hardware button 108 clicked call virtual function
//Call scrollDown
scrollDown();
}
}
void DebugViewViewBase::updateItemCallbackHandler(touchgfx::DrawableListItemsInterface* items, int16_t containerIndex, int16_t itemIndex)
{
if (items == &listListItems)

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);
}
}

View File

@ -854,7 +854,7 @@
"CanvasBufferSize": 7200,
"Components": [
{
"Type": "ScrollList",
"Type": "ScrollWheel",
"Name": "list",
"X": 15,
"Y": 15,
@ -863,7 +863,7 @@
"IsCircular": true,
"ItemTemplateName": "DebugViewLine",
"NumberofItems": 1,
"Easing": "Back",
"Easing": "Linear",
"EasingOption": "Out",
"SwipeAcceleration": 1.0,
"DragAcceleration": 1.0
@ -917,7 +917,30 @@
"LineEndingStyle": "Round"
}
],
"Interactions": []
"Interactions": [
{
"InteractionName": "ScrollUp",
"Trigger": {
"Type": "TriggerPhysicalButtonClicked",
"ButtonKey": 104
},
"Action": {
"Type": "ActionCustom",
"FunctionName": "scrollUp"
}
},
{
"InteractionName": "ScrollDown",
"Trigger": {
"Type": "TriggerPhysicalButtonClicked",
"ButtonKey": 108
},
"Action": {
"Type": "ActionCustom",
"FunctionName": "scrollDown"
}
}
]
},
{
"Name": "VehicleConfig",