GtkPopoverMenu

GtkPopoverMenu — Popovers to use as menus

Properties

GMenuModel * menu-model Read / Write
gchar * visible-submenu Read / Write

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── GtkWidget
            ╰── GtkPopover
                ╰── GtkPopoverMenu

Implemented Interfaces

GtkPopoverMenu implements AtkImplementorIface, GtkBuildable, GtkConstraintTarget, GtkShortcutManager and GtkNative.

Includes

#include <gtk/gtk.h>

Description

GtkPopoverMenu is a subclass of GtkPopover that 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 gtk_popover_menu_new_from_model(). If you need to put other widgets such as GtkSpinButton or GtkSwitch into a popover, 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<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 gtk_application_set_menubar().

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 gtk_application_set_accels_for_action(), gtk_widget_class_add_binding_action() or gtk_shortcut_controller_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.

Functions

gtk_popover_menu_new_from_model ()

GtkWidget *
gtk_popover_menu_new_from_model (GMenuModel *model);

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 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 gtk_popover_menu_new_from_model_full() for a way to control this.

Parameters

model

a GMenuModel, or NULL.

[allow-none]

Returns

the new GtkPopoverMenu


gtk_popover_menu_new_from_model_full ()

GtkWidget *
gtk_popover_menu_new_from_model_full (GMenuModel *model,
                                      GtkPopoverMenuFlags 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 gtk_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.

Parameters

model

a GMenuModel

 

flags

flags that affect how the menu is created

 

Returns

the new GtkPopoverMenu.

[transfer full]


gtk_popover_menu_set_menu_model ()

void
gtk_popover_menu_set_menu_model (GtkPopoverMenu *popover,
                                 GMenuModel *model);

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 .

Parameters

popover

a GtkPopoverMenu

 

model

a GMenuModel, or NULL.

[nullable]

gtk_popover_menu_get_menu_model ()

GMenuModel *
gtk_popover_menu_get_menu_model (GtkPopoverMenu *popover);

Returns the menu model used to populate the popover.

Parameters

popover

a GtkPopoverMenu

 

Returns

the menu model of popover .

[transfer none]

Types and Values

GtkPopoverMenu

typedef struct _GtkPopoverMenu GtkPopoverMenu;

enum GtkPopoverMenuFlags

Flags that affect how popover menus are created from a menu model.

Members

GTK_POPOVER_MENU_NESTED

Create submenus as nested popovers. Without this flag, submenus are created as sliding pages that replace the main menu.

 

Property Details

The “menu-model” property

  “menu-model”               GMenuModel *

The model from which the menu is made.

Owner: GtkPopoverMenu

Flags: Read / Write


The “visible-submenu” property

  “visible-submenu”          gchar *

The name of the visible submenu.

Owner: GtkPopoverMenu

Flags: Read / Write

Default value: NULL