PopoverMenu

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 [ctor@Gtk.PopoverMenu.new_from_model]. If you need to put other widgets such as a GtkSpinButton or a GtkSwitch into a popover, you can use [method@Gtk.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 determine if a submenu can be opened - "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], [method@Gtk.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 [method@Gtk.Application.set_accels_for_action], [id@gtk_widget_class_add_binding_action] or [method@Gtk.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.

Constructors

this
this(GtkPopoverMenu* gtkPopoverMenu, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(MenuModel model)

Creates a GtkPopoverMenu and populates it according to @model.

this
this(MenuModel model, GtkPopoverMenuFlags flags)

Creates a GtkPopoverMenu and populates it according to @model.

Members

Functions

addChild
bool addChild(Widget child, string id)

Adds a custom widget to a generated menu.

getMenuModel
MenuModel getMenuModel()

Returns the menu model used to populate the popover.

getPopoverMenuStruct
GtkPopoverMenu* getPopoverMenuStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

removeChild
bool removeChild(Widget child)

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

setMenuModel
void setMenuModel(MenuModel model)

Sets a new menu model on @popover.

Static functions

getType
GType getType()

Variables

gtkPopoverMenu
GtkPopoverMenu* gtkPopoverMenu;

the main Gtk struct

Inherited Members

From Popover

gtkPopover
GtkPopover* gtkPopover;

the main Gtk struct

getPopoverStruct
GtkPopover* getPopoverStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

__anonymous
mixin NativeT!(GtkPopover)
Undocumented in source.
__anonymous
mixin ShortcutManagerT!(GtkPopover)
Undocumented in source.
getType
GType getType()
getAutohide
bool getAutohide()

Returns whether the popover is modal.

getCascadePopdown
bool getCascadePopdown()

Returns whether the popover will close after a modal child is closed.

getChild
Widget getChild()

Gets the child widget of @popover.

getHasArrow
bool getHasArrow()

Gets whether this popover is showing an arrow pointing at the widget that it is relative to.

getMnemonicsVisible
bool getMnemonicsVisible()

Gets whether mnemonics are visible.

getOffset
void getOffset(int xOffset, int yOffset)

Gets the offset previous set with gtk_popover_set_offset().

getPointingTo
bool getPointingTo(GdkRectangle rect)

Gets the rectangle that the popover points to.

getPosition
GtkPositionType getPosition()

Returns the preferred position of @popover.

popdown
void popdown()

Pops @popover down.

popup
void popup()

Pops @popover up.

present
void present()

Presents the popover to the user.

setAutohide
void setAutohide(bool autohide)

Sets whether @popover is modal.

setCascadePopdown
void setCascadePopdown(bool cascadePopdown)

If @cascade_popdown is %TRUE, the popover will be closed when a child modal popover is closed.

setChild
void setChild(Widget child)

Sets the child widget of @popover.

setDefaultWidget
void setDefaultWidget(Widget widget)

Sets the default widget of a GtkPopover.

setHasArrow
void setHasArrow(bool hasArrow)

Sets whether this popover should draw an arrow pointing at the widget it is relative to.

setMnemonicsVisible
void setMnemonicsVisible(bool mnemonicsVisible)

Sets whether mnemonics should be visible.

setOffset
void setOffset(int xOffset, int yOffset)

Sets the offset to use when calculating the position of the popover.

setPointingTo
void setPointingTo(GdkRectangle* rect)

Sets the rectangle that @popover points to.

setPosition
void setPosition(GtkPositionType position)

Sets the preferred position for @popover to appear.

addOnActivateDefault
gulong addOnActivateDefault(void delegate(Popover) dlg, ConnectFlags connectFlags)

Emitted whend the user activates the default widget.

addOnClosed
gulong addOnClosed(void delegate(Popover) dlg, ConnectFlags connectFlags)

Emitted when the popover is closed.

Meta