It derives from <GtkButton>.
Shows 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 toggle-button:new or toggle-button:new-with-label. If using the former, it
is advisable to pack a widget, (such as a <GtkLabel>
and/or a <GtkImage>), into the toggle button’s
container. (See <GtkButton> for more information).
The state of a <GtkToggleButton> can be set
specifically using toggle-button:set-active, and retrieved using
toggle-button:get-active?.
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 <GtkToggleButton> to a group, use
toggle-button:set-group.
<GtkToggleButton> has a single CSS node with
name button. To differentiate it from a plain
<GtkButton>, it gets the .toggle style
class.
<GtkToggleButton> uses the
Gtk.AccessibleRole.toggle_button role.
static void
output_state (GtkToggleButton *source,
gpointer user_data)
{
g_print ("Toggle button "%s" is active: %s",
gtk_button_get_label (GTK_BUTTON (source)),
gtk_toggle_button_get_active (source) ? "Yes" : "No");
}
static void
make_toggles (void)
{
GtkWidget *window, *toggle1, *toggle2;
GtkWidget *box;
const char *text;
window = gtk_window_new ();
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
text = "Hi, I’m toggle button one";
toggle1 = gtk_toggle_button_new_with_label (text);
g_signal_connect (toggle1, "toggled",
G_CALLBACK (output_state),
NULL);
gtk_box_append (GTK_BOX (box), toggle1);
text = "Hi, I’m toggle button two";
toggle2 = gtk_toggle_button_new_with_label (text);
g_signal_connect (toggle2, "toggled",
G_CALLBACK (output_state),
NULL);
gtk_box_append (GTK_BOX (box), toggle2);
gtk_window_set_child (GTK_WINDOW (window), box);
gtk_window_present (GTK_WINDOW (window));
}
If the toggle button should be pressed in.
Its value is a boolean.
Set it with (set! (toggle-button:active self) value).
The toggle button whose group this widget belongs to.
Its value is a <GtkToggleButton>, or
#f.
It can only be set, with (set! (toggle-button:group self) value).
Queries a <GtkToggleButton> and returns its
current state.
Returns #t if the toggle button is pressed in and #f if it
is raised.
Passed: a <GtkToggleButton>.
Returned: a boolean.
whether the button is pressed
Creates a new toggle button.
A widget should be packed into the button, as in button:new.
Returned: a <GtkWidget>.
a new toggle button.
Creates a new toggle button with a text label.
Passed: a string.
a string containing the message to be placed in the toggle button.
Returned: a <GtkWidget>.
a new toggle button.
Creates a new <GtkToggleButton> containing a
label.
The label will be created using label:new-with-mnemonic, so underscores in
label indicate the mnemonic for the button.
Passed: a string.
the text of the button, with an underscore in front of the mnemonic character
Returned: a <GtkWidget>.
a new <GtkToggleButton>
Sets the status of the toggle button.
Set to #t if you want the
<GtkToggleButton> to be “pressed in”, and
#f to raise it.
If the status of the button changes, this action causes the
toggle-button:toggled signal
to be emitted.
Passed: a <GtkToggleButton>.
Passed: a boolean.
#t or #f.
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
<GtkActionable> 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.
Passed: a <GtkToggleButton>.
Passed, or left out: a <GtkToggleButton>, or
#f.
another <GtkToggleButton> to form a group
with
Emits the ::toggled signal on the
<GtkToggleButton>.
Passed: a <GtkToggleButton>.
Connect a handler with (connect object toggle-button:toggled
handler). It is called as (handler self).
Emitted whenever the <GtkToggleButton>’s
state is changed.
Passed: a <GtkToggleButton>.
Emits the ::toggled signal on the
<GtkToggleButton>.
To override it in a new class, give register-type #:vfuncs
`((toggled . ,procedure)). The procedure is called as
(procedure self).
Passed: the class whose implementation to call:
<GtkToggleButton>, or a class that derives
from it, or its GType number.
Passed: a <GtkToggleButton>.