Aether
SDL2 based UI Framework for NX
Scrollable.hpp
1 #ifndef AETHER_SCROLLABLE_HPP
2 #define AETHER_SCROLLABLE_HPP
3 
4 #include "Aether/base/Container.hpp"
5 
6 namespace Aether {
13  class Scrollable : public Container {
14  private:
16  Padding paddingType;
18  Drawable * scrollBar;
20  Colour scrollBarColour;
22  bool showScrollBar_;
23 
27  int paddingAmount();
28 
32  void stopScrolling();
33 
34  protected:
36  bool canScroll_;
38  bool isTouched;
46  int touchY;
48  unsigned int maxScrollPos_;
52  unsigned int scrollPos_;
53 
54  void addElementAt(Element * e, size_t i);
55 
59  void updateMaxScrollPos();
60 
61  public:
71  Scrollable(int x, int y, int w, int h, Padding p = Padding::Default);
72 
78  int catchup();
79 
85  void setCatchup(int c);
86 
92  float dampening();
93 
99  void setDampening(float d);
100 
107  bool showScrollBar();
108 
114  void setShowScrollBar(bool b);
115 
121  void setScrollBarColour(Colour c);
122 
129  bool canScroll();
130 
136  void setCanScroll(bool b);
137 
144  int maxScrollPos();
145 
151  int scrollPos();
152 
159  void setScrollPos(int pos);
160 
167  void addElement(Element * e);
168 
180  bool addElementAfter(Element * e, Element * a);
181 
193  bool addElementBefore(Element * e, Element * b);
194 
203  bool removeElementsAfter(Element * e);
204 
213  bool removeElementsBefore(Element * e);
214 
215  void setW(int w);
216  void setH(int h);
217 
218  bool removeElement(Element * e);
219  void removeAllElements();
220  bool returnElement(Element * e);
221  void returnAllElements();
222 
223  bool handleEvent(InputEvent * e);
224  void update(unsigned int dt);
225  void render();
226 
230  ~Scrollable();
231  };
232 };
233 
234 #endif
int maxScrollPos()
Returns the maximum value permitted for scrollPos (i.e. the limit).
bool removeElementsAfter(Element *e)
Deletes any elements succeeding the given element.
Padding
Enum class for amount of padding in a scrollable.
Definition: Types.hpp:47
bool showScrollBar()
Returns if the scroll bar is being shown.
A container is an element that contains other elements. It implements the required behaviour to navig...
Definition: Container.hpp:16
A scrollable element arranges all of it's children as a list. It's children are rendered and 'cut off...
Definition: Scrollable.hpp:13
void setScrollBarColour(Colour c)
Set scroll bar colour.
int touchY
Start of touch Y coord (used to touch element instead of scroll briefly)
Definition: Scrollable.hpp:46
void updateMaxScrollPos()
Sums up height of children and sets maximum scroll value.
unsigned int maxScrollPos_
Maximum Y offset in pixels.
Definition: Scrollable.hpp:48
void returnAllElements()
Removes (but does not delete) all children elements.
void setH(int h)
Set height of element.
unsigned int scrollPos_
Offset (y) in pixels.
Definition: Scrollable.hpp:52
int catchup()
Get amount to "catchup" by.
~Scrollable()
Delete the scrollable object.
void addElement(Element *e)
Add the given element to the list.
bool addElementAfter(Element *e, Element *a)
Adds an element to the scrollable object after the specified element. Pass nullptr to insert at the s...
void setW(int w)
Set width of element.
int w()
Returns width of element.
Stores RGBA values representing a colour. Each component can be within the range 0 to 255 (inclusive)...
Definition: Colour.hpp:9
Stores either a surface or texture which can be drawn on screen by providing a renderer to render()...
Definition: Drawable.hpp:22
int x()
Returns x-coordinate of element.
bool isTouched
Indicator on whether this scrollable has been touched (used for scrolling when touch is outside) ...
Definition: Scrollable.hpp:38
void setShowScrollBar(bool b)
Set whether to show scroll bar.
float dampening()
Get amount to decrease velocity by (pixels per second)
bool returnElement(Element *e)
Attempt to remove the given child element.
Element is the base class to be inherited to form all other types of elements.
Definition: Element.hpp:18
int h()
Returns height of element.
Base namespace for all Aether related classes and functions.
void render()
Render child elements + highlights.
bool removeElement(Element *e)
Attempt to delete given child element.
void removeAllElements()
Deletes all children elements.
bool canScroll_
Indicator on whether scrolling is allowed.
Definition: Scrollable.hpp:36
void update(unsigned int dt)
Update is passed time since last frame (for animations)
void setCatchup(int c)
Set amount to "catchup" by.
A class that represents an Aether input event.
Definition: InputEvent.hpp:25
bool removeElementsBefore(Element *e)
Deletes any elements preceding the given element.
bool isScrolling
Indicator on whether is the element is scrolling (used for touch events)
Definition: Scrollable.hpp:40
bool handleEvent(InputEvent *e)
Attempt to handle a given event.
float scrollVelocity
Scroll velocity (pixels to scroll per second)
Definition: Scrollable.hpp:44
void setScrollPos(int pos)
Sets scrollPos. Set to min/max if outside valid range.
float scrollDampening
Amount to decrease velocity by (oixels per second)
Definition: Scrollable.hpp:42
void setCanScroll(bool b)
Set whether this element can be scrolled by touching and dragging.
Scrollable(int x, int y, int w, int h, Padding p=Padding::Default)
Construct a new Scrollable object.
void setDampening(float d)
Set amount to decrease velocity by (pixels per second)
int scrollPos()
Returns current scroll position of list (0 indicates at the top)
bool addElementBefore(Element *e, Element *b)
Adds an element to the scrollable object before the specified element. Pass nullptr to insert at the ...
float scrollCatchup
Amount to "catchup" by.
Definition: Scrollable.hpp:50
int y()
Returns y-coordinate of element.
bool canScroll()
Check whether this element can be scrolled (by touch/drag)