Options
All
  • Public
  • Public/Protected
  • All
Menu

Module BoxEngine

The namespace for the box engine layout functions.

Index

Functions

Functions

adjust

  • adjust(sizers: ArrayLike<BoxSizer>, index: number, delta: number): void
  • Adjust a sizer by a delta and update its neighbors accordingly.

    Parameters

    • sizers: ArrayLike<BoxSizer>

      The sizers which should be adjusted.

    • index: number

      The index of the sizer to grow.

    • delta: number

      The amount to adjust the sizer, positive or negative.

      Notes

      This will adjust the indicated sizer by the specified amount, along with the sizes of the appropriate neighbors, subject to the limits specified by each of the sizers.

      This is useful when implementing box layouts where the boundaries between the sizers are interactively adjustable by the user.

    Returns void

calc

  • calc(sizers: ArrayLike<BoxSizer>, space: number): number
  • Calculate the optimal layout sizes for a sequence of box sizers.

    This distributes the available layout space among the box sizers according to the following algorithm:

    1. Initialize the sizers's size to its size hint and compute the sums for each of size hint, min size, and max size.

    2. If the total size hint equals the available space, return.

    3. If the available space is less than the total min size, set all sizers to their min size and return.

    4. If the available space is greater than the total max size, set all sizers to their max size and return.

    5. If the layout space is less than the total size hint, distribute the negative delta as follows:

      a. Shrink each sizer with a stretch factor greater than zero by an amount proportional to the negative space and the sum of stretch factors. If the sizer reaches its min size, remove it and its stretch factor from the computation.

      b. If after adjusting all stretch sizers there remains negative space, distribute the space equally among the sizers with a stretch factor of zero. If a sizer reaches its min size, remove it from the computation.

    6. If the layout space is greater than the total size hint, distribute the positive delta as follows:

      a. Expand each sizer with a stretch factor greater than zero by an amount proportional to the postive space and the sum of stretch factors. If the sizer reaches its max size, remove it and its stretch factor from the computation.

      b. If after adjusting all stretch sizers there remains positive space, distribute the space equally among the sizers with a stretch factor of zero. If a sizer reaches its max size, remove it from the computation.

    7. return

    Parameters

    • sizers: ArrayLike<BoxSizer>

      The sizers for a particular layout line.

    • space: number

      The available layout space for the sizers.

    Returns number

    The delta between the provided available space and the actual consumed space. This value will be zero if the sizers can be adjusted to fit, negative if the available space is too small, and positive if the available space is too large.

    Notes

    The size of each sizer is updated with the computed size.

    This function can be called at any time to recompute the layout for an existing sequence of sizers. The previously computed results will have no effect on the new output. It is therefore not necessary to create new sizer objects on each resize event.

Generated using TypeDoc