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
valueis flipped (truebecomesfalseand vice versa). - If a
press_callbackis defined, it is invoked.
Returns:
bool:trueto indicate the event was handled.
Comments