Use std::min and std::max

This commit is contained in:
Romain Goyet
2020-04-12 15:43:39 -04:00
committed by Ecco
parent 77ee5126e1
commit 950862f8d0
79 changed files with 297 additions and 406 deletions

View File

@@ -1,9 +1,7 @@
#include <escher/scrollable_view.h>
#include <escher/metric.h>
#include <assert.h>
static inline KDCoordinate minCoordinate(KDCoordinate x, KDCoordinate y) { return x < y ? x : y; }
static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; }
#include <algorithm>
ScrollableView::ScrollableView(Responder * parentResponder, View * view, ScrollViewDataSource * dataSource) :
Responder(parentResponder),
@@ -17,25 +15,25 @@ bool ScrollableView::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Left) {
KDCoordinate movementToEdge = contentOffset().x();
if (movementToEdge > 0) {
translation = KDPoint(-minCoordinate(Metric::ScrollStep, movementToEdge), 0);
translation = KDPoint(-std::min(Metric::ScrollStep, movementToEdge), 0);
}
}
if (event == Ion::Events::Right) {
KDCoordinate movementToEdge = minimalSizeForOptimalDisplay().width() - bounds().width() - contentOffset().x();
if (movementToEdge > 0) {
translation = KDPoint(minCoordinate(Metric::ScrollStep, movementToEdge), 0);
translation = KDPoint(std::min(Metric::ScrollStep, movementToEdge), 0);
}
}
if (event == Ion::Events::Up) {
KDCoordinate movementToEdge = contentOffset().y();
if (movementToEdge > 0) {
translation = KDPoint(0, -minCoordinate(Metric::ScrollStep, movementToEdge));
translation = KDPoint(0, -std::min(Metric::ScrollStep, movementToEdge));
}
}
if (event == Ion::Events::Down) {
KDCoordinate movementToEdge = minimalSizeForOptimalDisplay().height() - bounds().height() - contentOffset().y();
if (movementToEdge > 0) {
translation = KDPoint(0, minCoordinate(Metric::ScrollStep, movementToEdge));
translation = KDPoint(0, std::min(Metric::ScrollStep, movementToEdge));
}
}
if (translation != KDPointZero) {
@@ -51,7 +49,7 @@ void ScrollableView::reloadScroll(bool forceReLayout) {
KDSize ScrollableView::contentSize() const {
KDSize viewSize = ScrollView::contentSize();
KDCoordinate viewWidth = maxCoordinate(viewSize.width(), maxContentWidthDisplayableWithoutScrolling());
KDCoordinate viewHeight = maxCoordinate(viewSize.height(), maxContentHeightDisplayableWithoutScrolling());
KDCoordinate viewWidth = std::max(viewSize.width(), maxContentWidthDisplayableWithoutScrolling());
KDCoordinate viewHeight = std::max(viewSize.height(), maxContentHeightDisplayableWithoutScrolling());
return KDSize(viewWidth, viewHeight);
}