PopoverMenu
open class PopoverMenu : Popover, PopoverMenuProtocol
GtkPopoverMenu
is a subclass of GtkPopover
that implements menu
behavior.
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
.
Menu models
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 [method
Gtk.Application.set_menubar
]. - “custom”: a string used to match against the ID of a custom child added with
[method
Gtk.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 PopoverMenu
type acts as a reference-counted owner of an underlying GtkPopoverMenu
instance.
It provides the methods that can operate on this data type through PopoverMenuProtocol
conformance.
Use PopoverMenu
as a strong reference or owner of a GtkPopoverMenu
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
PopoverMenu
instance.Declaration
Swift
@inlinable public init(_ op: UnsafeMutablePointer<GtkPopoverMenu>)
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 thePopoverMenu
instance.Declaration
Swift
@inlinable public init(_ op: UnsafePointer<GtkPopoverMenu>)
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 thePopoverMenu
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 thePopoverMenu
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 thePopoverMenu
instance.Declaration
Swift
@inlinable public init!(_ op: UnsafePointer<GtkPopoverMenu>?)
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 thePopoverMenu
instance.Declaration
Swift
@inlinable public init!(_ op: UnsafeMutablePointer<GtkPopoverMenu>?)
Parameters
op
pointer to the underlying object
-
Designated initialiser from the underlying
C
data type. Will retainGtkPopoverMenu
. i.e., ownership is transferred to thePopoverMenu
instance.Declaration
Swift
@inlinable public init(retaining op: UnsafeMutablePointer<GtkPopoverMenu>)
Parameters
op
pointer to the underlying object
-
Reference intialiser for a related type that implements
PopoverMenuProtocol
Will retainGtkPopoverMenu
.Declaration
Swift
@inlinable public init<T>(popoverMenu other: T) where T : PopoverMenuProtocol
Parameters
other
an instance of a related type that implements
PopoverMenuProtocol
-
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
PopoverMenuProtocol
.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
PopoverMenuProtocol
.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
PopoverMenuProtocol
.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
PopoverMenuProtocol
.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
PopoverMenuProtocol
.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
PopoverMenuProtocol
.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
PopoverMenuProtocol
.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
PopoverMenuProtocol
.Declaration
Swift
@inlinable override public init(retainingOpaquePointer p: OpaquePointer)
Parameters
p
opaque pointer to the underlying object
-
Creates a
GtkPopoverMenu
and populates it according tomodel
.The created buttons are connected to actions found in the
GtkApplicationWindow
to which the popover belongs - typically by means of being attached to a widget that is contained within theGtkApplicationWindow
s widget hierarchy.Actions can also be added using [method
Gtk.Widget.insert_action_group
] on the menus attach widget or on any of its parent widgets.This function creates menus with sliding submenus. See [ctor
Gtk.PopoverMenu.new_from_model_full
] for a way to control this.Declaration
Swift
@inlinable public init<MenuModelT>(model: MenuModelT?) where MenuModelT : MenuModelProtocol
-
Creates a
GtkPopoverMenu
and populates it according tomodel
.The created buttons are connected to actions found in the action groups that are accessible from the parent widget. This includes the
GtkApplicationWindow
to which the popover belongs. Actions can also be added using [methodGtk.Widget.insert_action_group
] on the parent widget or on any of its parent widgets.The only flag that is supported currently is
GTK_POPOVER_MENU_NESTED
, which makes GTK create traditional, nested submenus instead of the default sliding submenus.Declaration
Swift
@inlinable public init<MenuModelT>(modelFull model: MenuModelT, flags: PopoverMenuFlags) where MenuModelT : MenuModelProtocol
-
Creates a
GtkPopoverMenu
and populates it according tomodel
.The created buttons are connected to actions found in the
GtkApplicationWindow
to which the popover belongs - typically by means of being attached to a widget that is contained within theGtkApplicationWindow
s widget hierarchy.Actions can also be added using [method
Gtk.Widget.insert_action_group
] on the menus attach widget or on any of its parent widgets.This function creates menus with sliding submenus. See [ctor
Gtk.PopoverMenu.new_from_model_full
] for a way to control this.Declaration
Swift
@inlinable public static func newFrom<MenuModelT>(model: MenuModelT?) -> Widget! where MenuModelT : MenuModelProtocol
-
Creates a
GtkPopoverMenu
and populates it according tomodel
.The created buttons are connected to actions found in the action groups that are accessible from the parent widget. This includes the
GtkApplicationWindow
to which the popover belongs. Actions can also be added using [methodGtk.Widget.insert_action_group
] on the parent widget or on any of its parent widgets.The only flag that is supported currently is
GTK_POPOVER_MENU_NESTED
, which makes GTK create traditional, nested submenus instead of the default sliding submenus.Declaration
Swift
@inlinable public static func newFrom<MenuModelT>(modelFull model: MenuModelT, flags: PopoverMenuFlags) -> Widget! where MenuModelT : MenuModelProtocol