Gnome::Gtk4::ToggleButton
Description
A Gnome::Gtk4::ToggleButton is a button which remains “pressed-in” when clicked.
Clicking again will cause the toggle button to return to its normal state.
A toggle button is created by calling either .newtogglebutton()
or .new-with-label()
. If using the former, it is advisable to pack a widget, (such as a Gnome::Gtk4::Label and/or a Gnome::Gtk4::Image), into the toggle button’s container. (See Gnome::Gtk4::Button for more information).
The state of a Gnome::Gtk4::ToggleButton can be set specifically using .set-active()
, and retrieved using .get-active()
.
To simply switch the state of a toggle button, use .toggled()
.
Grouping
Toggle buttons can be grouped together, to form mutually exclusive groups - only one of the buttons can be toggled at a time, and toggling another one will switch the currently toggled one off.
To add a Gnome::Gtk4::ToggleButton to a group, use .set-group()
.
CSS nodes
Gnome::Gtk4::ToggleButton has a single CSS node with name button. To differentiate it from a plain Gnome::Gtk4::Button, it gets the `.toggle` style class.
Accessibility
Gnome::Gtk4::ToggleButton uses the GTK_ACCESSIBLE_ROLE_TOGGLE_BUTTON
role.
Creating two Gnome::Gtk4::ToggleButton widgets.
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-togglebutton
Creates a new toggle button.
A widget should be packed into the button, as in .newtogglebutton() in class Gnome::Gtk4::Button
.
method new-togglebutton ( --> Gnome::Gtk4::ToggleButton \)
new-with-label
Creates a new toggle button with a text label.
method new-with-label ( Str $label --> Gnome::Gtk4::ToggleButton \)
$label; a string containing the message to be placed in the toggle button..
new-with-mnemonic
Creates a new Gnome::Gtk4::ToggleButton containing a label.
The label will be created using .new-with-mnemonic() in class Gnome::Gtk4::Label
, so underscores in $label
indicate the mnemonic for the button.
method new-with-mnemonic ( Str $label --> Gnome::Gtk4::ToggleButton \)
$label; the text of the button, with an underscore in front of the mnemonic character.
Methods
get-active
Queries a Gnome::Gtk4::ToggleButton and returns its current state.
Returns True
if the toggle button is pressed in and False
if it is raised.
method get-active (--> Bool )
Return value; whether the button is pressed.
set-active
Sets the status of the toggle button.
Set to True
if you want the Gnome::Gtk4::ToggleButton to be “pressed in”, and False
to raise it.
If the status of the button changes, this action causes the toggled signal to be emitted.
method set-active ( Bool() $is-active )
$is-active;
True
orFalse
..
set-group
Adds $self
to the group of $group
.
In a group of multiple toggle buttons, only one button can be active at a time.
Setting up groups in a cycle leads to undefined behavior.
Note that the same effect can be achieved via the Gnome::Gtk4::R-Actionable API, by using the same action with parameter type and state type 's' for all buttons in the group, and giving each button its own target value.
method set-group ( N-Object() $group )
$group; another Gnome::Gtk4::ToggleButton to form a group with.
toggled
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Emits the toggled signal on the Gnome::Gtk4::ToggleButton.
method toggled ( )
Signals
toggled
Emitted whenever the Gnome::Gtk4::ToggleButton's state is changed.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::ToggleButton :$_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::ToggleButton 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.