Carpenter Engine
A C++ game engine with a build once run anywhere solution
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Engine::UI::UIElement Class Reference

Base class for UI elements. More...

#include <UIElement.hpp>

Inheritance diagram for Engine::UI::UIElement:
Engine::Node Engine::UI::UIInput Engine::UI::UILabel Engine::UI::UIButton

Public Member Functions

 UIElement (std::string name)
 Default Constructor.
 
 ~UIElement () override
 
void Init () override
 Creates the UI element and adds it to the DOM.
 
void AddTheme (const char *theme)
 Sets the theme of the UI element.
 
void SetAnchor (const char *anchor)
 Sets the anchor of the UI element.
 
void SetDimensions (Vec2f dimensions)
 Sets the dimensions of the UI element.
 
void SetOffset (Vec2f offset)
 Sets the offset of the UI element.
 
void OnEnable () override
 Shows the UI element when enabled.
 
void OnDisable () override
 Hides the UI element when disabled.
 
- Public Member Functions inherited from Engine::Node
 Node (std::string name)
 Default constructor.
 
virtual ~Node ()
 Default destructor.
 
size_t AddChild (Node *child)
 Adds a child to the node and assigns itself as the parent of the new node.
 
NodeGetChild (size_t index)
 Returns a reference to the child at the specified index.
 
Success RemoveChild (size_t index)
 Removes the child at the specified index.
 
Success SetEnabled (bool enabled=true)
 Toggles the state of the node.
 
virtual void Draw ()
 Overridable draw method for the node.
 
virtual void Update (float dt)
 Overridable update method for the node.
 

Protected Attributes

const char * m_uiTag
 
const char * m_uiClass
 
- Protected Attributes inherited from Engine::Node
Nodem_parent
 

Additional Inherited Members

- Public Attributes inherited from Engine::Node
const char * m_nodeType
 
std::string m_name
 

Detailed Description

Base class for UI elements.

Uses the Node class to create an element in the DOM. Although this is considered an abstract class, you by freely use it as a container for UI Elements.

Author
Roberto Selles

Constructor & Destructor Documentation

◆ UIElement()

Engine::UI::UIElement::UIElement ( std::string  name)

Default Constructor.

Takes in a name to make identification easier in the DOM

Parameters
nameThe name of the UI element

◆ ~UIElement()

Engine::UI::UIElement::~UIElement ( )
override

Destructor Method

Member Function Documentation

◆ AddTheme()

void Engine::UI::UIElement::AddTheme ( const char *  theme)

Sets the theme of the UI element.

This theme will be applied and is inherited by children elements that are attached to this object.

Parameters
themeThe CSS class to use as a theme

◆ Init()

void Engine::UI::UIElement::Init ( )
overridevirtual

Creates the UI element and adds it to the DOM.

Reimplemented from Engine::Node.

Reimplemented in Engine::UI::UIInput, and Engine::UI::UILabel.

◆ OnDisable()

void Engine::UI::UIElement::OnDisable ( )
overridevirtual

Hides the UI element when disabled.

Override for Node::OnDisable()

Reimplemented from Engine::Node.

◆ OnEnable()

void Engine::UI::UIElement::OnEnable ( )
overridevirtual

Shows the UI element when enabled.

Override for Node::OnEnable()

Reimplemented from Engine::Node.

◆ SetAnchor()

void Engine::UI::UIElement::SetAnchor ( const char *  anchor)

Sets the anchor of the UI element.

By default, the element is placed in the top left, but you can set to anchor any of the following:

  • "topright"
  • "bottomleft"
  • "bottomright"
  • "center"

If you do anchor the element to a centered position, the offset will assume to translate either to the bottom or right of the anchor. (depending on the axis that has been centered)

Warning
This should only be called once per UI element
Parameters
anchorThe anchor as a string

◆ SetDimensions()

void Engine::UI::UIElement::SetDimensions ( Vec2f  dimensions)

Sets the dimensions of the UI element.

Parameters
dimensionsThe dimensions where x is the width, and y is the height

◆ SetOffset()

void Engine::UI::UIElement::SetOffset ( Vec2f  offset)

Sets the offset of the UI element.

Parameters
dimensionsThe dimensions where x is the width, and y is the height

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