Skip to content

SwitchWidget

The SwitchWidget is a toggle button that switches between an ON and OFF state. It supports custom textures, event callbacks, and dynamic state updates.


Features

  • Toggle button behavior – Click to switch between ON and OFF.
  • Event handling – Fires callbacks when the switch state changes.

Properties

FieldTypeDescription
isPressedboolean (default: false)Current switch state.

APIs

setPressed

Sets the ON/OFF state of the switch.

java
switchWidget.setPressed(true); // Turns ON
  • Triggers UI updates and event callbacks.

setOnPressCallback

Registers a callback when the switch is clicked.

java
switchWidget.setOnPressCallback((clickData, state) -> {
    System.out.println("Switch is now: " + state);
});

setSupplier

Automatically syncs with an external state.

java
switchWidget.setSupplier(() -> getCurrentState()); // bool
  • Updates dynamically when getCurrentState() changes.

Released under the MIT License.