ToggleButton
open class ToggleButton : Button, ToggleButtonProtocol
A GtkToggleButton 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 [ctorGtk.ToggleButton.new] or
[ctorGtk.ToggleButton.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 [classGtk.Button] for more information).
The state of a GtkToggleButton can be set specifically using
[methodGtk.ToggleButton.set_active], and retrieved using
[methodGtk.ToggleButton.get_active].
To simply switch the state of a toggle button, use
[methodGtk.ToggleButton.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 GtkToggleButton to a group, use [methodGtk.ToggleButton.set_group].
CSS nodes
GtkToggleButton has a single CSS node with name button. To differentiate
it from a plain GtkButton, it gets the .toggle style class.
Creating two GtkToggleButton widgets.
static void output_state (GtkToggleButton *source, gpointer user_data)
{
printf ("Active: `d`\n", gtk_toggle_button_get_active (source));
}
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 a toggle button.";
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 a toggle button.";
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_widget_show (window);
}
The ToggleButton type acts as a reference-counted owner of an underlying GtkToggleButton instance.
It provides the methods that can operate on this data type through ToggleButtonProtocol conformance.
Use ToggleButton as a strong reference or owner of a GtkToggleButton instance.
-
Designated initialiser from the underlying `C` data type.This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the
ToggleButtoninstance.Declaration
Swift
@inlinable public init(_ op: UnsafeMutablePointer<GtkToggleButton>)Parameters
oppointer to the underlying object
-
Designated initialiser from a constant pointer to the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theToggleButtoninstance.Declaration
Swift
@inlinable public init(_ op: UnsafePointer<GtkToggleButton>)Parameters
oppointer to the underlying object
-
Optional initialiser from a non-mutating
gpointerto the underlyingCdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theToggleButtoninstance.Declaration
Swift
@inlinable override public init!(gpointer op: gpointer?)Parameters
opgpointer to the underlying object
-
Optional initialiser from a non-mutating
gconstpointerto the underlyingCdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theToggleButtoninstance.Declaration
Swift
@inlinable override public init!(gconstpointer op: gconstpointer?)Parameters
oppointer to the underlying object
-
Optional initialiser from a constant pointer to the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theToggleButtoninstance.Declaration
Swift
@inlinable public init!(_ op: UnsafePointer<GtkToggleButton>?)Parameters
oppointer to the underlying object
-
Optional initialiser from the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theToggleButtoninstance.Declaration
Swift
@inlinable public init!(_ op: UnsafeMutablePointer<GtkToggleButton>?)Parameters
oppointer to the underlying object
-
Designated initialiser from the underlying
Cdata type. Will retainGtkToggleButton. i.e., ownership is transferred to theToggleButtoninstance.Declaration
Swift
@inlinable public init(retaining op: UnsafeMutablePointer<GtkToggleButton>)Parameters
oppointer to the underlying object
-
Reference intialiser for a related type that implements
ToggleButtonProtocolWill retainGtkToggleButton.Declaration
Swift
@inlinable public init<T>(toggleButton other: T) where T : ToggleButtonProtocolParameters
otheran instance of a related type that implements
ToggleButtonProtocol -
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable override public init<T>(cPointer p: UnsafeMutablePointer<T>)Parameters
cPointerpointer to the underlying object
-
Unsafe typed, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable override public init<T>(retainingCPointer cPointer: UnsafeMutablePointer<T>)Parameters
cPointerpointer to the underlying object
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable override public init(raw p: UnsafeRawPointer)Parameters
praw pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable override public init(retainingRaw raw: UnsafeRawPointer) -
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable public required init(raw p: UnsafeMutableRawPointer)Parameters
pmutable raw pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable required public init(retainingRaw raw: UnsafeMutableRawPointer)Parameters
rawmutable raw pointer to the underlying object
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable override public init(opaquePointer p: OpaquePointer)Parameters
popaque pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable override public init(retainingOpaquePointer p: OpaquePointer)Parameters
popaque pointer to the underlying object
-
Creates a new toggle button.
A widget should be packed into the button, as in [ctor
Gtk.Button.new].Declaration
Swift
@inlinable override public init() -
Creates a new toggle button with a text label.
Declaration
Swift
@inlinable override public init(label: UnsafePointer<CChar>!) -
Creates a new
GtkToggleButtoncontaining a label.The label will be created using [ctor
Gtk.Label.new_with_mnemonic], so underscores inlabelindicate the mnemonic for the button.Declaration
Swift
@inlinable override public init(mnemonic label: UnsafePointer<CChar>!) -
Creates a new toggle button with a text label.
Declaration
Swift
@inlinable public static func toggleButtonNewWith(label: UnsafePointer<CChar>!) -> Widget! -
Creates a new
GtkToggleButtoncontaining a label.The label will be created using [ctor
Gtk.Label.new_with_mnemonic], so underscores inlabelindicate the mnemonic for the button.Declaration
Swift
@inlinable public static func toggleButtonNewWith(mnemonic label: UnsafePointer<CChar>!) -> Widget!
View on GitHub
Install in Dash
ToggleButton Class Reference