Clutter Engine 0.0.1
Loading...
Searching...
No Matches
clt::ButtonElement Class Reference

UI element representing a button with different states, textures, and callbacks. More...

#include <ButtonElement.h>

Inheritance diagram for clt::ButtonElement:
clt::SpriteElement clt::WidgetElement

Public Member Functions

 ButtonElement (std::string text, std::unordered_map< ButtonState, const std::string & > texturesName={})
 Constructs a ButtonElement with text and optional texture names for each state.
 
 ButtonElement (std::string text, std::unordered_map< ButtonState, Texture * > textures)
 Constructs a ButtonElement with text and textures for each state.
 
 ~ButtonElement ()=default
 Destructor.
 
virtual void Update () override
 Updates the button state and handles input.
 
virtual void Draw (RendererGL *renderer) override
 Draws the button using the provided renderer.
 
void SetTextures (std::unordered_map< ButtonState, const std::string & > textures)
 Sets textures for each button state using texture names.
 
void SetTextures (std::unordered_map< ButtonState, Texture * > textures)
 Sets textures for each button state using texture pointers.
 
void SetStateTexture (ButtonState state, const std::string &texture, Color tint=Color::White)
 Sets the texture and tint for a specific button state using a texture name.
 
void SetStateTexture (ButtonState state, Texture *texture, Color tint=Color::White)
 Sets the texture and tint for a specific button state using a texture pointer.
 
void SetEnable (bool enable=true)
 Enables or disables the button.
 
void Subscribe (ButtonState state, Callback callback)
 Subscribes a callback to a specific button state event.
 
- Public Member Functions inherited from clt::SpriteElement
 SpriteElement (const std::string textureName, Vector2 size={ 1, 1 }, Vector2 position={ 0, 0 }, int ZOrder=0)
 Constructs a SpriteElement with a texture name, size, position, and Z order.
 
 SpriteElement (Vector2 size={ 1, 1 }, Vector2 position={ 0, 0 }, int ZOrder=0)
 Constructs a SpriteElement with size, position, and Z order. No texture is set.
 
 SpriteElement (Texture *texture, Vector2 size={ 1, 1 }, Vector2 position={ 0, 0 }, int ZOrder=0)
 Constructs a SpriteElement with a texture pointer, size, position, and Z order.
 
 ~SpriteElement ()=default
 Destructor for SpriteElement.
 
virtual Transform2D GetTransform () const override
 Gets the transform of the sprite element.
 
virtual Vector2 GetSize () const override
 Gets the size of the sprite element.
 
void SetTexture (Texture *pTexture)
 Sets the texture for the sprite element.
 
void SetTexture (std::string pTexture)
 Sets the texture for the sprite element by texture name.
 
TextureGetTexture () const
 Gets the current texture of the sprite element.
 
- Public Member Functions inherited from clt::WidgetElement
 WidgetElement (Vector2 size={ 1, 1 }, Vector2 position={ 0, 0 }, int ZOrder=0)
 Constructs a WidgetElement with given size, position, and Z-order.
 
 ~WidgetElement ()=default
 Default destructor.
 
int GetZOrder () const
 Gets the Z-order of the widget.
 
void SetZOrder (int ZOrder)
 Sets the Z-order and updates the widget order in the owner panel.
 
Vector2 GetPosition () const
 Gets the position of the widget.
 
float GetRotation () const
 Gets the rotation of the widget.
 
void SetSize (Vector2 size)
 Sets the size of the widget.
 
void SetSize (float size)
 Sets the size of the widget (uniform scale).
 
void SetAnchor (Anchor anchor)
 Sets the anchor type for the widget.
 
void SetPosition (Vector2 position)
 Sets the position of the widget.
 
void SetRotation (float rotation)
 Sets the rotation of the widget.
 
void ToggleVisibility ()
 Toggles the visibility of the widget.
 

Additional Inherited Members

- Public Attributes inherited from clt::WidgetElement
bool mVisibility
 
- Protected Member Functions inherited from clt::WidgetElement
void SetOwner (UIPanel *pOwner)
 Sets the owner UIPanel of this widget.
 
- Protected Attributes inherited from clt::SpriteElement
TexturemTexture
 Pointer to the texture used by this sprite element.
 
- Protected Attributes inherited from clt::WidgetElement
Transform2D mTransform
 
friend UIPanel
 

Detailed Description

UI element representing a button with different states, textures, and callbacks.

Constructor & Destructor Documentation

◆ ButtonElement() [1/2]

ButtonElement::ButtonElement ( std::string text,
std::unordered_map< ButtonState, const std::string & > texturesName = {} )

Constructs a ButtonElement with text and optional texture names for each state.

Parameters
textThe text to display on the button.
texturesNameOptional map of state to texture name.

◆ ButtonElement() [2/2]

ButtonElement::ButtonElement ( std::string text,
std::unordered_map< ButtonState, Texture * > textures )

Constructs a ButtonElement with text and textures for each state.

Parameters
textThe text to display on the button.
texturesMap of state to texture pointer.

Member Function Documentation

◆ Draw()

void ButtonElement::Draw ( RendererGL * renderer)
overridevirtual

Draws the button using the provided renderer.

Parameters
rendererThe renderer to use.

Reimplemented from clt::SpriteElement.

◆ SetEnable()

void ButtonElement::SetEnable ( bool enable = true)

Enables or disables the button.

Parameters
enableTrue to enable, false to disable.

◆ SetStateTexture() [1/2]

void ButtonElement::SetStateTexture ( ButtonState state,
const std::string & texture,
Color tint = Color::White )

Sets the texture and tint for a specific button state using a texture name.

Parameters
stateThe button state.
textureThe texture name.
tintThe color tint to apply.

◆ SetStateTexture() [2/2]

void ButtonElement::SetStateTexture ( ButtonState state,
Texture * texture,
Color tint = Color::White )

Sets the texture and tint for a specific button state using a texture pointer.

Parameters
stateThe button state.
textureThe texture pointer.
tintThe color tint to apply.

◆ SetTextures() [1/2]

void ButtonElement::SetTextures ( std::unordered_map< ButtonState, const std::string & > textures)

Sets textures for each button state using texture names.

Parameters
texturesMap of state to texture name.

◆ SetTextures() [2/2]

void ButtonElement::SetTextures ( std::unordered_map< ButtonState, Texture * > textures)

Sets textures for each button state using texture pointers.

Parameters
texturesMap of state to texture pointer.

◆ Subscribe()

void ButtonElement::Subscribe ( ButtonState state,
Callback callback )

Subscribes a callback to a specific button state event.

Parameters
stateThe button state to subscribe to.
callbackThe callback function to invoke.

◆ Update()

void ButtonElement::Update ( )
overridevirtual

Updates the button state and handles input.

Reimplemented from clt::SpriteElement.


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