About all my projects
Gnome::Gtk4::Switch

Gnome::Gtk4::Switch

Description

Gnome::Gtk4::Switch is a "light switch" that has two states: on or off.

No caption

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

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

No caption

See state-set for details.

CSS nodes

Gnome::Gtk4::Switch 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

Gnome::Gtk4::Switch uses the GTK_ACCESSIBLE_ROLE_SWITCH role.

Class initialization

new

:native-object

Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.

multi method new ( N-Object :$native-object! )

new-switch

Creates a new Gnome::Gtk4::Switch widget.

method new-switch ( --> Gnome::Gtk4::Switch \)

Methods

get-active

Gets whether the Gnome::Gtk4::Switch is in its “on” or “off” state.

method get-active (--> Bool )

Return value; True if the Gnome::Gtk4::Switch is active, and False otherwise.

get-state

Gets the underlying state of the Gnome::Gtk4::Switch.

method get-state (--> Bool )

Return value; the underlying state.

set-active

Changes the state of $self to the desired one.

method set-active ( Bool() $is-active )
  • $is-active; True if $self should be active, and False otherwise.

set-state

Sets the underlying state of the Gnome::Gtk4::Switch.

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

See state-set for details.

method set-state ( Bool() $state )
  • $state; the new state.

Signals

activate

Emitted to animate the switch.

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

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::Switch :$_widget,
  *C<user>-options
)
  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Switch object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

state-set

Emitted to change the underlying state.

The state-set signal is emitted when the user changes the switch position. The default handler calls .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 .set-state() when the underlying state change is complete. The signal handler should return True to prevent the default handler from running.

method handler (
  gboolean $state,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::Switch :$_widget,
  *C<user>-options
  --> gboolean
)
  • $state; the new state of the switch.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Switch object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

Return value; True to stop the signal emission