From 240ed439e0299e146e4b978cd38d97c0197fdad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 24 Apr 2019 14:34:18 +0200 Subject: [PATCH] [escher] ScrollableView: discard duplicate data source of scrolling offset --- ...lable_exact_approximate_expressions_view.cpp | 4 ++-- escher/include/escher/scrollable_view.h | 1 - escher/src/scrollable_view.cpp | 17 +++++++---------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/apps/shared/scrollable_exact_approximate_expressions_view.cpp b/apps/shared/scrollable_exact_approximate_expressions_view.cpp index 58f68ef10..dbb70ce11 100644 --- a/apps/shared/scrollable_exact_approximate_expressions_view.cpp +++ b/apps/shared/scrollable_exact_approximate_expressions_view.cpp @@ -147,9 +147,9 @@ bool ScrollableExactApproximateExpressionsView::handleEvent(Ion::Events::Event e if (m_contentCell.leftExpressionView()->layout().isUninitialized()) { return ScrollableView::handleEvent(event); } - bool rightExpressionIsVisible = minimalSizeForOptimalDisplay().width() - m_contentCell.rightExpressionView()->minimalSizeForOptimalDisplay().width() - m_manualScrollingOffset.x() < bounds().width() + bool rightExpressionIsVisible = minimalSizeForOptimalDisplay().width() - m_contentCell.rightExpressionView()->minimalSizeForOptimalDisplay().width() - contentOffset().x() < bounds().width() ; - bool leftExpressionIsVisible = m_contentCell.leftExpressionView()->minimalSizeForOptimalDisplay().width() - m_manualScrollingOffset.x() > 0; + bool leftExpressionIsVisible = m_contentCell.leftExpressionView()->minimalSizeForOptimalDisplay().width() - contentOffset().x() > 0; if ((event == Ion::Events::Right && selectedSubviewPosition() == SubviewPosition::Left && rightExpressionIsVisible) || (event == Ion::Events::Left && selectedSubviewPosition() == SubviewPosition::Right && leftExpressionIsVisible)) { SubviewPosition otherSubviewPosition = selectedSubviewPosition() == SubviewPosition::Left ? SubviewPosition::Right : SubviewPosition::Left; diff --git a/escher/include/escher/scrollable_view.h b/escher/include/escher/scrollable_view.h index ba4aaea4e..6d82205e3 100644 --- a/escher/include/escher/scrollable_view.h +++ b/escher/include/escher/scrollable_view.h @@ -12,7 +12,6 @@ public: void reloadScroll(bool forceRelayout = false); protected: KDSize contentSize() const override; - KDPoint m_manualScrollingOffset; }; #endif diff --git a/escher/src/scrollable_view.cpp b/escher/src/scrollable_view.cpp index 9efc0fd1e..5d5e90f57 100644 --- a/escher/src/scrollable_view.cpp +++ b/escher/src/scrollable_view.cpp @@ -7,8 +7,7 @@ static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { retur ScrollableView::ScrollableView(Responder * parentResponder, View * view, ScrollViewDataSource * dataSource) : Responder(parentResponder), - ScrollView(view, dataSource), - m_manualScrollingOffset(KDPointZero) + ScrollView(view, dataSource) { setDecoratorType(ScrollView::Decorator::Type::None); } @@ -16,40 +15,38 @@ ScrollableView::ScrollableView(Responder * parentResponder, View * view, ScrollV bool ScrollableView::handleEvent(Ion::Events::Event event) { KDPoint translation = KDPointZero; if (event == Ion::Events::Left) { - KDCoordinate movementToEdge = m_manualScrollingOffset.x(); + KDCoordinate movementToEdge = contentOffset().x(); if (movementToEdge > 0) { translation = KDPoint(-minCoordinate(Metric::ScrollStep, movementToEdge), 0); } } if (event == Ion::Events::Right) { - KDCoordinate movementToEdge = minimalSizeForOptimalDisplay().width() - bounds().width() - m_manualScrollingOffset.x(); + KDCoordinate movementToEdge = minimalSizeForOptimalDisplay().width() - bounds().width() - contentOffset().x(); if (movementToEdge > 0) { translation = KDPoint(minCoordinate(Metric::ScrollStep, movementToEdge), 0); } } if (event == Ion::Events::Up) { - KDCoordinate movementToEdge = m_manualScrollingOffset.y(); + KDCoordinate movementToEdge = contentOffset().y(); if (movementToEdge > 0) { translation = KDPoint(0, -minCoordinate(Metric::ScrollStep, movementToEdge)); } } if (event == Ion::Events::Down) { - KDCoordinate movementToEdge = minimalSizeForOptimalDisplay().height() - bounds().height() - m_manualScrollingOffset.y(); + KDCoordinate movementToEdge = minimalSizeForOptimalDisplay().height() - bounds().height() - contentOffset().y(); if (movementToEdge > 0) { translation = KDPoint(0, minCoordinate(Metric::ScrollStep, movementToEdge)); } } if (translation != KDPointZero) { - m_manualScrollingOffset = m_manualScrollingOffset.translatedBy(translation); - setContentOffset(m_manualScrollingOffset); + setContentOffset(contentOffset().translatedBy(translation)); return true; } return false; } void ScrollableView::reloadScroll(bool forceReLayout) { - m_manualScrollingOffset = KDPointZero; - setContentOffset(m_manualScrollingOffset, forceReLayout); + setContentOffset(KDPointZero, forceReLayout); } KDSize ScrollableView::contentSize() const {