ToggleButtonRef
public struct ToggleButtonRef : ToggleButtonProtocol, GWeakCapturing
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 ToggleButtonRef type acts as a lightweight Swift reference to an underlying GtkToggleButton instance.
It exposes methods that can operate on this data type through ToggleButtonProtocol conformance.
Use ToggleButtonRef only as an unowned reference to an existing GtkToggleButton instance.
-
Untyped pointer to the underlying `GtkToggleButton` instance.For type-safe access, use the generated, typed pointer
toggle_button_ptrproperty instead.Declaration
Swift
public let ptr: UnsafeMutableRawPointer!
-
Designated initialiser from the underlying
Cdata typeDeclaration
Swift
@inlinable init(_ p: UnsafeMutablePointer<GtkToggleButton>) -
Designated initialiser from a constant pointer to the underlying
Cdata typeDeclaration
Swift
@inlinable init(_ p: UnsafePointer<GtkToggleButton>) -
Conditional initialiser from an optional pointer to the underlying
Cdata typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafeMutablePointer<GtkToggleButton>?) -
Conditional initialiser from an optional, non-mutable pointer to the underlying
Cdata typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafePointer<GtkToggleButton>?) -
Conditional initialiser from an optional
gpointerDeclaration
Swift
@inlinable init!(gpointer g: gpointer?) -
Conditional initialiser from an optional, non-mutable
gconstpointerDeclaration
Swift
@inlinable init!(gconstpointer g: gconstpointer?) -
Reference intialiser for a related type that implements
ToggleButtonProtocolDeclaration
Swift
@inlinable init<T>(_ other: T) where T : ToggleButtonProtocol -
This factory is syntactic sugar for setting weak pointers wrapped in
GWeak<T>Declaration
Swift
@inlinable static func unowned<T>(_ other: T) -> ToggleButtonRef where T : ToggleButtonProtocol -
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable init<T>(cPointer: UnsafeMutablePointer<T>) -
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable init<T>(constPointer: UnsafePointer<T>) -
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable init(mutating 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 init(raw: UnsafeMutableRawPointer) -
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ToggleButtonProtocol.Declaration
Swift
@inlinable init(opaquePointer: OpaquePointer) -
Creates a new toggle button.A widget should be packed into the button, as in [ctor
Gtk.Button.new].Declaration
Swift
@inlinable init() -
Creates a new toggle button with a text label.
Declaration
Swift
@inlinable 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 init(mnemonic label: UnsafePointer<CChar>!) -
Creates a new toggle button with a text label.
Declaration
Swift
@inlinable static func toggleButtonNewWith(label: UnsafePointer<CChar>!) -> WidgetRef! -
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 static func toggleButtonNewWith(mnemonic label: UnsafePointer<CChar>!) -> WidgetRef!
View on GitHub
Install in Dash
ToggleButtonRef Structure Reference