Class Padding

java.lang.Object
limn.scene.Widget<Padding>
limn.scene.layout.Padding
Direct Known Subclasses:
BackdropPanel, TokenPadding

public class Padding extends Widget<Padding>
Wraps one child with edge insets.

Not final: a container that derives its insets from resolved ControlSize tokens subclasses this and pushes them from its own measure path. Without that, a size step would compact the controls and leave the page padding around them at whatever literal the app typed, and the spacing ramp is the widest of the three.

Like every layout, it declares how far its child may paint past it; see paintOverflow(float). By default that is the reach of the theme's focus ring less the narrowest of the four insets, and never below zero: a ring that fits inside the insets reaches nothing past the padding, so a padded panel declares nothing and its repaints stay inside it, while a padding of nothing declares the whole reach, as any other wrapper does.

  • Constructor Details

    • Padding

      public Padding(Insets insets, Widget<?> child)
      Insets child on each side; the padding is inside this widget's own box.
  • Method Details

    • all

      public static Padding all(float value, Widget<?> child)
      The same inset on all four sides.
    • insets

      public final Insets insets()
      The current insets.
    • setInsets

      public final void setInsets(Insets newInsets)
      Replaces the insets, with an equality guard. Without the guard, a token-driven subclass that re-applies its insets on every measure pass calls Widget.markNeedsLayout() from inside onMeasure, which dirties the path to the root and schedules another pass: a layout loop that never settles.
    • setInsetsSilently

      protected final void setInsetsSilently(Insets newInsets)
      Assigns the insets without requesting a layout pass: the measure-path form, for a subclass that derives them from resolved size tokens inside its own onMeasure. Safe there and only there: the caller is already inside the pass that will consume the new value, so requesting another one is at best wasteful and at worst non-terminating. Everything else uses setInsets(limn.scene.Insets).
    • paintOverflow

      public Padding paintOverflow(float points)
      Declares how far the child may paint past this padding's box, in logical points, in place of the default, which is the reach of the theme's focus ring less the narrowest inset. It is what Container.paintOverflow(float) is to a container, for the one child here: the public setter of paintOutset(), taken as given whatever the insets are, and a new declaration repaints this padding 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 padding
      Throws:
      IllegalArgumentException - when negative, NaN or infinite
    • paintOverflowFromTheme

      public Padding paintOverflowFromTheme()
      Goes back to declaring what is left of the theme's focus ring reach past the insets, which is the default; see paintOverflow(float). UI thread only.
      Returns:
      this padding
    • paintOutset

      protected float paintOutset()
      What paintOverflow(float) declared; else nothing when a subclass clips the child, whose clip bounds it; else the reach of the focus ring in the theme in effect for this padding, less the narrowest inset, never below zero. The child's box is this box less the insets, so that is what of the reach is left past this box on its closest side. O(1) and allocation-free.
      Overrides:
      paintOutset in class Widget<Padding>
    • 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<Padding>
    • 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<Padding>