gtk.menu_button
Module for [MenuButton] class
Types 3
The [gtk.menu_button.MenuButton] widget is used to display a popup when clicked.
This popup can be provided either as a [gtk.popover.Popover] or as an abstract [gio.menu_model.MenuModel].
The [gtk.menu_button.MenuButton] widget can show either an icon (set with the property@Gtk.MenuButton:icon-name property) or a label (set with the [gtk.menu_button.MenuButton.label] property). If neither is explicitly set, a [gtk.image.Image] is automatically created, using an arrow image oriented according to [gtk.menu_button.MenuButton.direction] or the generic “open-menu-symbolic” icon if the direction is not set.
The positioning of the popup is determined by the [gtk.menu_button.MenuButton.direction] property of the menu button.
For menus, the [gtk.widget.Widget.halign] and [gtk.widget.Widget.valign] properties of the menu are also taken into account. For example, when the direction is [gtk.types.ArrowType.Down] and the horizontal alignment is [gtk.types.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 |  |  |  |
| up |  |  |  |
| left |  |  |  |
| right |  |  |  |
CSS nodes
menubutton
╰── button.toggle
╰── <content>
╰── [arrow][gtk.menu_button.MenuButton] 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
[gtk.menu_button.MenuButton] uses the [gtk.types.AccessibleRole.Button] role.
MenuButton self()Returns `this`, for use in `with` statements.MenuButtonGidBuilder builder()Get builder for [gtk.menu_button.MenuButton] Returns: New builder objectvoid active(bool propval) @propertySet `active` property. Params: propval = Whether the menu button is active.bool alwaysShowArrow() @propertyGet `alwaysShowArrow` property. Returns: Whether to show a dropdown arrow even when using an icon or a custom child.void alwaysShowArrow(bool propval) @propertySet `alwaysShowArrow` property. Params: propval = Whether to show a dropdown arrow even when using an icon or a custom child.bool canShrink() @propertyGet `canShrink` property. Returns: Whether the size of the button can be made smaller than the natural size of its contents.void canShrink(bool propval) @propertySet `canShrink` property. Params: propval = Whether the size of the button can be made smaller than the natural size of its contents.void child(gtk.widget.Widget propval) @propertySet `child` property. Params: propval = The child widget.gtk.types.ArrowType direction() @propertyGet `direction` property. Returns: The [gtk.types.ArrowType] representing the direction in which the menu or popover will be popped out.void direction(gtk.types.ArrowType propval) @propertySet `direction` property. Params: propval = The [gtk.types.ArrowType] representing the direction in which the menu or popover will be popped out.void hasFrame(bool propval) @propertySet `hasFrame` property. Params: propval = Whether the button has a frame.string iconName() @propertyGet `iconName` property. Returns: The name of the icon used to automatically populate the button.void iconName(string propval) @propertySet `iconName` property. Params: propval = The name of the icon used to automatically populate the button.void label(string propval) @propertySet `label` property. Params: propval = The label for the button.gio.menu_model.MenuModel menuModel() @propertyGet `menuModel` property. Returns: The [gio.menu_model.MenuModel] from which the popup will be created.void menuModel(gio.menu_model.MenuModel propval) @propertySet `menuModel` property. Params: propval = The [gio.menu_model.MenuModel] from which the popup will be created.gtk.popover.Popover popover() @propertyGet `popover` property. Returns: The [gtk.popover.Popover] that will be popped up when the button is clicked.void popover(gtk.popover.Popover propval) @propertySet `popover` property. Params: propval = The [gtk.popover.Popover] that will be popped up when the button is clicked.bool primary() @propertyGet `primary` property. Returns: Whether the menu button acts as a primary menu.void primary(bool propval) @propertySet `primary` property. Params: propval = Whether the menu button acts as a primary menu.bool useUnderline() @propertyGet `useUnderline` property. Returns: If set an underscore in the text indicates a mnemonic.void useUnderline(bool propval) @propertySet `useUnderline` property. Params: propval = If set an underscore in the text indicates a mnemonic.bool getActive()Returns whether the menu button is active. Returns: TRUE if the button is activebool getAlwaysShowArrow()Gets whether to show a dropdown arrow even when using an icon or a custom child. Returns: whether to show a dropdown arrow even when using an icon or a custom child.bool getCanShrink()Retrieves whether the button can be smaller than the natural size of its contents. Returns: true if the button can shrink, and false otherwisegtk.widget.Widget getChild()Gets the child widget of menubutton. Returns: the child widget of menubuttongtk.types.ArrowType getDirection()Returns the direction the popup will be pointing at when popped up. Returns: a [gtk.types.ArrowType] valuebool getHasFrame()Returns whether the button has a frame. Returns: true if the button has a framestring getIconName()Gets the name of the icon shown in the button. Returns: the name of the icon shown in the buttonstring getLabel()Gets the label shown in the button Returns: the label shown in the buttongio.menu_model.MenuModel getMenuModel()Returns the [gio.menumodel.MenuModel] used to generate the popup. Returns: a [gio.menumodel.MenuModel]gtk.popover.Popover getPopover()Returns the [gtk.popover.Popover] that pops out of the button.bool getPrimary()Returns whether the menu button acts as a primary menu. Returns: true if the button is a primary menubool getUseUnderline()Returns whether an embedded underline in the text indicates a mnemonic. Returns: true whether an embedded underline in the text indicates the mnemonic accelerator keys.void popdown()Dismiss the menu.void popup()Pop up the menu.void setActive(bool active)Sets whether the menu button is active.void setAlwaysShowArrow(bool alwaysShowArrow)Sets whether to show a dropdown arrow even when using an icon or a custom child.void setCanShrink(bool canShrink)Sets whether the button size can be smaller than the natural size of its contents.void setChild(gtk.widget.Widget child = null)Sets the child widget of menu_button.void setCreatePopupFunc(gtk.types.MenuButtonCreatePopupFunc func = null)Sets func to be called when a popup is about to be shown.void setDirection(gtk.types.ArrowType direction)Sets the direction in which the popup will be popped up.void setHasFrame(bool hasFrame)Sets the style of the button.void setIconName(string iconName)Sets the name of an icon to show inside the menu button.void setLabel(string label)Sets the label to show inside the menu button.void setMenuModel(gio.menu_model.MenuModel menuModel = null)Sets the [gio.menu_model.MenuModel] from which the popup will be constructed.void setPopover(gtk.widget.Widget popover = null)Sets the [gtk.popover.Popover] that will be popped up when the menu_button is clicked.void setPrimary(bool primary)Sets whether menu button acts as a primary menu.void setUseUnderline(bool useUnderline)If true, an underline in the text indicates a mnemonic.gulong connectActivate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.menu_button.MenuButton)))
&& Parameters!T.length < 2)Connect to `Activate` signal.T active(bool propval)Set `active` property. Params: propval = Whether the menu button is active. Returns: Builder instance for fluent chainingT alwaysShowArrow(bool propval)Set `alwaysShowArrow` property. Params: propval = Whether to show a dropdown arrow even when using an icon or a custom child. Returns: Builder instance for fluent chainingT canShrink(bool propval)Set `canShrink` property. Params: propval = Whether the size of the button can be made smaller than the natural size of its contents. Returns: Builder instance for fluent chainingT child(gtk.widget.Widget propval)Set `child` property. Params: propval = The child widget. Returns: Builder instance for fluent chainingT direction(gtk.types.ArrowType propval)Set `direction` property. Params: propval = The [gtk.types.ArrowType] representing the direction in which the menu or popover will be popped out. Returns: Builder instance for fluent chainingT hasFrame(bool propval)Set `hasFrame` property. Params: propval = Whether the button has a frame. Returns: Builder instance for fluent chainingT iconName(string propval)Set `iconName` property. Params: propval = The name of the icon used to automatically populate the button. Returns: Builder instance for fluent chainingT label(string propval)Set `label` property. Params: propval = The label for the button. Returns: Builder instance for fluent chainingT menuModel(gio.menu_model.MenuModel propval)Set `menuModel` property. Params: propval = The [gio.menu_model.MenuModel] from which the popup will be created.T popover(gtk.popover.Popover propval)Set `popover` property. Params: propval = The [gtk.popover.Popover] that will be popped up when the button is clicked. Returns: Builder instance for fluent chainingT primary(bool propval)Set `primary` property. Params: propval = Whether the menu button acts as a primary menu.T useUnderline(bool propval)Set `useUnderline` property. Params: propval = If set an underscore in the text indicates a mnemonic. Returns: Builder instance for fluent chainingFluent builder for [gtk.menu_button.MenuButton]