About my projects, examples and tutorials
Gnome::Gtk4::Switch

Gnome::Gtk4::Switch

Description§

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

UNKNOWN image§

=for image :class<inline> :src<asset_files/images/switch.png> :width<30\%>

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).

UNKNOWN image§

=for image :class<inline> :src<asset_files/images/switch-state.png> :width<30\%>

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.

Uml Diagram§

UNKNOWN image§

=for image :class<inline> :src<asset_files/images/plantuml/Switch.png> :width<70\%>

Class initialization§

new§

:native-object§

Create an object using a native object from an object of the same type found elsewhere. See also Gnome::N::TopLevelSupportClass.

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

new-switch§

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

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

Methods§

get-active§

Gets whether the Gnome::Gtk4::Switch is in its ā€œonā€ or ā€œoffā€ state.

method get-active (--> Bool )
Code

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 )
Code

Return value; the underlying state.

set-active§

Changes the state of $self to the desired one.

method set-active ( Bool() $is-active )
Code
  • $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 )
Code
  • $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,
  *%user-options
)
Code
  • $_handle_id; The registered event handler id.
  • $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::Switch object.
  • %user-options; A list of named arguments provided by .register-signal() in class 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,
  *%user-options
  --> gboolean
)
Code
  • $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 is a native Gnome::Gtk4::Switch object.
  • %user-options; A list of named arguments provided by .register-signal() in class Object.

Return value; True to stop the signal emission