Animate field type selection

This commit is contained in:
Jasper Blanckenburg 2023-04-12 16:04:20 +02:00
parent 370dbb5ca1
commit d1b4ad625c
4 changed files with 13 additions and 6 deletions

View File

@ -102,7 +102,7 @@ DriverViewViewBase::DriverViewViewBase() :
fieldTypeSelection.setPosition(15, 95, 150, 225);
fieldTypeSelection.setHorizontal(false);
fieldTypeSelection.setCircular(true);
fieldTypeSelection.setEasingEquation(touchgfx::EasingEquations::backEaseOut);
fieldTypeSelection.setEasingEquation(touchgfx::EasingEquations::linearEaseOut);
fieldTypeSelection.setSwipeAcceleration(10);
fieldTypeSelection.setDragAcceleration(10);
fieldTypeSelection.setNumberOfItems(1);

View File

@ -38,7 +38,7 @@ private:
DriverViewField &getField(size_t i);
void updateSelectedField(size_t select);
void updateSelectedFieldType(size_t select);
void updateSelectedFieldType(size_t select, bool animate = true);
size_t selectedField;
size_t selectedFieldType;

View File

@ -138,15 +138,22 @@ void DriverViewView::updateSelectedField(size_t selected) {
fieldTypeSelection.invalidate();
selectedField = selected;
updateSelectedFieldType(fieldTypes[selectedField]);
updateSelectedFieldType(fieldTypes[selectedField], false);
}
void DriverViewView::updateSelectedFieldType(size_t selected) {
void DriverViewView::updateSelectedFieldType(size_t selected, bool animate) {
size_t previousSelected = selectedFieldType;
selectedFieldType = selected;
// Trigger update of the background
fieldTypeSelection.itemChanged(previousSelected);
fieldTypeSelection.itemChanged(selectedFieldType);
fieldTypeSelection.animateToItem(selectedFieldType, 0);
int16_t steps = animate ? 2 : 0;
if (selectedFieldType == 0) {
// Just animating to 0 looks very broken when scrolling forwards. Animating
// to DataFieldType_COUNT looks good in both directions.
fieldTypeSelection.animateToItem(DataFieldType_COUNT, steps);
} else {
fieldTypeSelection.animateToItem(selectedFieldType, steps);
}
}

View File

@ -436,7 +436,7 @@
"IsCircular": true,
"ItemTemplateName": "DriverViewFieldSelection",
"NumberofItems": 1,
"Easing": "Back",
"Easing": "Linear",
"EasingOption": "Out",
"SwipeAcceleration": 1.0,
"DragAcceleration": 1.0