Package ch.bailu.gtk.gtk
Class MenuButton
- All Implemented Interfaces:
PointerInterface
The `GtkMenuButton` widget is used to display a popup when clicked.
![An example GtkMenuButton](menu-button.png)
This popup can be provided either as a `GtkPopover` or as an abstract
`GMenuModel`.
The `GtkMenuButton` widget can show either an icon (set with the
[property@Gtk.MenuButton:icon-name] property) or a label (set with the
[property@Gtk.MenuButton:label] property). If neither is explicitly set,
a [class@Gtk.Image] is automatically created, using an arrow image oriented
according to [property@Gtk.MenuButton:direction] or the generic
“open-menu-symbolic” icon if the direction is not set.
The positioning of the popup is determined by the
[property@Gtk.MenuButton:direction] property of the menu button.
For menus, the [property@Gtk.Widget:halign] and [property@Gtk.Widget: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”.
| | start | center | end |
| - | --- | --- | --- |
| **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]
```
`GtkMenuButton` 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
`GtkMenuButton` uses the %GTK_ACCESSIBLE_ROLE_BUTTON role.
![An example GtkMenuButton](menu-button.png)
This popup can be provided either as a `GtkPopover` or as an abstract
`GMenuModel`.
The `GtkMenuButton` widget can show either an icon (set with the
[property@Gtk.MenuButton:icon-name] property) or a label (set with the
[property@Gtk.MenuButton:label] property). If neither is explicitly set,
a [class@Gtk.Image] is automatically created, using an arrow image oriented
according to [property@Gtk.MenuButton:direction] or the generic
“open-menu-symbolic” icon if the direction is not set.
The positioning of the popup is determined by the
[property@Gtk.MenuButton:direction] property of the menu button.
For menus, the [property@Gtk.Widget:halign] and [property@Gtk.Widget: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”.
| | start | center | end |
| - | --- | --- | --- |
| **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]
```
`GtkMenuButton` 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
`GtkMenuButton` uses the %GTK_ACCESSIBLE_ROLE_BUTTON role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Widget
Widget.OnDestroy, Widget.OnDirectionChanged, Widget.OnHide, Widget.OnKeynavFailed, Widget.OnMap, Widget.OnMnemonicActivate, Widget.OnMoveFocus, Widget.OnQueryTooltip, Widget.OnRealize, Widget.OnShow, Widget.OnStateFlagsChanged, Widget.OnTickCallback, Widget.OnUnmap, Widget.OnUnrealize
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gtk.Widget
SIGNAL_ON_DESTROY, SIGNAL_ON_DIRECTION_CHANGED, SIGNAL_ON_HIDE, SIGNAL_ON_KEYNAV_FAILED, SIGNAL_ON_MAP, SIGNAL_ON_MNEMONIC_ACTIVATE, SIGNAL_ON_MOVE_FOCUS, SIGNAL_ON_QUERY_TOOLTIP, SIGNAL_ON_REALIZE, SIGNAL_ON_SHOW, SIGNAL_ON_STATE_FLAGS_CHANGED, SIGNAL_ON_UNMAP, SIGNAL_ON_UNREALIZE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
ConstructorDescriptionCreates a new `GtkMenuButton` widget with downwards-pointing
arrow as the only child.MenuButton
(PointerContainer pointer) -
Method Summary
Modifier and TypeMethodDescriptionImplements interfaceAccessible
.Implements interfaceBuildable
.Implements interfaceConstraintTarget
.boolean
Gets whether to show a dropdown arrow even when using an icon.getChild()
Gets the child widget of @menu_button.static ClassHandler
int
Returns the direction the popup will be pointing at when popped up.boolean
Returns whether the button has a frame.Gets the name of the icon shown in the button.static int
getLabel()
Gets the label shown in the buttonReturns the `GMenuModel` used to generate the popup.static long
static TypeSystem.TypeSize
Returns the `GtkPopover` that pops out of the button.boolean
Returns whether the menu button acts as a primary menu.static long
static TypeSystem.TypeSize
boolean
Returns whether an embedded underline in the text indicates a
mnemonic.onActivate
(MenuButton.OnActivate signal) Connect to signal "activate".void
popdown()
Dismiss the menu.void
popup()
Pop up the menu.void
setAlwaysShowArrow
(boolean always_show_arrow) Sets whether to show a dropdown arrow even when using an icon or a custom
child.void
Sets the child widget of @menu_button.void
setCreatePopupFunc
(MenuButton.OnMenuButtonCreatePopupFunc func, Pointer user_data, MenuButton.OnDestroyNotify destroy_notify) Sets @func to be called when a popup is about to be shown.void
setDirection
(int direction) Sets the direction in which the popup will be popped up.void
setHasFrame
(boolean has_frame) Sets the style of the button.void
setIconName
(Str icon_name) Sets the name of an icon to show inside the menu button.void
setIconName
(String icon_name) Sets the name of an icon to show inside the menu button.void
Sets the label to show inside the menu button.void
Sets the label to show inside the menu button.void
setMenuModel
(MenuModel menu_model) Sets the `GMenuModel` from which the popup will be constructed.void
setPopover
(Widget popover) Sets the `GtkPopover` that will be popped up when the @menu_button is clicked.void
setPrimary
(boolean primary) Sets whether menu button acts as a primary menu.void
setUseUnderline
(boolean use_underline) If true, an underline in the text indicates a mnemonic.Methods inherited from class ch.bailu.gtk.gtk.Widget
actionSetEnabled, actionSetEnabled, activate, activateAction, activateAction, activateActionVariant, activateActionVariant, activateDefault, addController, addCssClass, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getCanFocus, getCanTarget, getChildVisible, getClipboard, getCssClasses, getCssName, getCursor, getDefaultDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeCssClass, removeMnemonicLabel, removeTickCallback, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setCursorFromName, setDefaultDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipMarkup, setTooltipText, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, snapshotChild, triggerTooltipQuery, unmap, unparent, unrealize, unsetStateFlags
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_ACTIVATE
- See Also:
-
-
Constructor Details
-
MenuButton
-
MenuButton
public MenuButton()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.
-
-
Method Details
-
getClassHandler
-
getAlwaysShowArrow
public boolean getAlwaysShowArrow()Gets whether to show a dropdown arrow even when using an icon.- Returns:
- whether to show a dropdown arrow even when using an icon
-
getChild
Gets the child widget of @menu_button.- Returns:
- the child widget of @menu_button
-
getDirection
public int getDirection()Returns the direction the popup will be pointing at when popped up.- Overrides:
getDirection
in classWidget
- Returns:
- a `GtkArrowType` value
-
getHasFrame
public boolean getHasFrame()Returns whether the button has a frame.- Returns:
- %TRUE if the button has a frame
-
getIconName
Gets the name of the icon shown in the button.- Returns:
- the name of the icon shown in the button
-
getLabel
Gets the label shown in the button- Returns:
- the label shown in the button
-
getMenuModel
Returns the `GMenuModel` used to generate the popup.- Returns:
- a `GMenuModel`
-
getPopover
Returns the `GtkPopover` that pops out of the button.
If the button is not using a `GtkPopover`, this function
returns %NULL.- Returns:
- a `GtkPopover` or %NULL
-
getPrimary
public boolean getPrimary()Returns whether the menu button acts as a primary menu.- Returns:
- %TRUE if the button is a primary menu
-
getUseUnderline
public boolean 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.
-
popdown
public void popdown()Dismiss the menu. -
popup
public void popup()Pop up the menu. -
setAlwaysShowArrow
public void setAlwaysShowArrow(boolean always_show_arrow) Sets whether to show a dropdown arrow even when using an icon or a custom
child.- Parameters:
always_show_arrow
- hether to show a dropdown arrow even when using an icon
-
setChild
Sets the child widget of @menu_button.
Setting a child resets [property@Gtk.MenuButton:label] and
[property@Gtk.MenuButton:icon-name].
If [property@Gtk.MenuButton:always-show-arrow] is set to `TRUE` and
[property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown arrow
will be shown next to the child.- Parameters:
child
- the child widget
-
setCreatePopupFunc
public void setCreatePopupFunc(MenuButton.OnMenuButtonCreatePopupFunc func, @Nullable Pointer user_data, MenuButton.OnDestroyNotify destroy_notify) Sets @func to be called when a popup is about to be shown.
@func should use one of
- [method@Gtk.MenuButton.set_popover]
- [method@Gtk.MenuButton.set_menu_model]
to set a popup for @menu_button.
If @func is non-%NULL, @menu_button will always be sensitive.
Using this function will not reset the menu widget attached to
@menu_button. Instead, this can be done manually in @func.- Parameters:
func
- function to call when a popup is about to be shown, but none has been provided via other means, or %NULL to reset to default behavior.user_data
- user data to pass to @func.destroy_notify
- destroy notify for @user_data
-
setDirection
public void setDirection(int direction) Sets the direction in which the popup will be popped up.
If the button is automatically populated with an arrow icon,
its direction will be changed to match.
If the does not fit in the available space in the given direction,
GTK will its best to keep it inside the screen and fully visible.
If you pass %GTK_ARROW_NONE for a @direction, the popup will behave
as if you passed %GTK_ARROW_DOWN (although you won’t see any arrows).- Overrides:
setDirection
in classWidget
- Parameters:
direction
- a `GtkArrowType`
-
setHasFrame
public void setHasFrame(boolean has_frame) Sets the style of the button.- Parameters:
has_frame
- whether the button should have a visible frame
-
setIconName
Sets the name of an icon to show inside the menu button.
Setting icon name resets [property@Gtk.MenuButton:label] and
[property@Gtk.MenuButton:child].
If [property@Gtk.MenuButton:always-show-arrow] is set to `TRUE` and
[property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown arrow
will be shown next to the icon.- Parameters:
icon_name
- the icon name
-
setIconName
Sets the name of an icon to show inside the menu button.
Setting icon name resets [property@Gtk.MenuButton:label] and
[property@Gtk.MenuButton:child].
If [property@Gtk.MenuButton:always-show-arrow] is set to `TRUE` and
[property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown arrow
will be shown next to the icon.- Parameters:
icon_name
- the icon name
-
setLabel
Sets the label to show inside the menu button.
Setting a label resets [property@Gtk.MenuButton:icon-name] and
[property@Gtk.MenuButton:child].
If [property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown
arrow will be shown next to the label.- Parameters:
label
- the label
-
setLabel
Sets the label to show inside the menu button.
Setting a label resets [property@Gtk.MenuButton:icon-name] and
[property@Gtk.MenuButton:child].
If [property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown
arrow will be shown next to the label.- Parameters:
label
- the label
-
setMenuModel
Sets the `GMenuModel` from which the popup will be constructed.
If @menu_model is %NULL, the button is disabled.
A [class@Gtk.Popover] will be created from the menu model with
[ctor@Gtk.PopoverMenu.new_from_model]. Actions will be connected
as documented for this function.
If [property@Gtk.MenuButton:popover] is already set, it will be
dissociated from the @menu_button, and the property is set to %NULL.- Parameters:
menu_model
- a `GMenuModel`, or %NULL to unset and disable the button
-
setPopover
Sets the `GtkPopover` that will be popped up when the @menu_button is clicked.
If @popover is %NULL, the button is disabled.
If [property@Gtk.MenuButton:menu-model] is set, the menu model is dissociated
from the @menu_button, and the property is set to %NULL.- Parameters:
popover
- a `GtkPopover`, or %NULL to unset and disable the button
-
setPrimary
public void setPrimary(boolean primary) Sets whether menu button acts as a primary menu.
Primary menus can be opened with the <kbd>F10</kbd> key.- Parameters:
primary
- whether the menubutton should act as a primary menu
-
setUseUnderline
public void setUseUnderline(boolean use_underline) If true, an underline in the text indicates a mnemonic.- Parameters:
use_underline
- %TRUE if underlines in the text indicate mnemonics
-
onActivate
Connect to signal "activate".
SeeMenuButton.OnActivate.onActivate()
for signal description.
FieldSIGNAL_ON_ACTIVATE
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
asAccessible
Implements interfaceAccessible
. Call this to get access to interface functions.- Overrides:
asAccessible
in classWidget
- Returns:
Accessible
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Overrides:
asBuildable
in classWidget
- Returns:
Buildable
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Overrides:
asConstraintTarget
in classWidget
- Returns:
ConstraintTarget
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-