MenuButton

The #GtkMenuButton widget is used to display a popup when clicked on. This popup can be provided either as a #GtkMenu, a #GtkPopover or an abstract #GMenuModel.

The #GtkMenuButton widget can hold any valid child widget. That is, it can hold almost any other standard #GtkWidget. The most commonly used child is #GtkImage. If no widget is explicitely added to the #GtkMenuButton, a #GtkImage is automatically created, using an arrow image oriented according to #GtkMenuButton:direction or the generic “open-menu-symbolic” icon if the direction is not set.

The positioning of the popup is determined by the #GtkMenuButton:direction property of the menu button.

For menus, the #GtkWidget:halign and #GtkWidget: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”.

Direction = Down

  • halign = start

  • halign = center

  • halign = end

Direction = Up

  • halign = start

  • halign = center

  • halign = end

Direction = Left

  • valign = start

  • valign = center

  • valign = end

Direction = Right

  • valign = start

  • valign = center

  • valign = end

CSS nodes

GtkMenuButton has a single CSS node with name button. To differentiate it from a plain #GtkButton, it gets the .popup style class.

Constructors

this
this(void* ptr, Flag!"Take" take)
this
this()

Creates a new #GtkMenuButton widget with downwards-pointing arrow as the only child. You can replace the child widget with another #GtkWidget should you wish to.

Members

Functions

getAlignWidget
gtk.widget.Widget getAlignWidget()

Returns the parent #GtkWidget to use to line up with menu.

getDirection
gtk.types.ArrowType getDirection()

Returns the direction the popup will be pointing at when popped up.

getMenuModel
gio.menu_model.MenuModel getMenuModel()

Returns the #GMenuModel used to generate the popup.

getPopover
gtk.popover.Popover getPopover()

Returns the #GtkPopover that pops out of the button. If the button is not using a #GtkPopover, this function returns null.

getPopup
gtk.menu.Menu getPopup()

Returns the #GtkMenu that pops out of the button. If the button does not use a #GtkMenu, this function returns null.

getUsePopover
bool getUsePopover()

Returns whether a #GtkPopover or a #GtkMenu will be constructed from the menu model.

self
MenuButton self()

Returns this, for use in with statements.

setAlignWidget
void setAlignWidget(gtk.widget.Widget alignWidget)

Sets the #GtkWidget to use to line the menu with when popped up. Note that the align_widget must contain the #GtkMenuButton itself.

setDirection
void setDirection(gtk.types.ArrowType direction)

Sets the direction in which the popup will be popped up, as well as changing the arrow’s direction. The child will not be changed to an arrow if it was customized.

setMenuModel
void setMenuModel(gio.menu_model.MenuModel menuModel)

Sets the #GMenuModel from which the popup will be constructed, or null to dissociate any existing menu model and disable the button.

setPopover
void setPopover(gtk.widget.Widget popover)

Sets the #GtkPopover that will be popped up when the menu_button is clicked, or null to dissociate any existing popover and disable the button.

setPopup
void setPopup(gtk.widget.Widget menu)

Sets the #GtkMenu that will be popped up when the menu_button is clicked, or null to dissociate any existing menu and disable the button.

setUsePopover
void setUsePopover(bool usePopover)

Sets whether to construct a #GtkPopover instead of #GtkMenu when gtk.menu_button.MenuButton.setMenuModel is called. Note that this property is only consulted when a new menu model is set.

Properties

_gType
GType _gType [@property getter]
alignWidget
gtk.container.Container alignWidget [@property getter]

Get alignWidget property.

alignWidget
gtk.container.Container alignWidget [@property setter]

Set alignWidget property.

direction
gtk.types.ArrowType direction [@property getter]

Get direction property.

direction
gtk.types.ArrowType direction [@property setter]

Set direction property.

menuModel
gio.menu_model.MenuModel menuModel [@property getter]

Get menuModel property.

menuModel
gio.menu_model.MenuModel menuModel [@property setter]

Set menuModel property.

popover
gtk.popover.Popover popover [@property getter]

Get popover property.

popover
gtk.popover.Popover popover [@property setter]

Set popover property.

popup
gtk.menu.Menu popup [@property getter]

Get popup property.

popup
gtk.menu.Menu popup [@property setter]

Set popup property.

usePopover
bool usePopover [@property getter]

Get usePopover property.

usePopover
bool usePopover [@property setter]

Set usePopover property.

Static functions

_getGType
GType _getGType()
builder
MenuButtonGidBuilder builder()

Get builder for gtk.menu_button.MenuButton

Inherited Members

From ToggleButton

_getGType
GType _getGType()
_gType
GType _gType [@property getter]
self
ToggleButton self()

Returns this, for use in with statements.

builder
ToggleButtonGidBuilder builder()

Get builder for gtk.toggle_button.ToggleButton

active
bool active [@property getter]
active
bool active [@property setter]
drawIndicator
bool drawIndicator [@property getter]
drawIndicator
bool drawIndicator [@property setter]
inconsistent
bool inconsistent [@property getter]
inconsistent
bool inconsistent [@property setter]
newWithLabel
gtk.toggle_button.ToggleButton newWithLabel(string label)

Creates a new toggle button with a text label.

newWithMnemonic
gtk.toggle_button.ToggleButton newWithMnemonic(string label)

Creates a new #GtkToggleButton containing a label. The label will be created using gtk.label.Label.newWithMnemonic, so underscores in label indicate the mnemonic for the button.

getActive
bool getActive()

Queries a #GtkToggleButton and returns its current state. Returns true if the toggle button is pressed in and false if it is raised.

getInconsistent
bool getInconsistent()

Gets the value set by gtk.toggle_button.ToggleButton.setInconsistent.

getMode
bool getMode()

Retrieves whether the button is displayed as a separate indicator and label. See gtk.toggle_button.ToggleButton.setMode.

setActive
void setActive(bool isActive)

Sets the status of the toggle button. Set to true if you want the GtkToggleButton to be “pressed in”, and false to raise it. This action causes the #GtkToggleButton::toggled signal and the #GtkButton::clicked signal to be emitted.

setInconsistent
void setInconsistent(bool setting)

If the user has selected a range of elements (such as some text or spreadsheet cells) that are affected by a toggle button, and the current values in that range are inconsistent, you may want to display the toggle in an “in between” state. This function turns on “in between” display. Normally you would turn off the inconsistent state again if the user toggles the toggle button. This has to be done manually, gtk.toggle_button.ToggleButton.setInconsistent only affects visual appearance, it doesn’t affect the semantics of the button.

setMode
void setMode(bool drawIndicator)

Sets whether the button is displayed as a separate indicator and label. You can call this function on a checkbutton or a radiobutton with draw_indicator = false to make the button look like a normal button.

toggled
void toggled()

Emits the #GtkToggleButton::toggled signal on the #GtkToggleButton. There is no good reason for an application ever to call this function.

connectToggled
gulong connectToggled(T callback, Flag!"After" after)

Connect to Toggled signal.