Gnome::Gtk4::Switch
#------------------------------------------------------------------------------- #--[Class Description]---------------------------------------------------------- #-------------------------------------------------------------------------------
Description
Gnome::Gtk4::Switch is a "light switch" that has two states: on or off.
=for image :src<asset_files/images/switch.png> :width<30%> :class<inline>
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).
=for image :src<asset_files/images/switch-state.png> :width<30%> :class<inline>
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 =for image :src<asset_files/images/plantuml/Switch.png> :width<70%> :class<inline>
#------------------------------------------------------------------------------- #--[Class Initialization]------------------------------------------------------- #-------------------------------------------------------------------------------
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! )
#-------------------------------------------------------------------------------
new-switch
Creates a new Gnome::Gtk4::Switch widget.
method new-switch ( --> Gnome::Gtk4::Switch )
#------------------------------------------------------------------------------- #--[Methods]-------------------------------------------------------------------- #-------------------------------------------------------------------------------
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;
Trueif$selfshould be active, andFalseotherwise.
#-------------------------------------------------------------------------------
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.
#------------------------------------------------------------------------------- #--[Signal Documentation]------------------------------------------------------- #-------------------------------------------------------------------------------
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
)
$_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
)
$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