gtk.menu_button

Module for [MenuButton] class

Types 3

The gtk.menu_button.MenuButton widget is used to display a popup when clicked.

!An example GtkMenuButton

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

startcenterend
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]

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.

Methods
GType _getGType() static nothrow
GType _gType() @property nothrow
MenuButton self() nothrowReturns `this`, for use in `with` statements.
MenuButtonGidBuilder builder() static nothrowGet builder for [gtk.menu_button.MenuButton] Returns: New builder object
bool active() @property nothrowGet `active` property. Returns: Whether the menu button is active.
void 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.
gtk.widget.Widget child() @property nothrowGet `child` property. Returns: The child widget.
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.
bool hasFrame() @property nothrowGet `hasFrame` property. Returns: Whether the button has a frame.
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.
string label() @property nothrowGet `label` property. Returns: The label for 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 active
bool 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 otherwise
gtk.widget.Widget getChild() nothrowGets the child widget of menu_button. Returns: the child widget of menu_button
gtk.types.ArrowType getDirection() nothrowReturns the direction the popup will be pointing at when popped up. Returns: a [gtk.types.ArrowType] value
bool getHasFrame() nothrowReturns whether the button has a frame. Returns: true if the button has a frame
string getIconName() nothrowGets the name of the icon shown in the button. Returns: the name of the icon shown in the button
string getLabel() nothrowGets the label shown in the button Returns: the label shown in the button
gio.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 menu
bool 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 popdown() nothrowDismiss the menu.
void popup() nothrowPop up the menu.
void setActive(bool active) nothrowSets whether the menu button is active.
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 setChild(gtk.widget.Widget child = null) nothrowSets the child widget of menu_button.
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 setHasFrame(bool hasFrame) nothrowSets the style of the button.
void setIconName(string iconName) nothrowSets the name of an icon to show inside the menu button.
void setLabel(string label) nothrowSets the label to show inside the menu button.
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 setPrimary(bool primary) nothrowSets whether menu button acts as a primary menu.
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.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new [gtk.menu_button.MenuButton] widget with downwards-pointing arrow as the only child.

Fluent builder implementation template for gtk.menu_button.MenuButton

Methods
T active(bool propval) nothrowSet `active` property. Params: propval = Whether the menu button is active. Returns: Builder instance for fluent chaining
T 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 chaining
T 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 chaining
T child(gtk.widget.Widget propval) nothrowSet `child` property. Params: propval = The child widget. Returns: Builder instance for fluent chaining
T 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 chaining
T hasFrame(bool propval) nothrowSet `hasFrame` property. Params: propval = Whether the button has a frame. Returns: Builder instance for fluent chaining
T iconName(string propval) nothrowSet `iconName` property. Params: propval = The name of the icon used to automatically populate the button. Returns: Builder instance for fluent chaining
T label(string propval) nothrowSet `label` property. Params: propval = The label for the button. Returns: Builder instance for fluent chaining
T 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 chaining
T 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 chaining

Fluent builder for gtk.menu_button.MenuButton

Methods
MenuButton build() nothrowCreate object from builder. Returns: New object