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

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

Uml Diagram§

UNKNOWN image§

=for image :class<inline> :src<asset_files/images/plantuml/ToggleButton.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-togglebutton§

Creates a new toggle button.

A widget should be packed into the button, as in .newtogglebutton() in class Gnome.

method new-togglebutton ( --> Gnome::Gtk4::ToggleButton )
Code

new-with-label§

Creates a new toggle button with a text label.

method new-with-label ( Str $label --> Gnome::Gtk4::ToggleButton )
Code
  • $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, so underscores in $label indicate the mnemonic for the button.

method new-with-mnemonic ( Str $label --> Gnome::Gtk4::ToggleButton )
Code
  • $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 )
Code

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 )
Code
  • $is-active; True or False..

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 )
Code
  • $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 ( )
Code

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,
  *%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::ToggleButton object.
  • %user-options; A list of named arguments provided by .register-signal() in class Gnome.