ButtonRef

public struct ButtonRef : ButtonProtocol, GWeakCapturing

The GtkButton widget is generally used to trigger a callback function that is called when the button is pressed.

An example GtkButton

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 ButtonRef type acts as a lightweight Swift reference to an underlying GtkButton instance. It exposes methods that can operate on this data type through ButtonProtocol conformance. Use ButtonRef only as an unowned reference to an existing GtkButton instance.

  • ptr
    Untyped pointer to the underlying `GtkButton` instance.
    

    For type-safe access, use the generated, typed pointer button_ptr property instead.

    Declaration

    Swift

    public let ptr: UnsafeMutableRawPointer!

Button Class

  • Designated initialiser from the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafeMutablePointer<GtkButton>)
  • Designated initialiser from a constant pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafePointer<GtkButton>)
  • Conditional initialiser from an optional pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafeMutablePointer<GtkButton>?)
  • Conditional initialiser from an optional, non-mutable pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafePointer<GtkButton>?)
  • 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 ButtonProtocol

    Declaration

    Swift

    @inlinable
    init<T>(_ other: T) where T : ButtonProtocol
  • This factory is syntactic sugar for setting weak pointers wrapped in GWeak<T>

    Declaration

    Swift

    @inlinable
    static func unowned<T>(_ other: T) -> ButtonRef where T : ButtonProtocol
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ButtonProtocol.

    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 ButtonProtocol.

    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 ButtonProtocol.

    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 ButtonProtocol.

    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 ButtonProtocol.

    Declaration

    Swift

    @inlinable
    init(opaquePointer: OpaquePointer)
  • Creates a new `GtkButton` widget.
    

    To add a child widget to the button, use [methodGtk.Button.set_child].

    Declaration

    Swift

    @inlinable
    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
    init(iconName: UnsafePointer<CChar>? = nil)
  • Creates a GtkButton widget with a GtkLabel child.

    Declaration

    Swift

    @inlinable
    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
    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
    static func newFrom(iconName: UnsafePointer<CChar>? = nil) -> WidgetRef!
  • Creates a GtkButton widget with a GtkLabel child.

    Declaration

    Swift

    @inlinable
    static func newWith(label: UnsafePointer<CChar>!) -> WidgetRef!
  • 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
    static func newWith(mnemonic label: UnsafePointer<CChar>!) -> WidgetRef!