Button
open class Button : Widget, ButtonProtocol
The GtkButton
widget is generally used to trigger a callback function that is
called when the button is pressed.
The GtkButton
widget can hold any valid child widget. That is, it can hold
almost any other standard GtkWidget
. The most commonly used child is the
GtkLabel
.
CSS nodes
GtkButton
has a single CSS node with name button. The node will get the
style classes .image-button or .text-button, if the content is just an
image or label, respectively. It may also receive the .flat style class.
When activating a button via the keyboard, the button will temporarily
gain the .keyboard-activating style class.
Other style classes that are commonly used with GtkButton
include
.suggested-action and .destructive-action. In special cases, buttons
can be made round by adding the .circular style class.
Button-like widgets like [classGtk.ToggleButton
], [classGtk.MenuButton
],
[classGtk.VolumeButton
], [classGtk.LockButton
], [classGtk.ColorButton
]
or [classGtk.FontButton
] use style classes such as .toggle, .popup, .scale,
.lock, .color on the button node to differentiate themselves from a plain
GtkButton
.
Accessibility
GtkButton
uses the GTK_ACCESSIBLE_ROLE_BUTTON
role.
The Button
type acts as a reference-counted owner of an underlying GtkButton
instance.
It provides the methods that can operate on this data type through ButtonProtocol
conformance.
Use Button
as a strong reference or owner of a GtkButton
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
Button
instance.Declaration
Swift
@inlinable public init(_ op: UnsafeMutablePointer<GtkButton>)
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 theButton
instance.Declaration
Swift
@inlinable public init(_ op: UnsafePointer<GtkButton>)
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 theButton
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 theButton
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 theButton
instance.Declaration
Swift
@inlinable public init!(_ op: UnsafePointer<GtkButton>?)
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 theButton
instance.Declaration
Swift
@inlinable public init!(_ op: UnsafeMutablePointer<GtkButton>?)
Parameters
op
pointer to the underlying object
-
Designated initialiser from the underlying
C
data type. Will retainGtkButton
. i.e., ownership is transferred to theButton
instance.Declaration
Swift
@inlinable public init(retaining op: UnsafeMutablePointer<GtkButton>)
Parameters
op
pointer to the underlying object
-
Reference intialiser for a related type that implements
ButtonProtocol
Will retainGtkButton
.Declaration
Swift
@inlinable public init<T>(button other: T) where T : ButtonProtocol
Parameters
other
an instance of a related type that implements
ButtonProtocol
-
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
ButtonProtocol
.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
ButtonProtocol
.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
ButtonProtocol
.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
ButtonProtocol
.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
ButtonProtocol
.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
ButtonProtocol
.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
ButtonProtocol
.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
ButtonProtocol
.Declaration
Swift
@inlinable override public init(retainingOpaquePointer p: OpaquePointer)
Parameters
p
opaque pointer to the underlying object
-
Creates a new
GtkButton
widget.To add a child widget to the button, use [method
Gtk.Button.set_child
].Declaration
Swift
@inlinable public init()
-
Creates a new button containing an icon from the current icon theme.
If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
Declaration
Swift
@inlinable public init(iconName: UnsafePointer<CChar>? = nil)
-
Creates a
GtkButton
widget with aGtkLabel
child.Declaration
Swift
@inlinable public init(label: UnsafePointer<CChar>!)
-
Creates a new
GtkButton
containing a label.If characters in
label
are preceded by an underscore, they are underlined. If you need a literal underscore character in a label, use “__” (two underscores). The first underlined character represents a keyboard accelerator called a mnemonic. Pressing Alt and that key activates the button.Declaration
Swift
@inlinable public init(mnemonic label: UnsafePointer<CChar>!)
-
Creates a new button containing an icon from the current icon theme.
If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
Declaration
Swift
@inlinable public static func newFrom(iconName: UnsafePointer<CChar>? = nil) -> Widget!
-
Creates a
GtkButton
widget with aGtkLabel
child.Declaration
Swift
@inlinable public static func newWith(label: UnsafePointer<CChar>!) -> Widget!
-
Creates a new
GtkButton
containing a label.If characters in
label
are preceded by an underscore, they are underlined. If you need a literal underscore character in a label, use “__” (two underscores). The first underlined character represents a keyboard accelerator called a mnemonic. Pressing Alt and that key activates the button.Declaration
Swift
@inlinable public static func newWith(mnemonic label: UnsafePointer<CChar>!) -> Widget!