ToggleComponent constructor
ToggleComponent({
- required bool value,
- required ValueChanged<
bool> onChanged, - required PositionComponent valueOn,
- required PositionComponent valueOff,
- PositionComponent? disabledComponent,
- bool disabled = false,
- void onAnimate(
- PositionComponent visual,
- bool newValue
- Vector2? position,
- Vector2? size,
Creates a ToggleComponent with custom visual components.
value is the initial state of the toggle.
onChanged is the callback invoked when the toggle value changes.
valueOn is the visual component for the enabled state.
valueOff is the visual component for the disabled state.
disabledComponent is shown when disabled is true (optional).
Implementation
ToggleComponent({
required bool value,
required ValueChanged<bool> onChanged,
required PositionComponent valueOn,
required PositionComponent valueOff,
PositionComponent? disabledComponent,
this.disabled = false,
this.onAnimate,
Vector2? position,
Vector2? size,
}) : _value = value,
_onChanged = onChanged,
_valueOn = valueOn,
_valueOff = valueOff,
_disabledComponent = disabledComponent,
super(
position: position ?? Vector2.zero(),
size: size ?? valueOn.size.clone(),
);