Class: UIButton
The UIButton class represents a button component in the UI system. It is a specialized subclass of UIComponent that supports callbacks for press and hold events, dynamic colors, and customizable sizes.
Use this class to create interactive buttons in your UI.
The source file for this class is located in os/ui/UIComponents/UIButton.h.
Constructorβ
UIButtonβ
UIButton() {}
Creates a new button component.
Use the setname, setsize, setcolor/setcolorfunc, onpress, and onhold methods to customize the button.
Methodsβ
GetNameβ
virtual string GetName();
Retrieves the name of the button.
Returns:
string: The name of the button.
SetNameβ
void SetName(string name);
Sets the name of the button.
Parameters:
name(string): The name to assign to the button.
GetColorβ
virtual Color GetColor();
Gets the current color of the button. If a color function (color_func) is defined, it overrides the static color property.
Returns:
Color: The button's color.
SetColorβ
void SetColor(Color color);
Sets a static color for the button.
Parameters:
color(Color): The color to assign to the button.
SetColorFuncβ
void SetColorFunc(std::function<Color()> color_func);
Assigns a dynamic color function for the button. The function determines the button's color dynamically at runtime.
Parameters:
color_func(std::function<Color()>): A function that returns the button's color.
GetSizeβ
virtual Dimension GetSize();
Gets the size of the button.
Returns:
Dimension: The dimensions (widthandheight) of the button.
SetSizeβ
void SetSize(Dimension dimension);
Sets the size of the button.
Parameters:
dimension(Dimension): The new size of the button.
PressCallbackβ
virtual bool PressCallback();
Triggers the button's press callback if defined. Override this method to customize the button's press behavior.
Returns:
bool:trueif a press callback is defined and executed,falseotherwise.
OnPressβ
void OnPress(std::function<void()> press_callback);
Sets a callback function to be executed when the button is pressed.
Parameters:
press_callback(std::function<void()>): The function to call on button press.
HoldCallbackβ
virtual bool HoldCallback();
Triggers the button's hold callback if defined.
Returns:
bool:trueif a hold callback is defined and executed,falseotherwise.
OnHoldβ
void OnHold(std::function<void()> hold_callback);
Sets a callback function to be executed when the button is held.
Parameters:
hold_callback(std::function<void()>): The function to call on button hold.
Renderβ
virtual bool Render(Point origin);
Renders the button on the screen by filling its area with the assigned color.
Parameters:
origin(Point): The top-left corner of the button's rendering area.
Returns:
bool:trueif rendering was successful.
KeyEventβ
virtual bool KeyEvent(Point xy, KeyInfo* keyInfo);
Handles key events on the button. Triggers the press or hold callback based on the event type.
Parameters:
xy(Point): The position of the event relative to the button.keyInfo(KeyInfo*): Information about the key event.
Returns:
bool:trueif the event was handled,falseotherwise.
Comments