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 gtk.menu_button.MenuButton.iconName 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.
MenuButtonGidBuilder builder() static nothrowGet builder for [gtk.menu_button.MenuButton] Returns: New builder objectvoid active(bool propval) @property nothrowSet `active` property. Params: propval = Whether the menu button is active.bool alwaysShowArrow() @property nothrowGet `alwaysShowArrow` property. Returns: Whether to show a dropdown arrow even when using an icon or a custom child.void alwaysShowArrow(bool propval) @property nothrowSet `alwaysShowArrow` property. Params: propval = Whether to show a dropdown arrow even when using an icon or a custom child.bool canShrink() @property nothrowGet `canShrink` property. Returns: Whether the size of the button can be made smaller than the natural size of its contents.void canShrink(bool propval) @property nothrowSet `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) @property nothrowSet `child` property. Params: propval = The child widget.gtk.types.ArrowType direction() @property nothrowGet `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) @property nothrowSet `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) @property nothrowSet `hasFrame` property. Params: propval = Whether the button has a frame.string iconName() @property nothrowGet `iconName` property. Returns: The name of the icon used to automatically populate the button.void iconName(string propval) @property nothrowSet `iconName` property. Params: propval = The name of the icon used to automatically populate the button.void label(string propval) @property nothrowSet `label` property. Params: propval = The label for the button.gio.menu_model.MenuModel menuModel() @property nothrowGet `menuModel` property. Returns: The [gio.menu_model.MenuModel] from which the popup will be created.void menuModel(gio.menu_model.MenuModel propval) @property nothrowSet `menuModel` property. Params: propval = The [gio.menu_model.MenuModel] from which the popup will be created.gtk.popover.Popover popover() @property nothrowGet `popover` property. Returns: The [gtk.popover.Popover] that will be popped up when the button is clicked.void popover(gtk.popover.Popover propval) @property nothrowSet `popover` property. Params: propval = The [gtk.popover.Popover] that will be popped up when the button is clicked.bool primary() @property nothrowGet `primary` property. Returns: Whether the menu button acts as a primary menu.void primary(bool propval) @property nothrowSet `primary` property. Params: propval = Whether the menu button acts as a primary menu.bool useUnderline() @property nothrowGet `useUnderline` property. Returns: If set an underscore in the text indicates a mnemonic.void useUnderline(bool propval) @property nothrowSet `useUnderline` property. Params: propval = If set an underscore in the text indicates a mnemonic.bool getActive() nothrowReturns whether the menu button is active. Returns: TRUE if the button is activebool getAlwaysShowArrow() nothrowGets 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() nothrowRetrieves 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() nothrowGets the child widget of menu_button. Returns: the child widget of menu_buttongtk.types.ArrowType getDirection() nothrowReturns the direction the popup will be pointing at when popped up. Returns: a [gtk.types.ArrowType] valuebool getHasFrame() nothrowReturns whether the button has a frame. Returns: true if the button has a framestring getIconName() nothrowGets the name of the icon shown in the button. Returns: the name of the icon shown in the buttongio.menu_model.MenuModel getMenuModel() nothrowReturns the [gio.menu_model.MenuModel] used to generate the popup. Returns: a [gio.menu_model.MenuModel]gtk.popover.Popover getPopover() nothrowReturns the [gtk.popover.Popover] that pops out of the button.bool getPrimary() nothrowReturns whether the menu button acts as a primary menu. Returns: true if the button is a primary menubool getUseUnderline() nothrowReturns 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 setAlwaysShowArrow(bool alwaysShowArrow) nothrowSets whether to show a dropdown arrow even when using an icon or a custom child.void setCanShrink(bool canShrink) nothrowSets whether the button size can be smaller than the natural size of its contents.void setCreatePopupFunc(gtk.types.MenuButtonCreatePopupFunc func = null) nothrowSets func to be called when a popup is about to be shown.void setDirection(gtk.types.ArrowType direction) nothrowSets the direction in which the popup will be popped up.void setMenuModel(gio.menu_model.MenuModel menuModel = null) nothrowSets the [gio.menu_model.MenuModel] from which the popup will be constructed.void setPopover(gtk.widget.Widget popover = null) nothrowSets the [gtk.popover.Popover] that will be popped up when the menu_button is clicked.void setUseUnderline(bool useUnderline) nothrowIf 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) nothrowConnect to `Activate` signal.Fluent builder implementation template for gtk.menu_button.MenuButton
T active(bool propval) nothrowSet `active` property. Params: propval = Whether the menu button is active. Returns: Builder instance for fluent chainingT alwaysShowArrow(bool propval) nothrowSet `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) nothrowSet `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) nothrowSet `child` property. Params: propval = The child widget. Returns: Builder instance for fluent chainingT direction(gtk.types.ArrowType propval) nothrowSet `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) nothrowSet `hasFrame` property. Params: propval = Whether the button has a frame. Returns: Builder instance for fluent chainingT iconName(string propval) nothrowSet `iconName` property. Params: propval = The name of the icon used to automatically populate the button. Returns: Builder instance for fluent chainingT label(string propval) nothrowSet `label` property. Params: propval = The label for the button. Returns: Builder instance for fluent chainingT menuModel(gio.menu_model.MenuModel propval) nothrowSet `menuModel` property. Params: propval = The [gio.menu_model.MenuModel] from which the popup will be created.T popover(gtk.popover.Popover propval) nothrowSet `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) nothrowSet `primary` property. Params: propval = Whether the menu button acts as a primary menu.T useUnderline(bool propval) nothrowSet `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