MenuButtonProtocol

public protocol MenuButtonProtocol : ToggleButtonProtocol

The GtkMenuButton widget is used to display a popup when clicked on. This popup can be provided either as a GtkMenu, a GtkPopover or an abstract GMenuModel.

The GtkMenuButton widget can hold any valid child widget. That is, it can hold almost any other standard GtkWidget. The most commonly used child is GtkImage. If no widget is explicitely added to the GtkMenuButton, a GtkImage is automatically created, using an arrow image oriented according to GtkMenuButton:direction or the generic “open-menu-symbolic” icon if the direction is not set.

The positioning of the popup is determined by the GtkMenuButton:direction property of the menu button.

For menus, the GtkWidget:halign and GtkWidget:valign properties of the menu are also taken into account. For example, when the direction is GTK_ARROW_DOWN and the horizontal alignment is GTK_ALIGN_START, the menu will be positioned below the button, with the starting edge (depending on the text direction) of the menu aligned with the starting edge of the button. If there is not enough space below the button, the menu is popped up above the button instead. If the alignment would move part of the menu offscreen, it is “pushed in”.

Direction = Down

  • halign = start

  • halign = center

  • halign = end

Direction = Up

  • halign = start

  • halign = center

  • halign = end

Direction = Left

  • valign = start

  • valign = center

  • valign = end

Direction = Right

  • valign = start

  • valign = center

  • valign = end

CSS nodes

GtkMenuButton has a single CSS node with name button. To differentiate it from a plain GtkButton, it gets the .popup style class.

The MenuButtonProtocol protocol exposes the methods and properties of an underlying GtkMenuButton instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see MenuButton. Alternatively, use MenuButtonRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkMenuButton instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • menu_button_ptr Default implementation

    Typed pointer to the underlying GtkMenuButton instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkMenuButton instance.

    Declaration

    Swift

    var menu_button_ptr: UnsafeMutablePointer<GtkMenuButton>! { get }
  • Required Initialiser for types conforming to MenuButtonProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

MenuButton Class

  • Bind a MenuButtonPropertyName source property to a given target object.

    Declaration

    Swift

    @discardableResult
    @inlinable
    func bind<Q, T>(property source_property: MenuButtonPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocol

    Parameters

    source_property

    the source property to bind

    target

    the target object to bind to

    target_property

    the target property to bind to

    flags

    the flags to pass to the Binding

    transform_from

    ValueTransformer to use for forward transformation

    transform_to

    ValueTransformer to use for backwards transformation

    Return Value

    binding reference or nil in case of an error

  • get(property:) Extension method

    Get the value of a MenuButton property

    Declaration

    Swift

    @inlinable
    func get(property: MenuButtonPropertyName) -> GLibObject.Value

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

  • set(property:value:) Extension method

    Set the value of a MenuButton property. Note that this will only have an effect on properties that are writable and not construct-only!

    Declaration

    Swift

    @inlinable
    func set(property: MenuButtonPropertyName, value v: GLibObject.Value)

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

MenuButton Class: MenuButtonProtocol extension (methods and fields)

  • getAlignWidget() Extension method

    Returns the parent GtkWidget to use to line up with menu.

    Declaration

    Swift

    @inlinable
    func getAlignWidget() -> WidgetRef!
  • getDirection() Extension method

    Returns the direction the popup will be pointing at when popped up.

    Declaration

    Swift

    @inlinable
    func getDirection() -> GtkArrowType
  • getMenuModel() Extension method

    Returns the GMenuModel used to generate the popup.

    Declaration

    Swift

    @inlinable
    func getMenuModel() -> GIO.MenuModelRef!
  • getPopover() Extension method

    Returns the GtkPopover that pops out of the button. If the button is not using a GtkPopover, this function returns nil.

    Declaration

    Swift

    @inlinable
    func getPopover() -> PopoverRef!
  • getPopup() Extension method

    Returns the GtkMenu that pops out of the button. If the button does not use a GtkMenu, this function returns nil.

    Declaration

    Swift

    @inlinable
    func getPopup() -> MenuRef!
  • getUsePopover() Extension method

    Returns whether a GtkPopover or a GtkMenu will be constructed from the menu model.

    Declaration

    Swift

    @inlinable
    func getUsePopover() -> Bool
  • set(alignWidget:) Extension method

    Sets the GtkWidget to use to line the menu with when popped up. Note that the align_widget must contain the GtkMenuButton itself.

    Setting it to nil means that the menu will be aligned with the button itself.

    Note that this property is only used with menus currently, and not for popovers.

    Declaration

    Swift

    @inlinable
    func set(alignWidget: WidgetRef? = nil)
  • set(alignWidget:) Extension method

    Sets the GtkWidget to use to line the menu with when popped up. Note that the align_widget must contain the GtkMenuButton itself.

    Setting it to nil means that the menu will be aligned with the button itself.

    Note that this property is only used with menus currently, and not for popovers.

    Declaration

    Swift

    @inlinable
    func set<WidgetT>(alignWidget: WidgetT?) where WidgetT : WidgetProtocol
  • set(direction:) Extension method

    Sets the direction in which the popup will be popped up, as well as changing the arrow’s direction. The child will not be changed to an arrow if it was customized.

    If the does not fit in the available space in the given direction, GTK+ will its best to keep it inside the screen and fully visible.

    If you pass GTK_ARROW_NONE for a direction, the popup will behave as if you passed GTK_ARROW_DOWN (although you won’t see any arrows).

    Declaration

    Swift

    @inlinable
    func set(direction: GtkArrowType)
  • set(menuModel:) Extension method

    Sets the GMenuModel from which the popup will be constructed, or nil to dissociate any existing menu model and disable the button.

    Depending on the value of GtkMenuButton:use-popover, either a GtkMenu will be created with gtk_menu_new_from_model(), or a GtkPopover with gtk_popover_new_from_model(). In either case, actions will be connected as documented for these functions.

    If GtkMenuButton:popup or GtkMenuButton:popover are already set, those widgets are dissociated from the menu_button, and those properties are set to nil.

    Declaration

    Swift

    @inlinable
    func set(menuModel: GIO.MenuModelRef? = nil)
  • set(menuModel:) Extension method

    Sets the GMenuModel from which the popup will be constructed, or nil to dissociate any existing menu model and disable the button.

    Depending on the value of GtkMenuButton:use-popover, either a GtkMenu will be created with gtk_menu_new_from_model(), or a GtkPopover with gtk_popover_new_from_model(). In either case, actions will be connected as documented for these functions.

    If GtkMenuButton:popup or GtkMenuButton:popover are already set, those widgets are dissociated from the menu_button, and those properties are set to nil.

    Declaration

    Swift

    @inlinable
    func set<MenuModelT>(menuModel: MenuModelT?) where MenuModelT : MenuModelProtocol
  • set(popover:) Extension method

    Sets the GtkPopover that will be popped up when the menu_button is clicked, or nil to dissociate any existing popover and disable the button.

    If GtkMenuButton:menu-model or GtkMenuButton:popup are set, those objects are dissociated from the menu_button, and those properties are set to nil.

    Declaration

    Swift

    @inlinable
    func set(popover: WidgetRef? = nil)
  • set(popover:) Extension method

    Sets the GtkPopover that will be popped up when the menu_button is clicked, or nil to dissociate any existing popover and disable the button.

    If GtkMenuButton:menu-model or GtkMenuButton:popup are set, those objects are dissociated from the menu_button, and those properties are set to nil.

    Declaration

    Swift

    @inlinable
    func set<WidgetT>(popover: WidgetT?) where WidgetT : WidgetProtocol
  • setPopup(menu:) Extension method

    Sets the GtkMenu that will be popped up when the menu_button is clicked, or nil to dissociate any existing menu and disable the button.

    If GtkMenuButton:menu-model or GtkMenuButton:popover are set, those objects are dissociated from the menu_button, and those properties are set to nil.

    Declaration

    Swift

    @inlinable
    func setPopup(menu: WidgetRef? = nil)
  • setPopup(menu:) Extension method

    Sets the GtkMenu that will be popped up when the menu_button is clicked, or nil to dissociate any existing menu and disable the button.

    If GtkMenuButton:menu-model or GtkMenuButton:popover are set, those objects are dissociated from the menu_button, and those properties are set to nil.

    Declaration

    Swift

    @inlinable
    func setPopup<WidgetT>(menu: WidgetT?) where WidgetT : WidgetProtocol
  • set(usePopover:) Extension method

    Sets whether to construct a GtkPopover instead of GtkMenu when gtk_menu_button_set_menu_model() is called. Note that this property is only consulted when a new menu model is set.

    Declaration

    Swift

    @inlinable
    func set(usePopover: Bool)
  • alignWidget Extension method

    Returns the parent GtkWidget to use to line up with menu.

    Declaration

    Swift

    @inlinable
    var alignWidget: WidgetRef! { get nonmutating set }
  • direction Extension method

    The GtkArrowType representing the direction in which the menu or popover will be popped out.

    Declaration

    Swift

    @inlinable
    var direction: GtkArrowType { get nonmutating set }
  • menuModel Extension method

    Returns the GMenuModel used to generate the popup.

    Declaration

    Swift

    @inlinable
    var menuModel: GIO.MenuModelRef! { get nonmutating set }
  • popover Extension method

    The GtkPopover that will be popped up when the button is clicked.

    Declaration

    Swift

    @inlinable
    var popover: PopoverRef! { get nonmutating set }
  • popup Extension method

    The GtkMenu that will be popped up when the button is clicked.

    Declaration

    Swift

    @inlinable
    var popup: MenuRef! { get nonmutating set }
  • usePopover Extension method

    Returns whether a GtkPopover or a GtkMenu will be constructed from the menu model.

    Declaration

    Swift

    @inlinable
    var usePopover: Bool { get nonmutating set }
  • parent Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var parent: GtkToggleButton { get }