Class TokenBox

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

public final class TokenBox extends Widget
A SizedBox whose fixed dimensions come from the resolved ControlSize step instead of from a number baked at construction.

The fourth of the Token* family: TokenRow, TokenColumn and TokenPadding do this for gaps and insets, and this does it for an extent. It exists for the size-axis trap the repository keeps running into: a widget has no parent while it is being built, so a size read there resolves against the process default and stays there forever, whatever step the eventual parent declares.


 // the colour picker, as wide as the step says a picker in a dialog should be
 new TokenBox(SizeTokens::colorDialogW, null, picker)
 

null means "unset" on either axis, exactly as SizedBox.UNSET does: that axis is whatever the child measures to.

  • Constructor Details

    • TokenBox

      public TokenBox(TokenBox.Extent fixedWidth, TokenBox.Extent fixedHeight, Widget child)
      Parameters:
      fixedWidth - the width to impose, or null to take the child's
      fixedHeight - the height to impose, or null to take the child's
      child - the widget to size; never null
  • Method Details

    • 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