Aether
SDL2 based UI Framework for NX
|
Element is the base class to be inherited to form all other types of elements. More...
#include <Element.hpp>
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... | |
Element * | parent () |
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... | |
Element * | focused () |
Returns the currently focused element. More... | |
Element * | focussed () |
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 Drawable * | renderHighlightBG () |
Renders the highlight background. More... | |
virtual Drawable * | renderHighlight () |
Renders the highlight border. More... | |
virtual Drawable * | renderSelection () |
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 | |
Element * | parent_ |
Pointer to parent element, if there is one. | |
std::vector< Element * > | children |
Vector of child elements (used to call their methods) | |
Element * | focused_ |
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 Drawable * | hiBGTex |
Highlight background texture. | |
static Drawable * | hiBorderTex |
Highlight border texture. | |
static Drawable * | selTex |
Selection texture. | |
static Renderer * | renderer |
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... | |
Element is the base class to be inherited to form all other types of elements.
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
x | x-coordinate of element |
y | y-coordinate of element |
w | width of element |
h | height of element |
|
virtual |
Adds new element a child.
e | element to add |
Reimplemented in Aether::Scrollable, and Aether::Container.
|
protected |
Add element at given index in vector.
e | element to add |
i | index to insert at |
Element* Aether::Element::focused | ( | ) |
Returns the currently focused element.
Element* Aether::Element::focussed | ( | ) |
Returns the currently focused element.
int Aether::Element::h | ( | ) |
Returns height of element.
|
virtual |
Attempt to handle a given event.
e | event to handle |
Reimplemented in Aether::Scrollable, Aether::DateTime, Aether::Spinner, Aether::List, Aether::Screen, and Aether::Container.
bool Aether::Element::hasHighlighted | ( | ) |
Check if current element has highlighted children element.
bool Aether::Element::hasSelectable | ( | ) |
Check if current element has selectable children element.
bool Aether::Element::hasSelected | ( | ) |
Check if current element has selected children element.
bool Aether::Element::hidden | ( | ) |
Check if current element is hidden.
bool Aether::Element::highlighted | ( | ) |
Check if current element is highlighted.
bool Aether::Element::isVisible | ( | ) |
Check if current element is visible on-screen.
void Aether::Element::onPress | ( | std::function< void()> | f | ) |
Sets the function to invoked when the element is pressed.
f | Function to invoke |
std::function<void()> Aether::Element::onPressFunc | ( | ) |
Returns function invoked when the element is pressed.
Element* Aether::Element::parent | ( | ) |
Returns the parent element of this element.
|
virtual |
Attempt to delete given child element.
e | child to delete |
Reimplemented in Aether::Scrollable, and Aether::Container.
|
virtual |
Renders the highlight border.
Reimplemented in Aether::FilledButton, Aether::BorderButton, Aether::Ellipse, and Aether::HelpButton.
|
virtual |
Renders the highlight background.
Reimplemented in Aether::FilledButton, Aether::BorderButton, Aether::Ellipse, and Aether::HelpButton.
|
virtual |
Renders the selection overlay.
Reimplemented in Aether::FilledButton, Aether::BorderButton, Aether::Ellipse, and Aether::HelpButton.
|
virtual |
Attempt to remove the given child element.
e | child to remove |
Reimplemented in Aether::Scrollable, and Aether::Container.
bool Aether::Element::selectable | ( | ) |
Check if current element is selectable.
bool Aether::Element::selected | ( | ) |
Check if current element is selected.
void Aether::Element::setFocused | ( | Element * | e | ) |
Sets current element as unfocused and instead focuses a sub-element.
e | element to focus |
void Aether::Element::setFocussed | ( | Element * | e | ) |
Sets current element as unfocused and instead focuses a sub-element.
e | element to focus |
|
virtual |
Set height of element.
h | new height of element |
Reimplemented in Aether::Scrollable, Aether::ListOption, Aether::ControlBar, Aether::AsyncItem, Aether::ListButton, Aether::ListHeadingHelp, Aether::FilledButton, Aether::BorderButton, Aether::RoundProgressBar, and Aether::ProgressBar.
void Aether::Element::setHasHighlighted | ( | bool | b | ) |
Set whether element has highlighted children element or not.
b | state to change highlighted children element status to |
void Aether::Element::setHasSelectable | ( | bool | b | ) |
Set whether element has selectable children element or not.
b | state to change selectable children element status to |
void Aether::Element::setHasSelected | ( | bool | b | ) |
Set whether element has selected children element or not.
b | state to change selected children element status to |
void Aether::Element::setHidden | ( | bool | b | ) |
Set whether element is hidden or not.
b | state to change hidden status to |
void Aether::Element::setHighlighted | ( | bool | b | ) |
Set whether element is highlighted or not.
b | state to change highlighted status to |
void Aether::Element::setParent | ( | Element * | p | ) |
Set the parent element of this element.
p | parent element to set as |
void Aether::Element::setSelectable | ( | bool | b | ) |
Set whether element is selectable or not.
b | state to change selectable status to |
|
virtual |
Set whether element is selected or not.
b | state to change selected status to |
void Aether::Element::setTouchable | ( | bool | b | ) |
Set whether element is touch responsive or not.
b | state to change touch responsive status to |
|
virtual |
Set width of element.
w | new width of element |
Reimplemented in Aether::Scrollable, Aether::ListOption, Aether::ControlBar, Aether::AsyncItem, Aether::Text, Aether::ListButton, Aether::ListHeadingHelp, Aether::FilledButton, Aether::BorderButton, Aether::RoundProgressBar, Aether::ProgressBar, Aether::ListComment, Aether::MenuOption, and Aether::MenuSeparator.
|
virtual |
Set size of element.
w | new width of element |
h | new height of element |
|
virtual |
Set x-coordinate of element.
x | new x-coordinate of element |
|
virtual |
Set co-ordinates of element.
x | new x-coordinate of element |
y | new y-coordinate of element |
|
virtual |
Setter size and co-ordinates of element.
x | new x-coordinate of element |
y | new y-coordinate of element |
w | new width of element |
h | new height of element |
|
virtual |
Set y-coordinate of element.
y | new y-coordinate of element |
bool Aether::Element::touchable | ( | ) |
Check if current element is touch responsive.
|
virtual |
Update is passed time since last frame (for animations)
dt | change in time |
Reimplemented in Aether::Scrollable, Aether::Texture, Aether::Text, Aether::Spinner, Aether::List, Aether::Animation, and Aether::Menu.
int Aether::Element::w | ( | ) |
Returns width of element.
int Aether::Element::x | ( | ) |
Returns x-coordinate of element.
int Aether::Element::y | ( | ) |
Returns y-coordinate of element.
|
friend |
Returns the element currently highlighted within given element or nullptr if none found.
e | currently highlighted element within given element or nullptr if none found |