1.196 <GtkSwitch>

Class: <GtkSwitch>

It derives from <GtkWidget>.

Shows a "light switch" that has two states: on or off.

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 switch:active property), while the trough color indicates the present underlying state (represented by the switch:state property).

See 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 Gtk.AccessibleRole.switch role.

Properties

Property: switch:active self

Whether the <GtkSwitch> widget is in its on or off state.

Its value is a boolean.

Set it with (set! (switch:active self) value).

Property: switch:state self

The backend state that is controlled by the switch.

Applications should usually set the switch:active property, except when indicating a change to the backend state which occurs separately from the user’s interaction.

See switch:state-set for details.

Its value is a boolean.

Set it with (set! (switch:state self) value).

Procedures

Method: switch:get-active? self ⇒ %return
Method: get-active? self ⇒ %return

Gets whether the <GtkSwitch> is in its “on” or “off” state.

self

Passed: a <GtkSwitch>.

a <GtkSwitch>

%return

Returned: a boolean.

#t if the <GtkSwitch> is active, and #f otherwise

Method: switch:get-state? self ⇒ %return
Method: get-state? self ⇒ %return

Gets the underlying state of the <GtkSwitch>.

self

Passed: a <GtkSwitch>.

a <GtkSwitch>

%return

Returned: a boolean.

the underlying state

Procedure: switch:new ⇒ %return

Creates a new <GtkSwitch> widget.

%return

Returned: a <GtkWidget>.

the newly created <GtkSwitch> instance

Method: switch:set-active self is-active
Method: set-active self is-active

Changes the state of self to the desired one.

self

Passed: a <GtkSwitch>.

a <GtkSwitch>

is-active

Passed: a boolean.

#t if self should be active, and #f otherwise

Method: switch:set-state self state
Method: set-state self state

Sets the underlying state of the <GtkSwitch>.

This function is typically called from a switch:state-set signal handler in order to set up delayed state changes.

See switch:state-set for details.

self

Passed: a <GtkSwitch>.

a <GtkSwitch>

state

Passed: a boolean.

the new state

Signals

Signal: switch:activate

Connect a handler with (connect object switch:activate handler). It is called as (handler self).

Emitted to animate the switch.

Applications should never connect to this signal, but use the switch:active property.

self

Passed: a <GtkSwitch>.

Signal: switch:state-set

Connect a handler with (connect object switch:state-set handler). It is called as (handler self state) ⇒ %return.

Emitted to change the underlying state.

The ::state-set signal is emitted when the user changes the switch position. The default handler calls switch:set-state with the value of state.

To implement delayed state change, applications can connect to this signal, initiate the change of the underlying state, and call switch:set-state when the underlying state change is complete. The signal handler should return #t to prevent the default handler from running.

self

Passed: a <GtkSwitch>.

state

Passed: a boolean.

the new state of the switch

%return

Returned: a boolean.

#t to stop the signal emission