Class SizedBox

java.lang.Object
limn.scene.Widget<SizedBox>
limn.scene.layout.SizedBox

public final class SizedBox extends Widget<SizedBox>
Forces a fixed width and/or height (unset dimensions pass through to the child, or collapse to zero without one). Also handy as a rigid spacer.

A dimension is a finite number of points, zero or more, or UNSET, which leaves it free. Any other negative leaves it free as well, and UNSET is the way to say so. A NaN or an infinite dimension is refused where the box is made: measure asked only whether a dimension was at least zero, so a NaN left its axis free without a word and positive infinity was clamped to whatever the parent allowed, which is a different box under every parent and an infinite one under an unbounded axis. A box meant to take all the room it is given leaves that to its parent: UNSET across a Flex that stretches its children, or an Expanded along one.

  • Field Details

    • UNSET

      public static final float UNSET
      Marks a dimension as "not fixed".
      See Also:
  • Constructor Details

    • SizedBox

      public SizedBox(float width, float height, @Nullable Widget<?> child)
      Forces child to an exact size; UNSET on an axis leaves it free.
      Parameters:
      width - the width in points, or UNSET
      height - the height in points, or UNSET
      child - what the box holds, or null for a spacer
      Throws:
      IllegalArgumentException - when a dimension is NaN or infinite
    • SizedBox

      public SizedBox(float width, float height)
      An empty box of a fixed size: a spacer.
      Parameters:
      width - the width in points, or UNSET
      height - the height in points, or UNSET
      Throws:
      IllegalArgumentException - when a dimension is NaN or infinite
  • Method Details

    • paintOverflow

      public SizedBox paintOverflow(float points)
      Declares how far the child may paint past this box, in logical points, in place of the reach of the theme's focus ring, which is the default. It is what Container.paintOverflow(float) is to a container, for the one child here: the public setter of paintOutset(), and a new declaration repaints this box and its band while one already in force repaints nothing. UI thread only.
      Parameters:
      points - how far the child may paint past each side of this box, in logical points
      Returns:
      this box
      Throws:
      IllegalArgumentException - when negative, NaN or infinite
    • paintOverflowFromTheme

      public SizedBox paintOverflowFromTheme()
      Goes back to declaring the reach of the theme's focus ring for the child, which is the default; see paintOverflow(float). UI thread only.
      Returns:
      this box
    • paintOutset

      protected float paintOutset()
      What paintOverflow(float) declared; else nothing for a spacer, which has no child to paint past it; else the reach of the focus ring in the theme in effect for this box: the child is laid out over the whole box, so a ring at its edge is a ring at this box's edge. O(1) and allocation-free.
      Overrides:
      paintOutset in class Widget<SizedBox>
    • 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<SizedBox>
    • 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<SizedBox>