A subclass of GtkPopover that implements menu behavior.
<picture> <source srcset="menu-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkPopoverMenu" src="menu.png"> </picture> 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. The property [propertyGtk.PopoverMenu:flags] controls this appearance.
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.
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 - "use-markup": whether the
text in the menu item includes [Pango
markup](https://docs.gtk.org/Pango/pango_markup.html) - "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
- "gtk-macos-special": (macOS only, ignored by others) Add special meaning
to a menu in the macOS menu bar. See [Using GTK on Apple macOS](osx.html).
Menu items will also show accelerators, which are usually associated with
actions via [methodGtk.Application.set_accels_for_action],
[methodWidgetclass.add_binding_action] or
[methodGtk.ShortcutController.add_shortcut].
# Shortcuts and Gestures
`GtkPopoverMenu` supports the following keyboard shortcuts:
- <kbd>Space</kbd> activates the default widget.
# 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 main `popover` node.
Menu items have nodes with name `button` and class `.model`. If a section
display-hint is set, the section gets a node `box` with class `horizontal`
plus a class with the same text as the display hint. Note that said box may
not be the direct ancestor of the item `button`s. Thus, for example, to
style items in an `inline-buttons` section, select `.inline-buttons
button.model`. Other things that may be of interest to style in menus
include `label` nodes.
# Accessibility
`GtkPopoverMenu` uses the [enumGtk.AccessibleRole.menu] role, and its
items use the [enumGtk.AccessibleRole.menu_item],
[enumGtk.AccessibleRole.checkbox] or
[enumGtk.AccessibleRole.menu_item_radio] roles, depending on the action
they are connected to.
<group>Menus and Toolbars</group>
<gtkada_demo>create_menu.adb</gtkada_demo>
function "+"
(Widget : access Gtk_Popover_Menu_Record'Class)
return Gtk.Accessible.Gtk_Accessible
function "+"
(Widget : access Gtk_Popover_Menu_Record'Class)
return Gtk.Buildable.Gtk_Buildable
function "+"
(Widget : access Gtk_Popover_Menu_Record'Class)
return Gtk.Constraint_Target.Gtk_Constraint_Target
function "+"
(Widget : access Gtk_Popover_Menu_Record'Class)
return Gtk.Native.Gtk_Native
function "+"
(Widget : access Gtk_Popover_Menu_Record'Class)
return Gtk.Shortcut_Manager.Gtk_Shortcut_Manager
function "-"
(Interf : Gtk.Accessible.Gtk_Accessible)
return Gtk_Popover_Menu
function "-"
(Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_Popover_Menu
function "-"
(Interf : Gtk.Constraint_Target.Gtk_Constraint_Target)
return Gtk_Popover_Menu
function "-"
(Interf : Gtk.Native.Gtk_Native)
return Gtk_Popover_Menu
function "-"
(Interf : Gtk.Shortcut_Manager.Gtk_Shortcut_Manager)
return Gtk_Popover_Menu
function Add_Child
(Self : not null access Gtk_Popover_Menu_Record;
Child : not null access Gtk.Widget.Gtk_Widget_Record'Class;
Id : UTF8_String) return Boolean
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.
the GtkWidget to add
the ID to insert Child at
True if Id was found and the widget added
procedure Announce
(Self : not null access Gtk_Popover_Menu_Record;
Message : UTF8_String;
Priority : Gtk.Accessible.Gtk_Accessible_Announcement_Priority)
Flags_Property : constant Gtk.Popover_Menu.Property_Gtk_Popover_Menu_Flags;
Type: Gtk_Popover_Menu_Flags The flags that Popover uses to create/display a menu from its model.
If a model is set and the flags change, contents are rebuilt, so if setting properties individually, set flags before model to avoid a redundant rebuild.
function Get_Accessible_Id
(Self : not null access Gtk_Popover_Menu_Record) return UTF8_String
function Get_Accessible_Parent
(Self : not null access Gtk_Popover_Menu_Record)
return Gtk.Accessible.Gtk_Accessible
function Get_Accessible_Role
(Self : not null access Gtk_Popover_Menu_Record)
return Gtk.Accessible.Gtk_Accessible_Role
function Get_At_Context
(Self : not null access Gtk_Popover_Menu_Record)
return Gtk.Atcontext.Gtk_Atcontext
function Get_Bounds
(Self : not null access Gtk_Popover_Menu_Record;
X : out Glib.Gint;
Y : out Glib.Gint;
Width : out Glib.Gint;
Height : out Glib.Gint) return Boolean
function Get_First_Accessible_Child
(Self : not null access Gtk_Popover_Menu_Record)
return Gtk.Accessible.Gtk_Accessible
function Get_Flags
(Self : not null access Gtk_Popover_Menu_Record)
return Gtk_Popover_Menu_Flags
Returns the flags that Popover uses to create/display a menu from its model. Since: gtk+ 4.14
the GtkPopoverMenuFlags
function Get_Menu_Model
(Self : not null access Gtk_Popover_Menu_Record)
return Glib.Menu_Model.Gmenu_Model
Returns the menu model used to populate the popover.
the menu model of Popover. Has transfer-ownership='none'.
function Get_Next_Accessible_Sibling
(Self : not null access Gtk_Popover_Menu_Record)
return Gtk.Accessible.Gtk_Accessible
function Get_Platform_State
(Self : not null access Gtk_Popover_Menu_Record;
State : Gtk.Accessible.Gtk_Accessible_Platform_State) return Boolean
function Get_Surface
(Self : not null access Gtk_Popover_Menu_Record)
return Gdk.Gdk_Surface
procedure Get_Surface_Transform
(Self : not null access Gtk_Popover_Menu_Record;
X : out Gdouble;
Y : out Gdouble)
function Get_Type return Glib.GType
procedure Gtk_New_From_Model
(Self : out Gtk_Popover_Menu;
Model : access Glib.Menu_Model.Gmenu_Model_Record'Class)
Creates a GtkPopoverMenu and populates it according to Model. 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 the GtkApplicationWindows widget hierarchy. Actions can also be added using [methodGtk.Widget.insert_action_group] on the menus attach widget or on any of its parent widgets. This function creates menus with sliding submenus. See [ctorGtk.PopoverMenu.new_from_model_full] for a way to control this. Initialize_From_Model does nothing if the object was already created with another call to Initialize* or G_New.
a GMenuModel
procedure Gtk_New_From_Model_Full
(Self : out Gtk_Popover_Menu;
Model : not null access Glib.Menu_Model.Gmenu_Model_Record'Class;
Flags : Gtk_Popover_Menu_Flags)
Creates a GtkPopoverMenu and populates it according to Model. 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. Initialize_From_Model_Full does nothing if the object was already created with another call to Initialize* or G_New.
a GMenuModel
flags that affect how the menu is created
type Gtk_Popover_Menu is access all Gtk_Popover_Menu_Record'Class;
type Gtk_Popover_Menu_Flags is mod 2 ** Integer'Size;
Flags that affect how [classGtk.PopoverMenu] widgets built from a [classGio.MenuModel] are created and displayed.
package Gtk_Popover_Menu_Flags_Properties is
new Generic_Internal_Flags_Property (Gtk_Popover_Menu_Flags);
function Gtk_Popover_Menu_New_From_Model
(Model : access Glib.Menu_Model.Gmenu_Model_Record'Class)
return Gtk_Popover_Menu
Creates a GtkPopoverMenu and populates it according to Model. 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 the GtkApplicationWindows widget hierarchy. Actions can also be added using [methodGtk.Widget.insert_action_group] on the menus attach widget or on any of its parent widgets. This function creates menus with sliding submenus. See [ctorGtk.PopoverMenu.new_from_model_full] for a way to control this.
a GMenuModel
function Gtk_Popover_Menu_New_From_Model_Full
(Model : not null access Glib.Menu_Model.Gmenu_Model_Record'Class;
Flags : Gtk_Popover_Menu_Flags) return Gtk_Popover_Menu
Creates a GtkPopoverMenu and populates it according to Model. 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.
a GMenuModel
flags that affect how the menu is created
type Gtk_Popover_Menu_Record is new Gtk_Popover_Record with null record;
package Implements_Gtk_Accessible is new Glib.Types.Implements
(Gtk.Accessible.Gtk_Accessible, Gtk_Popover_Menu_Record, Gtk_Popover_Menu);
package Implements_Gtk_Buildable is new Glib.Types.Implements
(Gtk.Buildable.Gtk_Buildable, Gtk_Popover_Menu_Record, Gtk_Popover_Menu);
package Implements_Gtk_Constraint_Target is new Glib.Types.Implements
(Gtk.Constraint_Target.Gtk_Constraint_Target, Gtk_Popover_Menu_Record, Gtk_Popover_Menu);
package Implements_Gtk_Native is new Glib.Types.Implements
(Gtk.Native.Gtk_Native, Gtk_Popover_Menu_Record, Gtk_Popover_Menu);
package Implements_Gtk_Shortcut_Manager is new Glib.Types.Implements
(Gtk.Shortcut_Manager.Gtk_Shortcut_Manager, Gtk_Popover_Menu_Record, Gtk_Popover_Menu);
procedure Initialize_From_Model
(Self : not null access Gtk_Popover_Menu_Record'Class;
Model : access Glib.Menu_Model.Gmenu_Model_Record'Class)
Creates a GtkPopoverMenu and populates it according to Model. 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 the GtkApplicationWindows widget hierarchy. Actions can also be added using [methodGtk.Widget.insert_action_group] on the menus attach widget or on any of its parent widgets. This function creates menus with sliding submenus. See [ctorGtk.PopoverMenu.new_from_model_full] for a way to control this. Initialize_From_Model does nothing if the object was already created with another call to Initialize* or G_New.
a GMenuModel
procedure Initialize_From_Model_Full
(Self : not null access Gtk_Popover_Menu_Record'Class;
Model : not null access Glib.Menu_Model.Gmenu_Model_Record'Class;
Flags : Gtk_Popover_Menu_Flags)
Creates a GtkPopoverMenu and populates it according to Model. 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. Initialize_From_Model_Full does nothing if the object was already created with another call to Initialize* or G_New.
a GMenuModel
flags that affect how the menu is created
Menu_Model_Property : constant Glib.Properties.Property_Boxed;
Type: Gio.Menu_Model The model from which the menu is made.
Popover_Menu_Nested : constant Gtk_Popover_Menu_Flags := 1;
Popover_Menu_Sliding : constant Gtk_Popover_Menu_Flags := 0;
type Property_Gtk_Popover_Menu_Flags is new Gtk_Popover_Menu_Flags_Properties.Property;
procedure Realize (Self : not null access Gtk_Popover_Menu_Record)
function Remove_Child
(Self : not null access Gtk_Popover_Menu_Record;
Child : not null access Gtk.Widget.Gtk_Widget_Record'Class)
return Boolean
Removes a widget that has previously been added with [methodGtk.PopoverMenu.add_child]
the GtkWidget to remove
True if the widget was removed
procedure Reset_Property
(Self : not null access Gtk_Popover_Menu_Record;
Property : Gtk.Accessible.Gtk_Accessible_Property)
procedure Reset_Relation
(Self : not null access Gtk_Popover_Menu_Record;
Relation : Gtk.Accessible.Gtk_Accessible_Relation)
procedure Reset_State
(Self : not null access Gtk_Popover_Menu_Record;
State : Gtk.Accessible.Gtk_Accessible_State)
procedure Set_Accessible_Parent
(Self : not null access Gtk_Popover_Menu_Record;
Parent : Gtk.Accessible.Gtk_Accessible;
Next_Sibling : Gtk.Accessible.Gtk_Accessible)
procedure Set_Flags
(Self : not null access Gtk_Popover_Menu_Record;
Flags : Gtk_Popover_Menu_Flags)
Sets the flags that Popover uses to create/display a menu from its model. If a model is set and the flags change, contents are rebuilt, so if setting properties individually, set flags before model to avoid a redundant rebuild. Since: gtk+ 4.14
a set of GtkPopoverMenuFlags
procedure Set_Menu_Model
(Self : not null access Gtk_Popover_Menu_Record;
Model : access Glib.Menu_Model.Gmenu_Model_Record'Class)
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.
a GMenuModel
procedure Unrealize (Self : not null access Gtk_Popover_Menu_Record)
procedure Update_Next_Accessible_Sibling
(Self : not null access Gtk_Popover_Menu_Record;
New_Sibling : Gtk.Accessible.Gtk_Accessible)
procedure Update_Platform_State
(Self : not null access Gtk_Popover_Menu_Record;
State : Gtk.Accessible.Gtk_Accessible_Platform_State)
Visible_Submenu_Property : constant Glib.Properties.Property_String;
The name of the visible submenu.