Numworks Epsilon  1.4.1
Graphing Calculator Operating System
scrollable_view.cpp
Go to the documentation of this file.
2 #include <escher/metric.h>
3 #include <assert.h>
4 
5 ScrollableView::ScrollableView(Responder * parentResponder, View * view, ScrollViewDataSource * dataSource) :
6  Responder(parentResponder),
7  ScrollView(view, dataSource),
8  m_manualScrollingOffset(KDPointZero)
9 {
10  setShowsIndicators(false);
11  setColorsBackground(false);
12 }
13 
15  KDPoint translation = KDPointZero;
16  if (event == Ion::Events::Left) {
17  KDCoordinate movementToEdge = m_manualScrollingOffset.x();
18  if (movementToEdge > 0) {
19  translation = KDPoint(-min(Metric::ScrollStep, movementToEdge), 0);
20  }
21  }
22  if (event == Ion::Events::Right) {
24  if (movementToEdge > 0) {
25  translation = KDPoint(min(Metric::ScrollStep, movementToEdge), 0);
26  }
27  }
28  if (event == Ion::Events::Up) {
29  KDCoordinate movementToEdge = m_manualScrollingOffset.y();
30  if (movementToEdge > 0) {
31  translation = KDPoint(0, -min(Metric::ScrollStep, movementToEdge));
32  }
33  }
34  if (event == Ion::Events::Down) {
36  if (movementToEdge > 0) {
37  translation = KDPoint(0, min(Metric::ScrollStep, movementToEdge));
38  }
39  }
40  if (translation != KDPointZero) {
43  return true;
44  }
45  return false;
46 }
47 
48 void ScrollableView::reloadScroll(bool forceReLayout) {
51 }
52 
54  KDSize viewSize = contentSize();
55  KDCoordinate viewWidth = viewSize.width() < bounds().width() ? bounds().width() : viewSize.width();
56  KDCoordinate viewHeight = viewSize.height() < bounds().height() ? bounds().height() : viewSize.height();
57  m_contentView->setSize(KDSize(viewWidth, viewHeight));
59 }
ScrollableView(Responder *parentResponder, View *view, ScrollViewDataSource *dataSource)
void setShowsIndicators(bool s)
Definition: scroll_view.h:28
KDCoordinate y() const
Definition: point.h:11
void reloadScroll(bool forceRelayout=false)
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr KDCoordinate width() const
Definition: size.h:10
constexpr Event Up
Definition: events.h:62
constexpr Event Down
Definition: events.h:63
constexpr KDPoint KDPointZero
Definition: point.h:25
void layoutSubviews() override
Definition: point.h:6
KDSize contentSize()
void setSize(KDSize size)
Definition: view.cpp:120
Definition: size.h:6
bool handleEvent(Ion::Events::Event event) override
static constexpr KDCoordinate ScrollStep
Definition: metric.h:20
void setColorsBackground(bool c)
Definition: scroll_view.h:30
void setContentOffset(KDPoint offset, bool forceRelayout=false)
constexpr Event Left
Definition: events.h:61
virtual KDSize minimalSizeForOptimalDisplay() const
Definition: view.cpp:183
KDPoint m_manualScrollingOffset
Definition: view.h:23
constexpr Event Right
Definition: events.h:64
KDCoordinate width() const
Definition: rect.h:39
void layoutSubviews() override
KDCoordinate x() const
Definition: point.h:10
KDPoint translatedBy(KDPoint other) const
Definition: point.cpp:3
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
View * m_contentView
Definition: scroll_view.h:56
constexpr KDCoordinate height() const
Definition: size.h:11