Package ch.bailu.gtk.gtk
Klasse MenuButton
- Alle implementierten Schnittstellen:
PointerInterface
Displays a popup when clicked.
<picture>
<source srcset="menu-button-dark.png" media="(prefers-color-scheme: dark)">
<img alt="An example GtkMenuButton" src="menu-button.png">
</picture>
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** |  |  |  |
| **up** |  |  |  |
| **left** |  |  |  |
| **right** |  |  |  |
# 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 [enum@Gtk.AccessibleRole.button] role.
<picture>
<source srcset="menu-button-dark.png" media="(prefers-color-scheme: dark)">
<img alt="An example GtkMenuButton" src="menu-button.png">
</picture>
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** |  |  |  |
| **up** |  |  |  |
| **left** |  |  |  |
| **right** |  |  |  |
# 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 [enum@Gtk.AccessibleRole.button] role.
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic interface
static interface
static interface
Von Klasse geerbte verschachtelte Klassen/Schnittstellen 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
Von Klasse geerbte verschachtelte Klassen/Schnittstellen ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Feldübersicht
FelderVon Klasse geerbte Felder 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
Von Klasse geerbte Felder ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungCreates a new `GtkMenuButton` widget with downwards-pointing
arrow as the only child.MenuButton
(PointerContainer pointer) -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungImplements interfaceAccessible
.Implements interfaceBuildable
.Implements interfaceConstraintTarget
.boolean
Returns whether the menu button is active.boolean
Gets whether to show a dropdown arrow even when using an icon or a custom
child.boolean
Retrieves whether the button can be smaller than the natural
size of its contents.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
setActive
(boolean active) Sets whether the menu button is active.void
setAlwaysShowArrow
(boolean always_show_arrow) Sets whether to show a dropdown arrow even when using an icon or a custom
child.void
setCanShrink
(boolean can_shrink) Sets whether the button size can be smaller than the natural size of
its contents.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.Von Klasse geerbte Methoden 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, getBaseline, getCanFocus, getCanTarget, getChildVisible, getClipboard, getColor, getCssClasses, getCssName, getCursor, getDefaultDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getLimitEvents, 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, setLimitEvents, 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
Von Klasse geerbte Methoden ch.bailu.gtk.type.PropertyHolder
getBooleanProperty, getIntProperty, getObjectProperty, getStringProperty, getStrProperty, setBooleanProperty, setIntProperty, setObjectProperty, setStringProperty, setStrProperty
Von Klasse geerbte Methoden 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
Von Klasse geerbte Methoden ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Von Klasse geerbte Methoden ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Von Klasse geerbte Methoden java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Von Schnittstelle geerbte Methoden ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Felddetails
-
SIGNAL_ON_ACTIVATE
- Siehe auch:
-
-
Konstruktordetails
-
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.
-
-
Methodendetails
-
getClassHandler
-
getActive
public boolean getActive()Returns whether the menu button is active.- Gibt zurück:
- TRUE if the button is active
-
getAlwaysShowArrow
public boolean getAlwaysShowArrow()Gets whether to show a dropdown arrow even when using an icon or a custom
child.- Gibt zurück:
- whether to show a dropdown arrow even when using an icon or a custom child.
-
getCanShrink
public boolean getCanShrink()Retrieves whether the button can be smaller than the natural
size of its contents.- Gibt zurück:
- true if the button can shrink, and false otherwise
-
getChild
Gets the child widget of @menu_button.- Gibt zurück:
- the child widget of @menu_button
-
getDirection
public int getDirection()Returns the direction the popup will be pointing at when popped up.- Setzt außer Kraft:
getDirection
in KlasseWidget
- Gibt zurück:
- a `GtkArrowType` value
-
getHasFrame
public boolean getHasFrame()Returns whether the button has a frame.- Gibt zurück:
- %TRUE if the button has a frame
-
getIconName
Gets the name of the icon shown in the button.- Gibt zurück:
- the name of the icon shown in the button
-
getLabel
Gets the label shown in the button- Gibt zurück:
- the label shown in the button
-
getMenuModel
Returns the `GMenuModel` used to generate the popup.- Gibt zurück:
- a `GMenuModel`
-
getPopover
Returns the `GtkPopover` that pops out of the button.
If the button is not using a `GtkPopover`, this function
returns %NULL.- Gibt zurück:
- a `GtkPopover` or %NULL
-
getPrimary
public boolean getPrimary()Returns whether the menu button acts as a primary menu.- Gibt zurück:
- %TRUE if the button is a primary menu
-
getUseUnderline
public boolean getUseUnderline()Returns whether an embedded underline in the text indicates a
mnemonic.- Gibt zurück:
- %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. -
setActive
public void setActive(boolean active) Sets whether the menu button is active.- Parameter:
active
- whether the menu button is active
-
setAlwaysShowArrow
public void setAlwaysShowArrow(boolean always_show_arrow) Sets whether to show a dropdown arrow even when using an icon or a custom
child.- Parameter:
always_show_arrow
- whether to show a dropdown arrow even when using an icon or a custom child
-
setCanShrink
public void setCanShrink(boolean can_shrink) Sets whether the button size can be smaller than the natural size of
its contents.
For text buttons, setting @can_shrink to true will ellipsize the label.
For icon buttons, this function has no effect.- Parameter:
can_shrink
- whether the button can shrink
-
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.- Parameter:
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.- Parameter:
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 behavioruser_data
- user data to pass to @funcdestroy_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).- Setzt außer Kraft:
setDirection
in KlasseWidget
- Parameter:
direction
- a `GtkArrowType`
-
setHasFrame
public void setHasFrame(boolean has_frame) Sets the style of the button.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
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.- Parameter:
signal
- callback function (lambda).- Gibt zurück:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
asAccessible
Implements interfaceAccessible
. Call this to get access to interface functions.- Setzt außer Kraft:
asAccessible
in KlasseWidget
- Gibt zurück:
Accessible
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Setzt außer Kraft:
asBuildable
in KlasseWidget
- Gibt zurück:
Buildable
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Setzt außer Kraft:
asConstraintTarget
in KlasseWidget
- Gibt zurück:
ConstraintTarget
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-