Class ToolBar

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

public class ToolBar extends Widget
A horizontal strip of controls (buttons, toggles, segmented controls, Separators…) on a rounded Theme.surface background. Lays its items out from the leading edge, vertically centered, with a configurable gap. Purely a styled container: the items handle their own input.

The strip follows its resolved LayoutDirection: reading left to right the first item added is the leftmost, reading right to left it is the rightmost, and the order in between is the order it was added in either way. Only the placed coordinate moves — the padding, the gap and the measured width are the same numbers in both directions, so a bar cannot change size by changing side.

Sizes follow the ControlSize resolved on this widget: the padding on all four edges, the default gap and the inset of the separators addSeparator() builds come from the SizeTokens row; the border weight comes from Strokes and is the same at every step, which is what makes a bar and the buttons inside it read as one object.

The bar has no height table of its own: its height stays tallestChild + 2 * toolBarPad. Giving it one would let a bar full of MEDIUM buttons disagree with itself about how tall those buttons are, depending only on the bar's own step. Items added through addItem(limn.scene.Widget) are children, so they inherit the bar's step: that propagation is the whole point of setting a step on a toolbar.

  • Constructor Details

    • ToolBar

      public ToolBar()
  • Method Details

    • addItem

      public ToolBar addItem(Widget item)
      Adds an item to the end of the bar.
    • addSeparator

      public ToolBar addSeparator()
      Adds a vertical divider between items, inset per the bar's step.
    • gap

      public ToolBar gap(float newGap)
      Overrides the gap between items, in points. Latches: the value survives every later ControlSize change. Leave it alone to follow the step's toolBarGap.
    • 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
    • onLayout

      protected void onLayout()
      Description copied from class: Widget
      Containers position children here (measure + Widget.layoutBox(float, float, float, float) per child).
      Overrides:
      onLayout 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