[escher] ScrollableView: discard duplicate data source of scrolling

offset
This commit is contained in:
Émilie Feral
2019-04-24 14:34:18 +02:00
parent e29c2b8b39
commit ff87c8c53c
3 changed files with 9 additions and 13 deletions

View File

@@ -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 {