PopoverMenuProtocol

public protocol PopoverMenuProtocol : PopoverProtocol

GtkPopoverMenu is a subclass of GtkPopover that implements menu behavior.

An example GtkPopoverMenu

GtkPopoverMenu treats its children like menus and allows switching between them. It can open submenus as traditional, nested submenus, or in a more touch-friendly sliding fashion.

GtkPopoverMenu is meant to be used primarily with menu models, using [ctorGtk.PopoverMenu.new_from_model]. If you need to put other widgets such as a GtkSpinButton or a GtkSwitch into a popover, you can use [methodGtk.PopoverMenu.add_child].

For more dialog-like behavior, use a plain GtkPopover.

The XML format understood by GtkBuilder for GMenuModel consists of a toplevel <menu> element, which contains one or more <item> elements. Each <item> element contains <attribute> and <link> elements with a mandatory name attribute. <link> elements have the same content model as <menu>. Instead of <link name="submenu"> or <link name="section">, you can use <submenu> or <section> elements.

<menu id='app-menu'>
  <section>
    <item>
      <attribute name='label' translatable='yes'>_New Window</attribute>
      <attribute name='action'>app.new</attribute>
    </item>
    <item>
      <attribute name='label' translatable='yes'>_About Sunny</attribute>
      <attribute name='action'>app.about</attribute>
    </item>
    <item>
      <attribute name='label' translatable='yes'>_Quit</attribute>
      <attribute name='action'>app.quit</attribute>
    </item>
  </section>
</menu>

Attribute values can be translated using gettext, like other GtkBuilder content. <attribute> elements can be marked for translation with a translatable="yes" attribute. It is also possible to specify message context and translator comments, using the context and comments attributes. To make use of this, the GtkBuilder must have been given the gettext domain to use.

The following attributes are used when constructing menu items:

  • “label”: a user-visible string to display
  • “action”: the prefixed name of the action to trigger
  • “target”: the parameter to use when activating the action
  • “icon” and “verb-icon”: names of icons that may be displayed
  • “submenu-action”: name of an action that may be used to track whether a submenu is open
  • “hidden-when”: a string used to determine when the item will be hidden. Possible values include “action-disabled”, “action-missing”, “macos-menubar”. This is mainly useful for exported menus, see [methodGtk.Application.set_menubar].
  • “custom”: a string used to match against the ID of a custom child added with [methodGtk.PopoverMenu.add_child], [methodGtk.PopoverMenuBar.add_child], or in the ui file with <child type="ID">.

The following attributes are used when constructing sections:

  • “label”: a user-visible string to use as section heading
  • “display-hint”: a string used to determine special formatting for the section. Possible values include “horizontal-buttons”, “circular-buttons” and “inline-buttons”. They all indicate that section should be displayed as a horizontal row of buttons.
  • “text-direction”: a string used to determine the GtkTextDirection to use when “display-hint” is set to “horizontal-buttons”. Possible values include “rtl”, “ltr”, and “none”.

The following attributes are used when constructing submenus:

  • “label”: a user-visible string to display
  • “icon”: icon name to display

Menu items will also show accelerators, which are usually associated with actions via [methodGtk.Application.set_accels_for_action], [idgtk_widget_class_add_binding_action] or [methodGtk.ShortcutController.add_shortcut].

CSS Nodes

GtkPopoverMenu is just a subclass of GtkPopover that adds custom content to it, therefore it has the same CSS nodes. It is one of the cases that add a .menu style class to the popover’s main node.

Accessibility

GtkPopoverMenu uses the GTK_ACCESSIBLE_ROLE_MENU role, and its items use the GTK_ACCESSIBLE_ROLE_MENU_ITEM, GTK_ACCESSIBLE_ROLE_MENU_ITEM_CHECKBOX or GTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO roles, depending on the action they are connected to.

The PopoverMenuProtocol protocol exposes the methods and properties of an underlying GtkPopoverMenu 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 PopoverMenu. Alternatively, use PopoverMenuRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkPopoverMenu instance.

    Declaration

    Swift

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

    Typed pointer to the underlying GtkPopoverMenu instance.

    Default Implementation

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

    Declaration

    Swift

    var popover_menu_ptr: UnsafeMutablePointer<GtkPopoverMenu>! { get }
  • Required Initialiser for types conforming to PopoverMenuProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

PopoverMenu Class

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

    Declaration

    Swift

    @discardableResult
    @inlinable
    func bind<Q, T>(property source_property: PopoverMenuPropertyName, 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 PopoverMenu property

    Declaration

    Swift

    @inlinable
    func get(property: PopoverMenuPropertyName) -> 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 PopoverMenu property. Note that this will only have an effect on properties that are writable and not construct-only!

    Declaration

    Swift

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

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

PopoverMenu Class: PopoverMenuProtocol extension (methods and fields)

  • add(child:id:) Extension method

    Adds a custom widget to a generated menu.

    For this to work, the menu model of popover must have an item with a custom attribute that matches id.

    Declaration

    Swift

    @inlinable
    func add<WidgetT>(child: WidgetT, id: UnsafePointer<CChar>!) -> Bool where WidgetT : WidgetProtocol
  • getMenuModel() Extension method

    Returns the menu model used to populate the popover.

    Declaration

    Swift

    @inlinable
    func getMenuModel() -> GIO.MenuModelRef!
  • remove(child:) Extension method

    Removes a widget that has previously been added with gtk_popover_menu_add_child().

    Declaration

    Swift

    @inlinable
    func remove<WidgetT>(child: WidgetT) -> Bool where WidgetT : WidgetProtocol
  • setMenu(model:) Extension method

    Sets a new menu model on popover.

    The existing contents of popover are removed, and the popover is populated with new contents according to model.

    Declaration

    Swift

    @inlinable
    func setMenu(model: GIO.MenuModelRef? = nil)
  • setMenu(model:) Extension method

    Sets a new menu model on popover.

    The existing contents of popover are removed, and the popover is populated with new contents according to model.

    Declaration

    Swift

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

    Returns the menu model used to populate the popover.

    Declaration

    Swift

    @inlinable
    var menuModel: GIO.MenuModelRef! { get nonmutating set }