Button
open class Button : Bin, ButtonProtocol
The GtkButton
widget is generally used to trigger a callback function that is
called when the button is pressed. The various signals and how to use them
are outlined below.
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.
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 GtkToggleButton
, GtkMenuButton
, GtkVolumeButton
,
GtkLockButton
, GtkColorButton
, GtkFontButton
or GtkFileChooserButton
use
style classes such as .toggle, .popup, .scale, .lock, .color, .font, .file
to differentiate themselves from a plain GtkButton.
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, usegtk_container_add()
.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.
This function is a convenience wrapper around
gtk_button_new()
andgtk_button_set_image()
.Declaration
Swift
@inlinable public init(iconName: UnsafePointer<gchar>? = nil, size: GtkIconSize)
-
Creates a new
GtkButton
containing the image and text from a stock item. Some stock ids have preprocessor macros likeGTK_STOCK_OK
andGTK_STOCK_APPLY
.If
stock_id
is unknown, then it will be treated as a mnemonic label (as forgtk_button_new_with_mnemonic()
).new_from_stock is deprecated: Stock items are deprecated. Use gtk_button_new_with_label() instead.
Declaration
Swift
@available(*, deprecated) @inlinable public init(stock stockID: UnsafePointer<gchar>!)
-
Creates a
GtkButton
widget with aGtkLabel
child containing the given text.Declaration
Swift
@inlinable public init(label: UnsafePointer<gchar>!)
-
Creates a new
GtkButton
containing a label. If characters inlabel
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<gchar>!)
-
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.
This function is a convenience wrapper around
gtk_button_new()
andgtk_button_set_image()
.Declaration
Swift
@inlinable public static func newFrom(iconName: UnsafePointer<gchar>? = nil, size: GtkIconSize) -> Widget!
-
Creates a new
GtkButton
containing the image and text from a stock item. Some stock ids have preprocessor macros likeGTK_STOCK_OK
andGTK_STOCK_APPLY
.If
stock_id
is unknown, then it will be treated as a mnemonic label (as forgtk_button_new_with_mnemonic()
).new_from_stock is deprecated: Stock items are deprecated. Use gtk_button_new_with_label() instead.
Declaration
Swift
@available(*, deprecated) @inlinable public static func newFrom(stock stockID: UnsafePointer<gchar>!) -> Widget!
-
Creates a
GtkButton
widget with aGtkLabel
child containing the given text.Declaration
Swift
@inlinable public static func newWith(label: UnsafePointer<gchar>!) -> Widget!
-
Creates a new
GtkButton
containing a label. If characters inlabel
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<gchar>!) -> Widget!