Skip to content

SwitchWidget ​

SwitchWidget 是一个切换按钮,用于在 ON 与 OFF 状态之间切换。它支持自定义纹理、事件回调和动态状态更新。


特性 ​

  • 切换按钮行为 —— 点击即可在 ON 与 OFF 之间切换。
  • 事件处理 —— 当开关状态改变时触发回调。

属性 ​

字段类型描述
isPressedboolean (默认值:false)当前开关状态。

API ​

setPressed ​

设置开关的 ON/OFF 状态。

java
switchWidget.setPressed(true); // 打开(ON)
  • 触发 UI 更新 与事件回调。

setOnPressCallback ​

注册当开关被点击时的回调。

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

setSupplier ​

与外部状态自动同步。

java
switchWidget.setSupplier(() -> getCurrentState()); // bool
  • 当 getCurrentState() 变化时动态更新。

Released under the MIT License.