Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: PopoverMenu

[84:7] extends: object

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. The property [property@Gtk.PopoverMenu:flags] controls this appearance. 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. ## 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. ```xml

_New Window app.new _About Sunny app.about _Quit app.quit
``` Attribute values can be translated using gettext, like other `GtkBuilder` content. `` 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 [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 ``. 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 [method@Gtk.Application.set_accels_for_action], [method@WidgetClass.add_binding_action] or [method@Gtk.ShortcutController.add_shortcut]. # Shortcuts and Gestures `GtkPopoverMenu` supports the following keyboard shortcuts: - Space 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 [enum@Gtk.AccessibleRole.menu] role, and its items use the [enum@Gtk.AccessibleRole.menu_item], [enum@Gtk.AccessibleRole.checkbox] or [enum@Gtk.AccessibleRole.menu_item_radio] roles, depending on the action they are connected to.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • PopoverMenu (model = null)

    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 [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.

    • @p model is a GMenuModel.
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • asPopover ()

    Wraps this handle as Popover.

    • @r A Popover object.
  • asAccessible ()

    Wraps this handle as Accessible.

    • @r A Accessible object.
  • asBuildable ()

    Wraps this handle as Buildable.

    • @r A Buildable object.
  • asConstraintTarget ()

    Wraps this handle as ConstraintTarget.

    • @r A ConstraintTarget object.
  • asNative ()

    Wraps this handle as Native.

    • @r A Native object.
  • asShortcutManager ()

    Wraps this handle as ShortcutManager.

    • @r A ShortcutManager object.
  • getProperty (string Name)

    Reads one generated property by name.

  • setProperty (string Name, Value)

    Writes one generated property by name.

  • setFlags (string Value)

    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.

    • @p Value is the new property value.
    • @r None.
  • setMenumodel (object Value)

    The model from which the menu is made.

    • @p Value is the new property value.
    • @r None.
  • setVisiblesubmenu (string Value)

    The name of the visible submenu.

    • @p Value is the new property value.
    • @r None.
  • add_child (object child, string id)

    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.

    • @p child is the GtkWidget to add.
    • @p id is the ID to insert @child at.
  • get_flags ()

    Returns the flags that @popover uses to create/display a menu from its model.

  • get_menu_model ()

    Returns the menu model used to populate the popover.

  • remove_child (object child)

    Removes a widget that has previously been added with [method@Gtk.PopoverMenu.add_child]

    • @p child is the GtkWidget to remove.
  • set_flags (string 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.

    • @p flags is a set of GtkPopoverMenuFlags.
    • @r None.
  • set_menu_model (object 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. ``
    • @p model is a GMenuModel.
    • @r None.

class: PopoverMenuMeta

[378:14] static extends: object

Generated metadata helpers for PopoverMenu class surfaces.

Methods

  • properties ()

    Returns property metadata for PopoverMenu.

    • @r A list.

class: PopoverMenuCtors

[354:14] static extends: object

Alternate constructors for PopoverMenu. Usage: PopoverMenuCtors.<name>(...). The primary constructor lives directly on PopoverMenu.

Methods

  • newFromModelFull (object model, string 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 [method@Gtk.Widget.insert_action_group] on the parent widget or on any of its parent widgets.

    • @p model is a GMenuModel.
    • @p flags is flags that affect how the menu is created.
    • @r A new PopoverMenu.