MenuButton

The gtk.MenuButton widget is used to display a popup when clicked on. This popup can be provided either as a gtk.Menu, a gtk.Popover or an abstract gio.MenuModel

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

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

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

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 gtk.Button, it gets the .popup style class.

Constructors

this
this(GtkMenuButton* gtkMenuButton, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this()

Creates a new gtk.MenuButton widget with downwards-pointing arrow as the only child. You can replace the child widget with another gtk.Widget should you wish to.

Members

Functions

getAlignWidget
Widget getAlignWidget()

Returns the parent gtk.Widget to use to line up with menu.

getMenuButtonStruct
GtkMenuButton* getMenuButtonStruct(bool transferOwnership)

Get the main Gtk struct

getMenuDirection
GtkArrowType getMenuDirection()

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

getMenuModel
MenuModel getMenuModel()

Returns the gio.MenuModel used to generate the popup.

getPopover
Popover getPopover()

Returns the gtk.Popover that pops out of the button. If the button is not using a gtk.Popover, this function returns NULL.

getPopup
Menu getPopup()

Returns the gtk.Menu that pops out of the button. If the button does not use a gtk.Menu, this function returns NULL.

getStruct
void* getStruct()

the main Gtk struct as a void*

getUsePopover
bool getUsePopover()

Returns whether a gtk.Popover or a gtk.Menu will be constructed from the menu model.

setAlignWidget
void setAlignWidget(Widget alignWidget)

Sets the gtk.Widget to use to line the menu with when popped up. Note that the align_widget must contain the gtk.MenuButton itself.

setMenuDirection
void setMenuDirection(GtkArrowType 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(MenuModel menuModel)

Sets the gio.MenuModel from which the popup will be constructed, or NULL to dissociate any existing menu model and disable the button.

setPopover
void setPopover(Widget popover)

Sets the gtk.Popover 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(Widget menu)

Sets the gtk.Menu 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 gtk.Popover instead of gtk.Menu when Menu.buttonSetMenuModel is called. Note that this property is only consulted when a new menu model is set.

Static functions

getType
GType getType()

Variables

gtkMenuButton
GtkMenuButton* gtkMenuButton;

the main Gtk struct

Inherited Members

From ToggleButton

gtkToggleButton
GtkToggleButton* gtkToggleButton;

the main Gtk struct

getToggleButtonStruct
GtkToggleButton* getToggleButtonStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
getActive
bool getActive()

Queries a gtk.ToggleButton 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 ToggleButton.setInconsistent.

getMode
bool getMode()

Retrieves whether the button is displayed as a separate indicator and label. See 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 toggled signal and the 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, 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 toggled signal on the gtk.ToggleButton There is no good reason for an application ever to call this function.

addOnToggled
gulong addOnToggled(void delegate(ToggleButton) dlg, ConnectFlags connectFlags)

Should be connected if you wish to perform an action whenever the gtk.ToggleButton's state is changed.