The `GtkMenuButton` widget is used to display a popup when clicked.
![An example GtkMenuButton](menu-button.png)
This popup can be provided either as a `GtkPopover` or as an abstract `GMenuModel`.
The `GtkMenuButton` widget can show either an icon (set with the [[email protected]:icon-name] property) or a label (set with the [
[email protected]:label] property). If neither is explicitly set, a [[email protected]] is automatically created, using an arrow image
oriented according to [[email protected]:direction] or the generic “open-menu-symbolic” icon if the direction is not set.
The positioning of the popup is determined by the [[email protected]:direction] property of the menu button.
For menus, the [[email protected]:halign] and [[email protected]:valign] properties of the menu are also taken into account. For
example, when the direction is gtk_arrow_down and the horizontal alignment is
gtk_align_start, the menu will be positioned below the button, with the starting edge (depending on the
text direction) of the menu aligned with the starting edge of the button. If there is not enough space below the button, the menu is
popped up above the button instead. If the alignment would move part of the menu offscreen, it is “pushed in”.
| | start | center | end | | - | --- | --- | --- | | **down** | ![](down-start.png) | ![](down-center.png) | ![](down-end.png) | | **up**
| ![](up-start.png) | ![](up-center.png) | ![](up-end.png) | | **left** | ![](left-start.png) | ![](left-center.png) | ![](left-end.png)
| | **right** | ![](right-start.png) | ![](right-center.png) | ![](right-end.png) |
CSS nodes
``` menubutton ╰── button.toggle ╰── <content> ╰── [arrow] ```
`GtkMenuButton` has a single CSS node with name `menubutton` which contains a `button` node with a `.toggle` style class.
If the button contains an icon, it will have the `.image-button` style class, if it contains text, it will have `.text-button` style
class. If an arrow is visible in addition to an icon, text or a custom child, it will also have `.arrow-button` style class.
Inside the toggle button content, there is an `arrow` node for the indicator, which will carry one of the `.none`, `.up`, `.down`,
`.left` or `.right` style classes to indicate the direction that the menu will appear in. The CSS is expected to provide a suitable image
for each of these cases using the `-gtk-icon-source` property.
Optionally, the `menubutton` node can carry the `.circular` style class to request a round appearance.
Accessibility
`GtkMenuButton` uses the gtk_accessible_role_button role.
- public bool get_always_show_arrow ()
Gets whether to show a dropdown arrow even when using an icon.
- public unowned Widget? get_child ()
Gets the child widget of this.
- public ArrowType get_direction ()
Returns the direction the popup will be pointing at when popped up.
- public bool get_has_frame ()
Returns whether the button has a frame.
- public unowned string? get_icon_name ()
Gets the name of the icon shown in the button.
- public unowned string? get_label ()
Gets the label shown in the button
- public unowned MenuModel? get_menu_model ()
Returns the `GMenuModel` used to generate the popup.
- public unowned Popover? get_popover ()
Returns the `GtkPopover` that pops out of the button.
- public bool get_primary ()
Returns whether the menu button acts as a primary menu.
- public bool get_use_underline ()
Returns whether an embedded underline in the text indicates a
mnemonic.
- public void popdown ()
Dismiss the menu.
- public void popup ()
Pop up the menu.
- public void set_always_show_arrow (bool always_show_arrow)
Sets whether to show a dropdown arrow even when using an icon or a
custom child.
- public void set_child (Widget? child)
Sets the child widget of this.
- public void set_create_popup_func (owned MenuButtonCreatePopupFunc? func)
Sets func
to be called when a popup is about to be shown.
- public void set_direction (ArrowType direction)
Sets the direction in which the popup will be popped up.
- public void set_has_frame (bool has_frame)
Sets the style of the button.
- public void set_icon_name (string icon_name)
Sets the name of an icon to show inside the menu button.
- public void set_label (string label)
Sets the label to show inside the menu button.
- public void set_menu_model (MenuModel? menu_model)
Sets the `GMenuModel` from which the popup will be constructed.
- public void set_popover (Widget? popover)
Sets the `GtkPopover` that will be popped up when the
this is clicked.
- public void set_primary (bool primary)
Sets whether menu button acts as a primary menu.
- public void set_use_underline (bool use_underline)
If true, an underline in the text indicates a mnemonic.