Aether
SDL2 based UI Framework for NX
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Aether::Scrollable Class Reference

A scrollable element arranges all of it's children as a list. It's children are rendered and 'cut off' outside the dimensions of the scrollable object. Note that added elements will have their width changed to match the list! Also note that elements are placed directly below the previous element (in terms of y-coords)! More...

#include <Scrollable.hpp>

Inheritance diagram for Aether::Scrollable:
Aether::Container Aether::Element Aether::List Aether::Menu

Public Member Functions

 Scrollable (int x, int y, int w, int h, Padding p=Padding::Default)
 Construct a new Scrollable object. More...
 
int catchup ()
 Get amount to "catchup" by. More...
 
void setCatchup (int c)
 Set amount to "catchup" by. More...
 
float dampening ()
 Get amount to decrease velocity by (pixels per second) More...
 
void setDampening (float d)
 Set amount to decrease velocity by (pixels per second) More...
 
bool showScrollBar ()
 Returns if the scroll bar is being shown. More...
 
void setShowScrollBar (bool b)
 Set whether to show scroll bar. More...
 
void setScrollBarColour (Colour c)
 Set scroll bar colour. More...
 
bool canScroll ()
 Check whether this element can be scrolled (by touch/drag) More...
 
void setCanScroll (bool b)
 Set whether this element can be scrolled by touching and dragging. More...
 
int maxScrollPos ()
 Returns the maximum value permitted for scrollPos (i.e. the limit). More...
 
int scrollPos ()
 Returns current scroll position of list (0 indicates at the top) More...
 
void setScrollPos (int pos)
 Sets scrollPos. Set to min/max if outside valid range. More...
 
void addElement (Element *e)
 Add the given element to the list. More...
 
bool addElementAfter (Element *e, Element *a)
 Adds an element to the scrollable object after the specified element. Pass nullptr to insert at the start. More...
 
bool addElementBefore (Element *e, Element *b)
 Adds an element to the scrollable object before the specified element. Pass nullptr to insert at the end (note: this is the same as addElement()) More...
 
bool removeElementsAfter (Element *e)
 Deletes any elements succeeding the given element. More...
 
bool removeElementsBefore (Element *e)
 Deletes any elements preceding the given element. More...
 
void setW (int w)
 Set width of element. More...
 
void setH (int h)
 Set height of element. More...
 
bool removeElement (Element *e)
 Attempt to delete given child element. More...
 
void removeAllElements ()
 Deletes all children elements.
 
bool returnElement (Element *e)
 Attempt to remove the given child element. More...
 
void returnAllElements ()
 Removes (but does not delete) all children elements.
 
bool handleEvent (InputEvent *e)
 Attempt to handle a given event. More...
 
void update (unsigned int dt)
 Update is passed time since last frame (for animations) More...
 
void render ()
 Render child elements + highlights.
 
 ~Scrollable ()
 Delete the scrollable object.
 
- Public Member Functions inherited from Aether::Container
 Container (int x=0, int y=0, int w=100, int h=100)
 Construct a new Container object. More...
 
void setActive ()
 Re-highlight/focus the focused element.
 
void setInactive ()
 Removes focus from the focused element.
 
- Public Member Functions inherited from Aether::Element
 Element (int x=0, int y=0, int w=100, int h=100)
 Construct a new Element object. More...
 
int x ()
 Returns x-coordinate of element. More...
 
int y ()
 Returns y-coordinate of element. More...
 
int w ()
 Returns width of element. More...
 
int h ()
 Returns height of element. More...
 
virtual void setX (int x)
 Set x-coordinate of element. More...
 
virtual void setY (int y)
 Set y-coordinate of element. More...
 
virtual void setXY (int x, int y)
 Set co-ordinates of element. More...
 
virtual void setWH (int w, int h)
 Set size of element. More...
 
virtual void setXYWH (int x, int y, int w, int h)
 Setter size and co-ordinates of element. More...
 
Elementparent ()
 Returns the parent element of this element. More...
 
void setParent (Element *p)
 Set the parent element of this element. More...
 
bool isVisible ()
 Check if current element is visible on-screen. More...
 
bool hidden ()
 Check if current element is hidden. More...
 
void setHidden (bool b)
 Set whether element is hidden or not. More...
 
bool selected ()
 Check if current element is selected. More...
 
virtual void setSelected (bool b)
 Set whether element is selected or not. More...
 
bool selectable ()
 Check if current element is selectable. More...
 
void setSelectable (bool b)
 Set whether element is selectable or not. More...
 
bool touchable ()
 Check if current element is touch responsive. More...
 
void setTouchable (bool b)
 Set whether element is touch responsive or not. More...
 
bool highlighted ()
 Check if current element is highlighted. More...
 
void setHighlighted (bool b)
 Set whether element is highlighted or not. More...
 
bool hasHighlighted ()
 Check if current element has highlighted children element. More...
 
void setHasHighlighted (bool b)
 Set whether element has highlighted children element or not. More...
 
bool hasSelectable ()
 Check if current element has selectable children element. More...
 
void setHasSelectable (bool b)
 Set whether element has selectable children element or not. More...
 
bool hasSelected ()
 Check if current element has selected children element. More...
 
void setHasSelected (bool b)
 Set whether element has selected children element or not. More...
 
void setFocused (Element *e)
 Sets current element as unfocused and instead focuses a sub-element. More...
 
void setFocussed (Element *e)
 Sets current element as unfocused and instead focuses a sub-element. More...
 
Elementfocused ()
 Returns the currently focused element. More...
 
Elementfocussed ()
 Returns the currently focused element. More...
 
std::function< void()> onPressFunc ()
 Returns function invoked when the element is pressed. More...
 
void onPress (std::function< void()> f)
 Sets the function to invoked when the element is pressed. More...
 
virtual DrawablerenderHighlightBG ()
 Renders the highlight background. More...
 
virtual DrawablerenderHighlight ()
 Renders the highlight border. More...
 
virtual DrawablerenderSelection ()
 Renders the selection overlay. More...
 
virtual ~Element ()
 Destroy the Element object.
 

Protected Member Functions

void addElementAt (Element *e, size_t i)
 
void updateMaxScrollPos ()
 Sums up height of children and sets maximum scroll value.
 
- Protected Member Functions inherited from Aether::Container
void addElementAt (Element *e, size_t i)
 
- Protected Member Functions inherited from Aether::Element
void renderHighlightTextures ()
 Renders cached highlight textures.
 
void renderSelectionTexture ()
 Renders cached selection texture.
 
void addElementAt (Element *e, size_t i)
 Add element at given index in vector. More...
 

Protected Attributes

bool canScroll_
 Indicator on whether scrolling is allowed.
 
bool isTouched
 Indicator on whether this scrollable has been touched (used for scrolling when touch is outside)
 
bool isScrolling
 Indicator on whether is the element is scrolling (used for touch events)
 
float scrollDampening
 Amount to decrease velocity by (oixels per second)
 
float scrollVelocity
 Scroll velocity (pixels to scroll per second)
 
int touchY
 Start of touch Y coord (used to touch element instead of scroll briefly)
 
unsigned int maxScrollPos_
 Maximum Y offset in pixels.
 
float scrollCatchup
 Amount to "catchup" by.
 
unsigned int scrollPos_
 Offset (y) in pixels.
 
- Protected Attributes inherited from Aether::Element
Elementparent_
 Pointer to parent element, if there is one.
 
std::vector< Element * > children
 Vector of child elements (used to call their methods)
 
Elementfocused_
 Children element which is highlighted/focused (to regain focus on activation)
 

Additional Inherited Members

- Static Protected Attributes inherited from Aether::Element
static Colour hiBGColour
 Background colour if element is highlighted.
 
static Colour hiBorderColour
 Border colour if element is highlighted.
 
static Colour selColour
 Selected colour if element is highlighted.
 
static unsigned int hiSize
 Size of highlight border.
 
static DrawablehiBGTex
 Highlight background texture.
 
static DrawablehiBorderTex
 Highlight border texture.
 
static DrawableselTex
 Selection texture.
 
static Rendererrenderer
 
static bool isTouch
 Indicator on whether the touch is "active" (i.e. hide highlighting) or not.
 

Detailed Description

A scrollable element arranges all of it's children as a list. It's children are rendered and 'cut off' outside the dimensions of the scrollable object. Note that added elements will have their width changed to match the list! Also note that elements are placed directly below the previous element (in terms of y-coords)!

Constructor & Destructor Documentation

◆ Scrollable()

Aether::Scrollable::Scrollable ( int  x,
int  y,
int  w,
int  h,
Padding  p = Padding::Default 
)

Construct a new Scrollable object.

Parameters
xx-coordinate of scrollable element
yy-coordinate of scrollable element
wwidth of scrollable element
hheight of scrollable element
ptype of padding to use (see Padding)

Member Function Documentation

◆ addElement()

void Aether::Scrollable::addElement ( Element e)
virtual

Add the given element to the list.

Note
The element's width will be set to match the width of the scrollable object
Parameters
eelement to add

Reimplemented from Aether::Container.

◆ addElementAfter()

bool Aether::Scrollable::addElementAfter ( Element e,
Element a 
)

Adds an element to the scrollable object after the specified element. Pass nullptr to insert at the start.

Note
The element to add is not deleted if it was not added!
Parameters
eelement to add
aelement to insert after
Returns
true if the preceding element was found and the element added
false if the preceding element was not found

◆ addElementBefore()

bool Aether::Scrollable::addElementBefore ( Element e,
Element b 
)

Adds an element to the scrollable object before the specified element. Pass nullptr to insert at the end (note: this is the same as addElement())

Note
The element to add is not deleted if it was not added!
Parameters
eelement to add
belement to insert before
Returns
true if the succeeding element was found and the element added
false if the succeeding element was not found

◆ canScroll()

bool Aether::Scrollable::canScroll ( )

Check whether this element can be scrolled (by touch/drag)

Returns
true if element is scrollable
false otherwise

◆ catchup()

int Aether::Scrollable::catchup ( )

Get amount to "catchup" by.

Returns
amount to catchup by

◆ dampening()

float Aether::Scrollable::dampening ( )

Get amount to decrease velocity by (pixels per second)

Returns
decrease velocity

◆ handleEvent()

bool Aether::Scrollable::handleEvent ( InputEvent e)
virtual

Attempt to handle a given event.

Parameters
eevent to handle
Returns
true if event was handled
false if event was not handled

Reimplemented from Aether::Container.

Reimplemented in Aether::List.

◆ maxScrollPos()

int Aether::Scrollable::maxScrollPos ( )

Returns the maximum value permitted for scrollPos (i.e. the limit).

Note
It cannot be set as it is done so by the object when items are changed
Returns
int specifying maximum scroll position allowed

◆ removeElement()

bool Aether::Scrollable::removeElement ( Element e)
virtual

Attempt to delete given child element.

Note
This calls the element destructor if it is found
Parameters
echild to delete
Returns
true if deleted successfully (i.e. was a child)
false if not a child of element

Reimplemented from Aether::Container.

◆ removeElementsAfter()

bool Aether::Scrollable::removeElementsAfter ( Element e)

Deletes any elements succeeding the given element.

Parameters
eelement to start from
Returns
true if following elements were found for the given element
false otherwise

◆ removeElementsBefore()

bool Aether::Scrollable::removeElementsBefore ( Element e)

Deletes any elements preceding the given element.

Parameters
eelement to start from
Returns
true if prior elements were found for the given element
false otherwise

◆ returnElement()

bool Aether::Scrollable::returnElement ( Element e)
virtual

Attempt to remove the given child element.

Note
This does not call the element's destructor, hence it can be reused
Parameters
echild to remove
Returns
true if removed successfully (i.e. was a child)
false if not a child of element

Reimplemented from Aether::Container.

◆ scrollPos()

int Aether::Scrollable::scrollPos ( )

Returns current scroll position of list (0 indicates at the top)

Returns
int specifying scroll position

◆ setCanScroll()

void Aether::Scrollable::setCanScroll ( bool  b)

Set whether this element can be scrolled by touching and dragging.

Parameters
btrue if element is scrollable, false otherwise

◆ setCatchup()

void Aether::Scrollable::setCatchup ( int  c)

Set amount to "catchup" by.

Parameters
cnew catchup value

◆ setDampening()

void Aether::Scrollable::setDampening ( float  d)

Set amount to decrease velocity by (pixels per second)

Parameters
dnew decrease velocity

◆ setH()

void Aether::Scrollable::setH ( int  h)
virtual

Set height of element.

Parameters
hnew height of element

Reimplemented from Aether::Element.

◆ setScrollBarColour()

void Aether::Scrollable::setScrollBarColour ( Colour  c)

Set scroll bar colour.

Parameters
ccolour to set to

◆ setScrollPos()

void Aether::Scrollable::setScrollPos ( int  pos)

Sets scrollPos. Set to min/max if outside valid range.

Note
This should only need to be used in rare-ish cases (such as jumping to the top of a list after pressing a button)
Parameters
posnew scroll position

◆ setShowScrollBar()

void Aether::Scrollable::setShowScrollBar ( bool  b)

Set whether to show scroll bar.

Parameters
btrue to show scroll bar, false otherwise

◆ setW()

void Aether::Scrollable::setW ( int  w)
virtual

Set width of element.

Parameters
wnew width of element

Reimplemented from Aether::Element.

◆ showScrollBar()

bool Aether::Scrollable::showScrollBar ( )

Returns if the scroll bar is being shown.

Returns
true if scroll bar is shown
false otherwise

◆ update()

void Aether::Scrollable::update ( unsigned int  dt)
virtual

Update is passed time since last frame (for animations)

Parameters
dtchange in time

Reimplemented from Aether::Element.

Reimplemented in Aether::List, and Aether::Menu.


The documentation for this class was generated from the following file: