Class MenuBar
Menu
as a PopupMenu (a native window) below it; Left/Right walk between
menus, Down/Enter opens the focused one, and its submenus/checkable items
behave like any other popup.
MenuBar bar = new MenuBar()
.addMenu("File", 'F', fileMenu)
.addMenu("Edit", 'E', editMenu)
.addMenu("View", 'V', viewMenu);
The bar is the keyboard entry point to the whole menu system, and it is one while it
is in a scene rather than only while it is focused. From the moment it is attached it answers,
anywhere in the scene and without focus: an item's Accelerator runs that item; a bare
Alt released (or F10) moves focus here; Alt plus a declared access letter opens that
menu. All of it is offered only after the focused widget has declined the key, so a shortcut
never steals a keystroke from a text field that wanted it.
The strip mirrors where it reads right to left: the first title is at the right edge, each title's text sits on the pad of the side reading starts from, and Left selects the visually-left title, which is then the next one in declaration order. The dropdown inherits the direction through the anchor and mirrors with it. Accelerator labels do not mirror: they name physical keys.
The strip's height is the ControlSize step's
controlHeight, so a bar and the buttons beside it agree at every step, and the
dropdown opens at the bar's step because PopupMenu is anchored on this widget.
Every metric comes from the resolved SizeTokens row, every weight from
Strokes, including the bottom rule, the most visible hairline in the toolkit,
which stays 1 pt at XSMALL and at XLARGE.
-
Constructor Summary
ConstructorsConstructorDescriptionMenuBar()An empty bar; add top-level menus withaddMenu(java.lang.String, limn.components.Menu). -
Method Summary
Modifier and TypeMethodDescriptionAppends a top-level menu whose title carries an access letter: it is underlined in the strip,Altplus that letter opens the menu from anywhere in the scene, and the bare letter opens it while the bar has focus.Appends a top-level menu with the given title, and no access letter.addMenu(I18nString title, char mnemonic, Menu menu) addMenu(String, char, Menu)with a title that follows the UI language.addMenu(I18nString title, Menu menu) A top-level menu whose title follows the UI language, and no access letter.protected floatThe baseline BASELINE rows align on, the expressiononPaint(limn.graphics.Canvas)draws titles with.booleanisOpen()protected voidThe bar answers for the whole scene while it is attached: accelerators, Alt/F10 and Alt+letter all arrive here, after the focused widget has declined them.protected voidA bar removed from the tree must never strand its dropdown on screen, nor keep answering the scene's keyboard from outside it, which is what the unhook is for.protected voidCalled when this widget takes keyboard focus.protected voidCalled when this widget loses keyboard focus.protected voidonKeyEvent(KeyEvent event) Key events (focused widget first, then ancestors).protected SizeonMeasure(Constraints constraints) Reports the size this widget wants withinconstraints.protected voidonMouseEvent(MouseEvent event) Mouse events (bubbling); callevent.consume()when handled.protected voidWidget's own background/content, in local coordinates.setDisplayMode(DisplayMode mode) Asks for the presentation of every dropdown this bar opens; seeDisplayMode.Methods inherited from class limn.scene.Widget
acceptsTextInput, add, baselineOffsetOf, caretRect, children, clipboard, clipsChildren, controlSize, cursor, declaredControlSize, declaredLayoutDirection, declaredLocale, focusArrivedByTraversal, height, hitTest, imageCursor, invalidate, invalidate, isEnabled, isFocusable, isFocused, isShowing, isVisible, layoutBox, layoutDirection, locale, localToSceneX, localToSceneY, markNeedsContainedLayout, markNeedsLayout, measure, moveChild, neutralBase, onCharTyped, onFileDrop, onLayout, onPaintOverlay, onPreedit, overlayPassesPointer, paintChildren, paintOutset, paintWidget, parent, remove, requestFocus, revealInView, scene, sceneToLocalX, sceneToLocalY, setControlSize, setCursor, setEnabled, setFocusable, setImageCursor, setInheritanceHost, setLayoutDirection, setLocale, setTooltip, setTooltip, setVisible, shapeText, textRuler, tooltip, width, x, y
-
Constructor Details
-
MenuBar
public MenuBar()An empty bar; add top-level menus withaddMenu(java.lang.String, limn.components.Menu).
-
-
Method Details
-
addMenu
Appends a top-level menu with the given title, and no access letter. UI thread only. -
addMenu
A top-level menu whose title follows the UI language, and no access letter. UI thread only. -
addMenu
Appends a top-level menu whose title carries an access letter: it is underlined in the strip,Altplus that letter opens the menu from anywhere in the scene, and the bare letter opens it while the bar has focus.- Parameters:
mnemonic- a letter or digit, matched case-insensitively;0for none- Throws:
IllegalArgumentException- for any other character
-
addMenu
addMenu(String, char, Menu)with a title that follows the UI language. -
setDisplayMode
Asks for the presentation of every dropdown this bar opens; seeDisplayMode. DefaultDisplayMode.NATIVE_WINDOW, which is what a platform menu bar does.A preference, not a guarantee: a dropdown asked for
NATIVE_WINDOWis still drawn in scene where the platform cannot place a window at the anchor, and in macOS exclusive fullscreen.IN_SCENEis always honoured, and the bar keeps its hover-to-switch behaviour under it, because pointer input over the strip falls through the overlay.Takes effect on the next open; a dropdown already down is not re-presented.
-
displayMode
- Returns:
- the presentation the next dropdown will be asked for.
-
isOpen
public boolean isOpen()- Returns:
- whether a dropdown is currently open.
-
onMeasure
Description copied from class:WidgetReports the size this widget wants withinconstraints. Called once per layout pass, and the result is cached against the constraints and the resolved axes (size step, layout direction, locale), so it must be a pure function of them and of this widget's own state.Resolve the
ControlSizeand theLayoutDirectiononce each here and thread them down; never read either in a constructor. The locale needs no threading: it is in scope, andI18n.locale()answers it wherever text is resolved. -
baselineOffset
protected float baselineOffset()The baseline BASELINE rows align on, the expressiononPaint(limn.graphics.Canvas)draws titles with.- Overrides:
baselineOffsetin classWidget
-
onPaint
Description copied from class:WidgetWidget's own background/content, in local coordinates. -
onMouseEvent
Description copied from class:WidgetMouse events (bubbling); callevent.consume()when handled.- Overrides:
onMouseEventin classWidget
-
onKeyEvent
Description copied from class:WidgetKey events (focused widget first, then ancestors).- Overrides:
onKeyEventin classWidget
-
onAttached
protected void onAttached()The bar answers for the whole scene while it is attached: accelerators, Alt/F10 and Alt+letter all arrive here, after the focused widget has declined them.- Overrides:
onAttachedin classWidget
-
onDetached
protected void onDetached()A bar removed from the tree must never strand its dropdown on screen, nor keep answering the scene's keyboard from outside it, which is what the unhook is for.- Overrides:
onDetachedin classWidget
-
onFocusGained
protected void onFocusGained()Description copied from class:WidgetCalled when this widget takes keyboard focus. Default: nothing.- Overrides:
onFocusGainedin classWidget
-
onFocusLost
protected void onFocusLost()Description copied from class:WidgetCalled when this widget loses keyboard focus. Default: nothing.- Overrides:
onFocusLostin classWidget
-