ToggleButton
open class ToggleButton : Button, ToggleButtonProtocol
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 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
ToggleButton
instance.Declaration
Swift
@inlinable public init(_ op: UnsafeMutablePointer<GtkToggleButton>)
Parameters
op
pointer to the underlying object
-
Designated initialiser from a constant pointer to the underlying
C
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theToggleButton
instance.Declaration
Swift
@inlinable public init(_ op: UnsafePointer<GtkToggleButton>)
Parameters
op
pointer to the underlying object
-
Optional initialiser from a non-mutating
gpointer
to the underlyingC
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theToggleButton
instance.Declaration
Swift
@inlinable override public init!(gpointer op: gpointer?)
Parameters
op
gpointer to the underlying object
-
Optional initialiser from a non-mutating
gconstpointer
to the underlyingC
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theToggleButton
instance.Declaration
Swift
@inlinable override public init!(gconstpointer op: gconstpointer?)
Parameters
op
pointer to the underlying object
-
Optional initialiser from a constant pointer to the underlying
C
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theToggleButton
instance.Declaration
Swift
@inlinable public init!(_ op: UnsafePointer<GtkToggleButton>?)
Parameters
op
pointer to the underlying object
-
Optional initialiser from the underlying
C
data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theToggleButton
instance.Declaration
Swift
@inlinable public init!(_ op: UnsafeMutablePointer<GtkToggleButton>?)
Parameters
op
pointer to the underlying object
-
Designated initialiser from the underlying
C
data type. Will retainGtkToggleButton
. i.e., ownership is transferred to theToggleButton
instance.Declaration
Swift
@inlinable public init(retaining op: UnsafeMutablePointer<GtkToggleButton>)
Parameters
op
pointer to the underlying object
-
Reference intialiser for a related type that implements
ToggleButtonProtocol
Will retainGtkToggleButton
.Declaration
Swift
@inlinable public init<T>(toggleButton other: T) where T : ToggleButtonProtocol
Parameters
other
an 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
cPointer
pointer 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
cPointer
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(raw p: UnsafeRawPointer)
Parameters
p
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 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
p
mutable 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
raw
mutable 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
p
opaque 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
p
opaque pointer to the underlying object
-
Creates a new toggle button. A widget should be packed into the button, as in
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<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 override public init(mnemonic label: UnsafePointer<gchar>!)
-
Creates a new toggle button with a text label.
Declaration
Swift
@inlinable public static func toggleButtonNewWith(label: UnsafePointer<gchar>!) -> Widget!
-
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 public static func toggleButtonNewWith(mnemonic label: UnsafePointer<gchar>!) -> Widget!