Struct gtk4::PopoverMenu[][src]

pub struct PopoverMenu(_);
Expand description

PopoverMenu is a subclass of Popover that implements menu behavior.

An example GtkPopoverMenu

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

PopoverMenu is meant to be used primarily with menu models, using from_model(). If you need to put other widgets such as a SpinButton or a Switch into a popover, you can use add_child().

For more dialog-like behavior, use a plain Popover.

The XML format understood by Builder 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 Builder 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 Builder 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 GtkApplicationExt::set_menubar().
  • “custom”: a string used to match against the ID of a custom child added with add_child(), 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 TextDirection 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 GtkApplicationExt::set_accels_for_action(), [WidgetClass::add_binding_action][crate::WidgetClass::add_binding_action] or ShortcutController::add_shortcut().

CSS Nodes

PopoverMenu is just a subclass of Popover 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

PopoverMenu uses the AccessibleRole::Menu role, and its items use the AccessibleRole::MenuItem, AccessibleRole::MenuItemCheckbox or AccessibleRole::MenuItemRadio roles, depending on the action they are connected to.

Implements

PopoverExt, WidgetExt, glib::ObjectExt, AccessibleExt, BuildableExt, ConstraintTargetExt, NativeExt, ShortcutManagerExt, WidgetExtManual, AccessibleExtManual

Implementations

Creates a PopoverMenu and populates it according to model.

The created buttons are connected to actions found in the ApplicationWindow to which the popover belongs - typically by means of being attached to a widget that is contained within the ApplicationWindows widget hierarchy.

Actions can also be added using WidgetExt::insert_action_group() on the menus attach widget or on any of its parent widgets.

This function creates menus with sliding submenus. See from_model_full() for a way to control this.

model

a GMenuModel

Returns

the new PopoverMenu

Creates a PopoverMenu 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 ApplicationWindow to which the popover belongs. Actions can also be added using WidgetExt::insert_action_group() on the parent widget or on any of its parent widgets.

The only flag that is supported currently is PopoverMenuFlags::NESTED, which makes GTK create traditional, nested submenus instead of the default sliding submenus.

model

a GMenuModel

flags

flags that affect how the menu is created

Returns

the new PopoverMenu

Creates a new builder-pattern struct instance to construct PopoverMenu objects.

This method returns an instance of PopoverMenuBuilder which can be used to create PopoverMenu objects.

Adds a custom widget to a generated menu.

For this to work, the menu model of self must have an item with a custom attribute that matches id.

child

the Widget to add

id

the ID to insert child at

Returns

true if id was found and the widget added

Returns the menu model used to populate the popover.

Returns

the menu model of self

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

child

the Widget to remove

Returns

true if the widget was removed

Sets a new menu model on self.

The existing contents of self are removed, and the self is populated with new contents according to model.

model

a GMenuModel

The name of the visible submenu.

The name of the visible submenu.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the type identifier of Self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Upcasts an object to a superclass or interface T. Read more

Upcasts an object to a reference of its superclass or interface T. Read more

Tries to downcast to a subclass or interface implementor T. Read more

Tries to downcast to a reference of its subclass or interface implementor T. Read more

Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Casts to T unconditionally. Read more

Casts to &T unconditionally. Read more

Performs the conversion.

Performs the conversion.

Returns true if the object is an instance of (can be cast to) T.

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Same as connect but takes a SignalId instead of a signal name.

Same as connect_local but takes a SignalId instead of a signal name.

Same as connect_unsafe but takes a SignalId instead of a signal name.

Emit signal by signal id.

Same as emit but takes Value for the arguments.

Emit signal by its name.

Same as emit_by_name but takes Value for the arguments.

Emit signal with details by signal id.

Same as emit_with_details but takes Value for the arguments.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Returns a SendValue clone of self.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.