Class MenuBar

java.lang.Object
limn.scene.Widget
limn.components.MenuBar

public final class MenuBar extends Widget
A horizontal strip of top-level menu titles; the strip itself is drawn in-scene (part of the window chrome). Clicking a title drops its 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 Details

  • Method Details

    • addMenu

      public MenuBar addMenu(String title, Menu menu)
      Appends a top-level menu with the given title, and no access letter. UI thread only.
    • addMenu

      public MenuBar addMenu(I18nString title, Menu menu)
      A top-level menu whose title follows the UI language, and no access letter. UI thread only.
    • addMenu

      public MenuBar addMenu(String title, char mnemonic, Menu menu)
      Appends a top-level menu whose title carries an access letter: it is underlined in the strip, Alt plus 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; 0 for none
      Throws:
      IllegalArgumentException - for any other character
    • addMenu

      public MenuBar addMenu(I18nString title, char mnemonic, Menu menu)
      addMenu(String, char, Menu) with a title that follows the UI language.
    • setDisplayMode

      public MenuBar setDisplayMode(DisplayMode mode)
      Asks for the presentation of every dropdown this bar opens; see DisplayMode. Default DisplayMode.NATIVE_WINDOW, which is what a platform menu bar does.

      A preference, not a guarantee: a dropdown asked for NATIVE_WINDOW is still drawn in scene where the platform cannot place a window at the anchor, and in macOS exclusive fullscreen. IN_SCENE is 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

      public DisplayMode displayMode()
      Returns:
      the presentation the next dropdown will be asked for.
    • isOpen

      public boolean isOpen()
      Returns:
      whether a dropdown is currently open.
    • onMeasure

      protected Size onMeasure(Constraints constraints)
      Description copied from class: Widget
      Reports the size this widget wants within constraints. 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 ControlSize and the LayoutDirection once each here and thread them down; never read either in a constructor. The locale needs no threading: it is in scope, and I18n.locale() answers it wherever text is resolved.

      Specified by:
      onMeasure in class Widget
    • baselineOffset

      protected float baselineOffset()
      The baseline BASELINE rows align on, the expression onPaint(limn.graphics.Canvas) draws titles with.
      Overrides:
      baselineOffset in class Widget
    • onPaint

      protected void onPaint(Canvas canvas)
      Description copied from class: Widget
      Widget's own background/content, in local coordinates.
      Overrides:
      onPaint in class Widget
    • onMouseEvent

      protected void onMouseEvent(MouseEvent event)
      Description copied from class: Widget
      Mouse events (bubbling); call event.consume() when handled.
      Overrides:
      onMouseEvent in class Widget
    • onKeyEvent

      protected void onKeyEvent(KeyEvent event)
      Description copied from class: Widget
      Key events (focused widget first, then ancestors).
      Overrides:
      onKeyEvent in class Widget
    • 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:
      onAttached in class Widget
    • 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:
      onDetached in class Widget
    • onFocusGained

      protected void onFocusGained()
      Description copied from class: Widget
      Called when this widget takes keyboard focus. Default: nothing.
      Overrides:
      onFocusGained in class Widget
    • onFocusLost

      protected void onFocusLost()
      Description copied from class: Widget
      Called when this widget loses keyboard focus. Default: nothing.
      Overrides:
      onFocusLost in class Widget