GtkSwitch
A toggle switch widget.
Preview
CSS Node Tree
switch[:checked]
├── image (on icon)
├── image (off icon)
└── sliderProps
Prop
Type
Behavior
- Click, tap, Space or Enter to toggle: the slider slides over, then
activechanges andonStateSetis called - Drag the slider horizontally: it follows the pointer, and the switch turns on if you let go past the middle
- Clicking doesn't move the keyboard focus to the switch
activeplaces the slider;statecolors the trough (:checked) and followsactivewhen not provided- For a delayed change (e.g., connecting to WiFi), pass your backend's value as
stateand start the change inonStateSet: the slider moves right away, the trough oncestatedoes. This is GTK'sstate-sethandler returningTRUE. onStateSetcallback can returnfalseto reject the changedisabledmakes the switch insensitive: dimmed, out of the tab order, and ignoring input
Animation
The slider slides for 100ms with an ease-out-cubic curve, matching the native GTK behavior. As in GTK, active changes when it gets there, or right away when the user prefers reduced motion.