Nox Engine
 
Loading...
Searching...
No Matches
Button Struct Reference

A UI component that can be clicked to trigger a callback function. More...

#include <Button.h>

Inheritance diagram for Button:
Inheritance graph
Collaboration diagram for Button:
Collaboration graph

Public Member Functions

 Button (std::string inStr, int x, int y, int w, int h, float scale, SDL_Colour defColour, SDL_Colour hoverColour, SDL_Colour textColour, std::function< void()> func)
 Constructs a fully customized Button.
 
 Button (std::string inStr, int x, int y, int w, int h, float scale, std::function< void()> func)
 Constructs a Button with default colors.
 
 Button (std::string inStr, int x, int y, int w, int h, std::function< void()> func)
 Constructs a Button with default colors and scale.
 
void init () override
 Initializes the button's components (transform, collider, text).
 
void update () override
 Checks for mouse hover and click events to update the button's state.
 
void reload () override
 Reloads the button's texture, useful after state changes.
 
void draw () override
 Draws the button's background and text.
 

Additional Inherited Members

- Public Attributes inherited from Component
Entityentity
 Pointer to the entity that owns this component.
 

Detailed Description

A UI component that can be clicked to trigger a callback function.

Combines a collider, text, and transform to create an interactive button. It changes color on hover and executes a function when pressed.

Constructor & Destructor Documentation

◆ Button() [1/3]

Button::Button ( std::string  inStr,
int  x,
int  y,
int  w,
int  h,
float  scale,
SDL_Colour  defColour,
SDL_Colour  hoverColour,
SDL_Colour  textColour,
std::function< void()>  func 
)

Constructs a fully customized Button.

Parameters
inStrThe text to display on the button.
xThe x-position of the button.
yThe y-position of the button.
wThe width of the button.
hThe height of the button.
scaleThe rendering scale of the button text.
defColourThe default background color.
hoverColourThe background color when the mouse hovers over it.
textColourThe color of the button's text.
funcThe callback function to execute when the button is pressed.
Here is the call graph for this function:

◆ Button() [2/3]

Button::Button ( std::string  inStr,
int  x,
int  y,
int  w,
int  h,
float  scale,
std::function< void()>  func 
)

Constructs a Button with default colors.

Parameters
inStrThe text to display on the button.
xThe x-position of the button.
yThe y-position of the button.
wThe width of the button.
hThe height of the button.
scaleThe rendering scale of the button text.
funcThe callback function to execute when the button is pressed.
Here is the call graph for this function:

◆ Button() [3/3]

Button::Button ( std::string  inStr,
int  x,
int  y,
int  w,
int  h,
std::function< void()>  func 
)

Constructs a Button with default colors and scale.

Parameters
inStrThe text to display on the button.
xThe x-position of the button.
yThe y-position of the button.
wThe width of the button.
hThe height of the button.
funcThe callback function to execute when the button is pressed.
Here is the call graph for this function:

Member Function Documentation

◆ draw()

void Button::draw ( )
overridevirtual

Draws the button's background and text.

Reimplemented from Component.

Here is the call graph for this function:

◆ init()

void Button::init ( )
overridevirtual

Initializes the button's components (transform, collider, text).

Reimplemented from Component.

Here is the call graph for this function:

◆ reload()

void Button::reload ( )
overridevirtual

Reloads the button's texture, useful after state changes.

Reimplemented from Component.

◆ update()

void Button::update ( )
overridevirtual

Checks for mouse hover and click events to update the button's state.

Reimplemented from Component.

Here is the call graph for this function:

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