Class: UIToggle
The UIToggle
class extends UIButton
to provide a toggle button functionality. It allows users to toggle a boolean value between true
and false
. Additionally, the toggle button's visual state (color and text) will auto reflects the current value.
The source file for this class is located in os/ui/UIComponents/UIToggle.h.
Constructor​
UIToggle
​
UIToggle();
Creates a new toggle button component. Creates a new button component.
Use the setname
, setsize
, setcolor
/setcolorfunc
, onpress
, and onhold
methods from uibutton
to customize the button.
Then use the setvalue
method to set the boolean value that the toggle button will modify.
Methods​
SetValue
​
void SetValue(bool* value);
Sets the boolean value that this toggle button modifies.
Parameters:
value
(bool*
): Pointer to the boolean variable controlled by the toggle button.
GetName
​
string GetName() override;
Retrieves the name of the toggle button, with a suffix indicating its current state ("On"
or "Off"
).
Returns:
string
: The name of the toggle button, e.g.,"MyToggle On"
or"MyToggle Off"
.
GetColor
​
Color GetColor() override;
Retrieves the color of the toggle button. The color is dimmed if the toggle is in the "off" state.
Returns:
Color
: The color of the toggle button.
PressCallback
​
bool PressCallback() override;
Handles the button press event. Toggles the value
and invokes the press_callback
, if defined.
Behavior:
- The
value
is flipped (true
becomesfalse
and vice versa). - If a
press_callback
is defined, it is invoked.
Returns:
bool
:true
to indicate the event was handled.
Comments