ToggleButtonRef
public struct ToggleButtonRef : ToggleButtonProtocol, GWeakCapturing
A GtkToggleButton
is a GtkButton
which will remain “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 gtk_toggle_button_new()
or
gtk_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
gtk_toggle_button_set_active()
, and retrieved using
gtk_toggle_button_get_active()
.
To simply switch the state of a toggle button, use gtk_toggle_button_toggled()
.
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.
(C Language Example):
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 (GTK_WINDOW_TOPLEVEL);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
text = "Hi, I’m a toggle button.";
toggle1 = gtk_toggle_button_new_with_label (text);
// Makes this toggle button invisible
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle1),
TRUE);
g_signal_connect (toggle1, "toggled",
G_CALLBACK (output_state),
NULL);
gtk_container_add (GTK_CONTAINER (box), toggle1);
text = "Hi, I’m a toggle button.";
toggle2 = gtk_toggle_button_new_with_label (text);
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle2),
FALSE);
g_signal_connect (toggle2, "toggled",
G_CALLBACK (output_state),
NULL);
gtk_container_add (GTK_CONTAINER (box), toggle2);
gtk_container_add (GTK_CONTAINER (window), box);
gtk_widget_show_all (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_ptr
property instead.Declaration
Swift
public let ptr: UnsafeMutableRawPointer!
-
Designated initialiser from the underlying
C
data typeDeclaration
Swift
@inlinable init(_ p: UnsafeMutablePointer<GtkToggleButton>)
-
Designated initialiser from a constant pointer to the underlying
C
data typeDeclaration
Swift
@inlinable init(_ p: UnsafePointer<GtkToggleButton>)
-
Conditional initialiser from an optional pointer to the underlying
C
data typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafeMutablePointer<GtkToggleButton>?)
-
Conditional initialiser from an optional, non-mutable pointer to the underlying
C
data typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafePointer<GtkToggleButton>?)
-
Conditional initialiser from an optional
gpointer
Declaration
Swift
@inlinable init!(gpointer g: gpointer?)
-
Conditional initialiser from an optional, non-mutable
gconstpointer
Declaration
Swift
@inlinable init!(gconstpointer g: gconstpointer?)
-
Reference intialiser for a related type that implements
ToggleButtonProtocol
Declaration
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
gtk_button_new()
.Declaration
Swift
@inlinable init()
-
Creates a new toggle button with a text label.
Declaration
Swift
@inlinable init(label: UnsafePointer<gchar>!)
-
Creates a new
GtkToggleButton
containing a label. The label will be created usinggtk_label_new_with_mnemonic()
, so underscores inlabel
indicate the mnemonic for the button.Declaration
Swift
@inlinable init(mnemonic label: UnsafePointer<gchar>!)
-
Creates a new toggle button with a text label.
Declaration
Swift
@inlinable static func toggleButtonNewWith(label: UnsafePointer<gchar>!) -> WidgetRef!
-
Creates a new
GtkToggleButton
containing a label. The label will be created usinggtk_label_new_with_mnemonic()
, so underscores inlabel
indicate the mnemonic for the button.Declaration
Swift
@inlinable static func toggleButtonNewWith(mnemonic label: UnsafePointer<gchar>!) -> WidgetRef!