Klasse Switch

Alle implementierten Schnittstellen:
PointerInterface

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

<picture>
<source srcset="switch-dark.png" media="(prefers-color-scheme: dark)">
<img alt="An example GtkSwitch" src="switch.png">
</picture>

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

`GtkSwitch` can also express situations where the underlying state changes
with a delay. In this case, the slider position indicates the user's recent
change (represented by the [property@Gtk.Switch:active] property), while the
trough color indicates the present underlying state (represented by the
[property@Gtk.Switch:state] property).

<picture>
<source srcset="switch-state-dark.png" media="(prefers-color-scheme: dark)">
<img alt="GtkSwitch with delayed state change" src="switch-state.png">
</picture>

See [signal@Gtk.Switch::state-set] for details.

# Shortcuts and Gestures

`GtkSwitch` supports pan and drag gestures to move the slider.

# CSS nodes

```
switch
├── image
├── image
╰── slider
```

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

# Accessibility

`GtkSwitch` uses the [enum@Gtk.AccessibleRole.switch] role.

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

  • Felddetails

  • Konstruktordetails

    • Switch

      public Switch(PointerContainer pointer)
    • Switch

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

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getActive

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

      public boolean getState()
      Gets the underlying state of the `GtkSwitch`.
      Gibt zurück:
      the underlying state
    • setActive

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

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

      This function is typically called from a [signal@Gtk.Switch::state-set]
      signal handler in order to set up delayed state changes.

      See [signal@Gtk.Switch::state-set] for details.
      Parameter:
      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.
      Parameter:
      signal - callback function (lambda).
      Gibt zurück:
      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.
      Parameter:
      signal - callback function (lambda).
      Gibt zurück:
      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.
      Setzt außer Kraft:
      asAccessible in Klasse Widget
      Gibt zurück:
      Accessible
    • asActionable

      public Actionable asActionable()
      Implements interface Actionable. Call this to get access to interface functions.
      Gibt zurück:
      Actionable
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Setzt außer Kraft:
      asBuildable in Klasse Widget
      Gibt zurück:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Setzt außer Kraft:
      asConstraintTarget in Klasse Widget
      Gibt zurück:
      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()