Class StackPanelImpl

java.lang.Object
org.inspirenxe.strata.core.node.BuiltInComponent<org.inspirenxe.strata.api.layout.StackPanel>
org.inspirenxe.strata.core.node.BuiltInComposite<org.inspirenxe.strata.api.layout.StackPanel>
org.inspirenxe.strata.core.node.BuiltInContainer<org.inspirenxe.strata.api.layout.StackPanel>
org.inspirenxe.strata.core.layout.StackPanelImpl
All Implemented Interfaces:
org.inspirenxe.strata.api.component.Component<org.inspirenxe.strata.api.layout.StackPanel>, org.inspirenxe.strata.api.component.Container<org.inspirenxe.strata.api.layout.StackPanel>, org.inspirenxe.strata.api.component.Enableable<org.inspirenxe.strata.api.layout.StackPanel>, org.inspirenxe.strata.api.component.HasContextMenu<org.inspirenxe.strata.api.layout.StackPanel>, org.inspirenxe.strata.api.component.HasCursor<org.inspirenxe.strata.api.layout.StackPanel>, org.inspirenxe.strata.api.component.HasTooltip<org.inspirenxe.strata.api.layout.StackPanel>, org.inspirenxe.strata.api.event.EventTarget<org.inspirenxe.strata.api.layout.StackPanel>, org.inspirenxe.strata.api.layout.StackPanel

public final class StackPanelImpl extends BuiltInContainer<org.inspirenxe.strata.api.layout.StackPanel> implements org.inspirenxe.strata.api.layout.StackPanel
The core StackPanel. Children without a weight are measured with unlimited space along the stacking axis and the content size across it. Weighted children are measured after them, each with its share of the space the others and the gaps leave, or with unlimited space when the panel itself has no limit; the panel asks for the smallest weighted length that gives each its desired size in proportion, less what a child's maximum size cuts from its part. Children are then placed one after another with the spacing between them, weighted ones in their share of the room left in the content box. Each slot spans the whole content box across the axis. Hidden children take no space and add no spacing. Spreading widens the gaps only when no visible child has a weight.

Shares respect each weighted child's minimum and maximum size along the axis, margin included: a child whose share would cross a limit gets the limit, and the other weighted children share what is left, as WeightedShares describes. The lower limit is the child's outer minimum (MeasureContext.minimumSize(Component)), so a content minimum or a fixed size holds a share up too.

In a row, children aligned VerticalAlignment.BASELINE are lined up as BaselineRow describes: the row is at least as tall as they need lined up, and each one's slot starts where its baseline meets theirs, as tall as the child asked for.

The panel's own content minimum is its children's minimums along the axis plus the gaps, the largest across, and the padding.

  • Constructor Details

    • StackPanelImpl

      public StackPanelImpl(ComponentFactoryImpl ui, org.inspirenxe.strata.api.layout.Orientation orientation)
      Creates an empty panel with no spacing.
      Parameters:
      ui - the factory that owns the panel
      orientation - the stacking direction
  • Method Details

    • orientation

      public org.inspirenxe.strata.api.layout.Orientation orientation()
      Specified by:
      orientation in interface org.inspirenxe.strata.api.layout.StackPanel
    • setOrientation

      public org.inspirenxe.strata.api.layout.StackPanel setOrientation(org.inspirenxe.strata.api.layout.Orientation orientation)
      Specified by:
      setOrientation in interface org.inspirenxe.strata.api.layout.StackPanel
    • spacing

      public float spacing()
      Specified by:
      spacing in interface org.inspirenxe.strata.api.layout.StackPanel
    • setSpacing

      public org.inspirenxe.strata.api.layout.StackPanel setSpacing(float spacing)
      Specified by:
      setSpacing in interface org.inspirenxe.strata.api.layout.StackPanel
    • isSpread

      public boolean isSpread()
      Specified by:
      isSpread in interface org.inspirenxe.strata.api.layout.StackPanel
    • setSpread

      public org.inspirenxe.strata.api.layout.StackPanel setSpread(boolean spread)
      Specified by:
      setSpread in interface org.inspirenxe.strata.api.layout.StackPanel
    • weight

      public float weight(org.inspirenxe.strata.api.component.Component<?> child)
      Specified by:
      weight in interface org.inspirenxe.strata.api.layout.StackPanel
    • setWeight

      public org.inspirenxe.strata.api.layout.StackPanel setWeight(org.inspirenxe.strata.api.component.Component<?> child, float weight)
      Specified by:
      setWeight in interface org.inspirenxe.strata.api.layout.StackPanel
    • onChildRemoved

      protected void onChildRemoved(org.inspirenxe.strata.api.component.Component<?> child)
      Description copied from class: BuiltInComposite
      Called after a child is removed, to drop any data kept about it. The default does nothing.
      Overrides:
      onChildRemoved in class BuiltInComposite<org.inspirenxe.strata.api.layout.StackPanel>
      Parameters:
      child - the removed child
    • measure

      protected org.inspirenxe.strata.api.geometry.Size measure(org.inspirenxe.strata.api.extension.MeasureContext context, float availableWidth, float availableHeight)
      Description copied from class: BuiltInComponent
      Returns the size the content needs within the given space, as CustomComponent.measure does.
      Specified by:
      measure in class BuiltInComponent<org.inspirenxe.strata.api.layout.StackPanel>
      Parameters:
      context - text measurement and child measuring
      availableWidth - the width offered, margin removed; may be Float.POSITIVE_INFINITY
      availableHeight - the height offered, margin removed; may be Float.POSITIVE_INFINITY
      Returns:
      the natural size of the content
    • arrange

      protected void arrange(org.inspirenxe.strata.api.extension.ArrangeContext context, org.inspirenxe.strata.api.geometry.Rect bounds)
      Description copied from class: BuiltInComposite
      Gives every child its slot. Called after BuiltInComponent.measure(MeasureContext, float, float), with the component's final bounds, and again with the same bounds after BuiltInComposite.invalidateArrangement().
      Specified by:
      arrange in class BuiltInComposite<org.inspirenxe.strata.api.layout.StackPanel>
      Parameters:
      context - child sizes and slot assignment
      bounds - the component's bounds
    • measureMinimum

      protected org.inspirenxe.strata.api.geometry.Size measureMinimum(org.inspirenxe.strata.api.extension.MeasureContext context)
      Description copied from class: BuiltInComponent
      Returns the smallest size the content can work in, as CustomComponent.measureMinimum does. The default returns Size.ZERO.
      Overrides:
      measureMinimum in class BuiltInComponent<org.inspirenxe.strata.api.layout.StackPanel>
      Parameters:
      context - text measurement and the children's minimums
      Returns:
      the smallest size of the content
    • snapshotState

      protected Object snapshotState()
      Description copied from class: BuiltInComponent
      Returns this component's own state for a snapshot, an immutable value without its children's state. Called only when an event with snapshots captures this component. The default returns null.
      Overrides:
      snapshotState in class BuiltInComponent<org.inspirenxe.strata.api.layout.StackPanel>
      Returns:
      the state, or null for none