Class GridLayout
- Namespace
- SharpConsoleUI.Layout
- Assembly
- SharpConsoleUI.dll
A WinUI-<Grid>-style 2D layout algorithm. Sizes its row and column tracks from the
IGridSource seam (fixed, auto-to-content, or proportional star) and places each
cell into its assigned tracks. Auto tracks are sized to the largest desired size of the cells
that occupy them; spanning cells contribute their desired size spread evenly across the auto
tracks they cover.
public sealed class GridLayout : ILayoutContainer, IRegionClippingLayout
- Inheritance
-
GridLayout
- Implements
- Inherited Members
- Extension Methods
Remarks
This type implements the measure and arrange passes, and clips each cell child to its track rectangle in GetPaintClipRect(LayoutNode, LayoutRect).
Constructors
GridLayout(IGridSource)
Initializes a new GridLayout backed by the given source.
public GridLayout(IGridSource source)
Parameters
sourceIGridSourceThe grid source exposing track definitions, gaps, margin/padding, and cells.
Exceptions
- ArgumentNullException
Thrown when
sourceis null.
Methods
ArrangeChildren(LayoutNode, LayoutRect)
Arranges the grid's cells into their assigned track rectangles. The local area is inset by the grid's margin then padding to form the track area; tracks are sized exactly as in the measure pass; each cell is positioned at its track offset, inset by the child's own margin, then aligned within the resulting inner box per the child's horizontal and vertical alignment (mirroring ArrangeChildren(LayoutNode, LayoutRect)). Invisible children are skipped.
public void ArrangeChildren(LayoutNode node, LayoutRect finalRect)
Parameters
nodeLayoutNodefinalRectLayoutRect
Remarks
finalRect is node-local (origin 0,0); cell rectangles are therefore computed
in local coordinates. Each cell's pre-alignment, pre-child-margin rectangle is cached in
SharpConsoleUI.Layout.GridLayout._cellRects for the paint-clip pass.
GetPaintClipRect(LayoutNode, LayoutRect)
Restricts a cell child's paint area to its track rectangle, intersected with the parent clip, so a child can never paint outside the cell it was placed in. The cell rectangle cached during arrange (SharpConsoleUI.Layout.GridLayout._cellRects) is node-local, so it is offset by the grid node's absolute origin to reach screen space before intersecting.
public LayoutRect GetPaintClipRect(LayoutNode child, LayoutRect parentClipRect)
Parameters
childLayoutNodeThe cell child whose paint clip is being resolved.
parentClipRectLayoutRectThe parent's visible bounds, in absolute/screen coordinates.
Returns
- LayoutRect
The cell rectangle (in absolute coordinates) intersected with
parentClipRect, or the parent clip unchanged when no cell rectangle is recorded for the child (e.g. arrange has not run yet, or the child was removed between arrange and paint) so the child is never over-clipped.
MeasureChildren(LayoutNode, LayoutConstraints)
Measures the grid's cells, sizes the row and column tracks, and returns the grid's desired size (track totals plus gaps, margin, and padding, clamped to the incoming constraints).
public LayoutSize MeasureChildren(LayoutNode node, LayoutConstraints constraints)
Parameters
nodeLayoutNodeconstraintsLayoutConstraints