Table of Contents

Class GridTrackSizer

Namespace
SharpConsoleUI.Layout
Assembly
SharpConsoleUI.dll

Turns a list of GridLength track definitions into concrete integer track sizes along a single axis (columns or rows). This is a pure function: it performs no rendering and holds no state, which makes it fully unit-testable in isolation.

public static class GridTrackSizer
Inheritance
GridTrackSizer
Inherited Members

Remarks

The sizing pass runs in three stages:

  1. Gaps between adjacent tracks are reserved up front.
  2. Fixed and Auto tracks are sized directly (the latter from autoContentSizes) and clamped to their optional Min/Max bounds.
  3. Star tracks split the remaining space by weight. Because a star track's Min/Max can clamp it, the split runs iteratively: any track that clamps is pinned and removed from the pool, and the remaining unclamped stars re-split the adjusted remainder.

Integer rounding is distributed via accumulated fractional remainder so star totals stay exact (no cells gained or lost). Track sizes are never negative.

When constraints are contradictory the function favours honesty over silently violating a constraint. If fixed/auto tracks plus gaps already exceed available, star tracks collapse to 0 (the grid overflows but no size is negative). If star Min values over-subscribe the space (their sum exceeds the remaining pool), every star is pinned to its Min and the returned total may therefore EXCEED available — contradictory minimums cannot all be honoured inside the available space. The iterative star pass always terminates: each pass pins at least one track and removes it from the unclamped set, so it runs at most once per star track.

Methods

Size(IReadOnlyList<GridLength>, int[], int, int)

Computes the concrete integer size of each track.

public static int[] Size(IReadOnlyList<GridLength> defs, int[] autoContentSizes, int available, int gap)

Parameters

defs IReadOnlyList<GridLength>

The track definitions, one per row or column.

autoContentSizes int[]

Parallel array giving, for each Auto track, the maximum desired content size of its cells. Entries for non-Auto tracks are ignored (typically 0).

available int

The total space available along this axis, in cells.

gap int

The gap size, in cells, between adjacent tracks.

Returns

int[]

An array with one resolved integer size per track. Sizes are never negative.