Class Switch

All Implemented Interfaces:
PointerInterface

public class Switch extends Widget
`GtkSwitch` is a "light switch" that has two states: on or off.

![An example GtkSwitch](switch.png)

The user can control which state should be active by clicking the
empty area, or by dragging the handle.

`GtkSwitch` can also handle situations where the underlying state
changes with a delay. See [signal@GtkSwitch::state-set] for details.

# CSS nodes

```
switch
├── label
├── label
╰── slider
```

`GtkSwitch` has four css nodes, the main node with the name switch and
subnodes for the slider and the on and off labels. Neither of them is
using any style classes.

# Accessibility

`GtkSwitch` uses the %GTK_ACCESSIBLE_ROLE_SWITCH role.

https://docs.gtk.org/gtk4/class.Switch.html

  • Field Details

  • Constructor Details

    • Switch

      public Switch(PointerContainer pointer)
    • Switch

      public Switch()
      Creates a new `GtkSwitch` widget.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getActive

      public boolean getActive()
      Gets whether the `GtkSwitch` is in its “on” or “off” state.
      Returns:
      %TRUE if the `GtkSwitch` is active, and %FALSE otherwise
    • getState

      public boolean getState()
      Gets the underlying state of the `GtkSwitch`.
      Returns:
      the underlying state
    • setActive

      public void setActive(boolean is_active)
      Changes the state of @self to the desired one.
      Parameters:
      is_active - %TRUE if @self should be active, and %FALSE otherwise
    • setState

      public void setState(boolean state)
      Sets the underlying state of the `GtkSwitch`.

      Normally, this is the same as [property@Gtk.Switch:active], unless
      the switch is set up for delayed state changes. This function is
      typically called from a [signal@Gtk.Switch::state-set] signal handler.

      See [signal@Gtk.Switch::state-set] for details.
      Parameters:
      state - the new state
    • onActivate

      public SignalHandler onActivate(Switch.OnActivate signal)
      Connect to signal "activate".
      See Switch.OnActivate.onActivate() for signal description.
      Field SIGNAL_ON_ACTIVATE contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onStateSet

      public SignalHandler onStateSet(Switch.OnStateSet signal)
      Connect to signal "state-set".
      See Switch.OnStateSet.onStateSet(boolean) for signal description.
      Field SIGNAL_ON_STATE_SET contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asActionable

      public Actionable asActionable()
      Implements interface Actionable. Call this to get access to interface functions.
      Returns:
      Actionable
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()