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

Element is the base class to be inherited to form all other types of elements. More...

#include <Element.hpp>

Inheritance diagram for Aether::Element:
Aether::Animation Aether::AsyncItem Aether::BaseProgress Aether::BorderButton Aether::Container Aether::ControlItem Aether::FilledButton Aether::HelpButton Aether::ListButton Aether::ListComment Aether::ListHeading Aether::ListOption Aether::ListSeparator Aether::MenuOption Aether::MenuSeparator Aether::Texture Aether::Tick

Public Member Functions

 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 setW (int w)
 Set width of element. More...
 
virtual void setH (int h)
 Set height 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...
 
virtual void addElement (Element *e)
 Adds new element a child. More...
 
virtual bool removeElement (Element *e)
 Attempt to delete given child element. More...
 
virtual void removeAllElements ()
 Deletes all children elements.
 
virtual bool returnElement (Element *e)
 Attempt to remove the given child element. More...
 
virtual void returnAllElements ()
 Removes (but does not delete) all children elements.
 
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...
 
virtual void setActive ()
 Set element as activated.
 
virtual void setInactive ()
 Set element as in-activated.
 
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 bool handleEvent (InputEvent *e)
 Attempt to handle a given event. More...
 
virtual void update (unsigned int dt)
 Update is passed time since last frame (for animations) More...
 
virtual void render ()
 Render child elements + highlights.
 
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 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

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)
 

Static Protected Attributes

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.
 

Friends

void moveHighlight (Element *e)
 Returns the element currently highlighted within given element or nullptr if none found. More...
 

Detailed Description

Element is the base class to be inherited to form all other types of elements.

Constructor & Destructor Documentation

◆ Element()

Aether::Element::Element ( int  x = 0,
int  y = 0,
int  w = 100,
int  h = 100 
)

Construct a new Element object.

Co-ordinates and size are optional. Default value of co-ordinates are (0, 0) and the default value of size are (100, 100). Parent is set as nullptr

Parameters
xx-coordinate of element
yy-coordinate of element
wwidth of element
hheight of element

Member Function Documentation

◆ addElement()

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

Adds new element a child.

Parameters
eelement to add

Reimplemented in Aether::Scrollable, and Aether::Container.

◆ addElementAt()

void Aether::Element::addElementAt ( Element e,
size_t  i 
)
protected

Add element at given index in vector.

Note
Will insert at end if index is beyond the end!
Parameters
eelement to add
iindex to insert at

◆ focused()

Element* Aether::Element::focused ( )

Returns the currently focused element.

Note
This is the same as focussed
Returns
focused element

◆ focussed()

Element* Aether::Element::focussed ( )

Returns the currently focused element.

Note
This is the same as focused
Returns
focused element

◆ h()

int Aether::Element::h ( )

Returns height of element.

Returns
int height of element

◆ handleEvent()

virtual bool Aether::Element::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 in Aether::Scrollable, Aether::DateTime, Aether::Spinner, Aether::List, Aether::Screen, and Aether::Container.

◆ hasHighlighted()

bool Aether::Element::hasHighlighted ( )

Check if current element has highlighted children element.

Returns
true if current element has highlighted children element
false if current element does not have highlighted children element

◆ hasSelectable()

bool Aether::Element::hasSelectable ( )

Check if current element has selectable children element.

Returns
true if current element has selectable children element
false if current element doesn't have selectable children element

◆ hasSelected()

bool Aether::Element::hasSelected ( )

Check if current element has selected children element.

Returns
true if current element has selected children element
false if current element doesn't have selected children element

◆ hidden()

bool Aether::Element::hidden ( )

Check if current element is hidden.

Returns
true if element is hidden
false if element is not hidden

◆ highlighted()

bool Aether::Element::highlighted ( )

Check if current element is highlighted.

Returns
true if current element is highlighted
false if current element is not highlighted

◆ isVisible()

bool Aether::Element::isVisible ( )

Check if current element is visible on-screen.

Returns
true if element is visible
false if element is not visible

◆ onPress()

void Aether::Element::onPress ( std::function< void()>  f)

Sets the function to invoked when the element is pressed.

Parameters
fFunction to invoke

◆ onPressFunc()

std::function<void()> Aether::Element::onPressFunc ( )

Returns function invoked when the element is pressed.

Returns
Function invoked when the element is pressed, or nullptr if one isn't assigned.

◆ parent()

Element* Aether::Element::parent ( )

Returns the parent element of this element.

Returns
parent element

◆ removeElement()

virtual bool Aether::Element::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 in Aether::Scrollable, and Aether::Container.

◆ renderHighlight()

virtual Drawable* Aether::Element::renderHighlight ( )
virtual

Renders the highlight border.

Note
The texture will be positioned centred in the middle of the element
Returns
Rendered texture to show when highlighted

Reimplemented in Aether::FilledButton, Aether::BorderButton, Aether::Ellipse, and Aether::HelpButton.

◆ renderHighlightBG()

virtual Drawable* Aether::Element::renderHighlightBG ( )
virtual

Renders the highlight background.

Note
The texture will be positioned centred in the middle of the element
Returns
Rendered texture to show when highlighted

Reimplemented in Aether::FilledButton, Aether::BorderButton, Aether::Ellipse, and Aether::HelpButton.

◆ renderSelection()

virtual Drawable* Aether::Element::renderSelection ( )
virtual

Renders the selection overlay.

Note
The texture will be positioned centred in the middle of the element
Returns
Rendered texture to show when selected

Reimplemented in Aether::FilledButton, Aether::BorderButton, Aether::Ellipse, and Aether::HelpButton.

◆ returnElement()

virtual bool Aether::Element::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 in Aether::Scrollable, and Aether::Container.

◆ selectable()

bool Aether::Element::selectable ( )

Check if current element is selectable.

Returns
true if current element is selectable
false if current element is not selectable

◆ selected()

bool Aether::Element::selected ( )

Check if current element is selected.

Returns
true if current element is selected
false if current element is not selected

◆ setFocused()

void Aether::Element::setFocused ( Element e)

Sets current element as unfocused and instead focuses a sub-element.

Note
This is the same as setFocussed
Parameters
eelement to focus

◆ setFocussed()

void Aether::Element::setFocussed ( Element e)

Sets current element as unfocused and instead focuses a sub-element.

Note
This is the same as setFocused
Parameters
eelement to focus

◆ setH()

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

◆ setHasHighlighted()

void Aether::Element::setHasHighlighted ( bool  b)

Set whether element has highlighted children element or not.

Parameters
bstate to change highlighted children element status to

◆ setHasSelectable()

void Aether::Element::setHasSelectable ( bool  b)

Set whether element has selectable children element or not.

Parameters
bstate to change selectable children element status to

◆ setHasSelected()

void Aether::Element::setHasSelected ( bool  b)

Set whether element has selected children element or not.

Parameters
bstate to change selected children element status to

◆ setHidden()

void Aether::Element::setHidden ( bool  b)

Set whether element is hidden or not.

Parameters
bstate to change hidden status to

◆ setHighlighted()

void Aether::Element::setHighlighted ( bool  b)

Set whether element is highlighted or not.

Parameters
bstate to change highlighted status to

◆ setParent()

void Aether::Element::setParent ( Element p)

Set the parent element of this element.

Parameters
pparent element to set as

◆ setSelectable()

void Aether::Element::setSelectable ( bool  b)

Set whether element is selectable or not.

Parameters
bstate to change selectable status to

◆ setSelected()

virtual void Aether::Element::setSelected ( bool  b)
virtual

Set whether element is selected or not.

Parameters
bstate to change selected status to

◆ setTouchable()

void Aether::Element::setTouchable ( bool  b)

Set whether element is touch responsive or not.

Parameters
bstate to change touch responsive status to

◆ setW()

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

◆ setWH()

virtual void Aether::Element::setWH ( int  w,
int  h 
)
virtual

Set size of element.

Parameters
wnew width of element
hnew height of element

◆ setX()

virtual void Aether::Element::setX ( int  x)
virtual

Set x-coordinate of element.

Parameters
xnew x-coordinate of element

◆ setXY()

virtual void Aether::Element::setXY ( int  x,
int  y 
)
virtual

Set co-ordinates of element.

Parameters
xnew x-coordinate of element
ynew y-coordinate of element

◆ setXYWH()

virtual void Aether::Element::setXYWH ( int  x,
int  y,
int  w,
int  h 
)
virtual

Setter size and co-ordinates of element.

Parameters
xnew x-coordinate of element
ynew y-coordinate of element
wnew width of element
hnew height of element

◆ setY()

virtual void Aether::Element::setY ( int  y)
virtual

Set y-coordinate of element.

Parameters
ynew y-coordinate of element

◆ touchable()

bool Aether::Element::touchable ( )

Check if current element is touch responsive.

Returns
true if current element is touch responsive
false if current element is not touch responsive

◆ update()

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

Update is passed time since last frame (for animations)

Parameters
dtchange in time

Reimplemented in Aether::Scrollable, Aether::Texture, Aether::Text, Aether::Spinner, Aether::List, Aether::Animation, and Aether::Menu.

◆ w()

int Aether::Element::w ( )

Returns width of element.

Returns
int width of element

◆ x()

int Aether::Element::x ( )

Returns x-coordinate of element.

Returns
int x-coordinate of element

◆ y()

int Aether::Element::y ( )

Returns y-coordinate of element.

Returns
int y-coordinate of element

Friends And Related Function Documentation

◆ moveHighlight

void moveHighlight ( Element e)
friend

Returns the element currently highlighted within given element or nullptr if none found.

Parameters
ecurrently highlighted element within given element or nullptr if none found

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