Table of Contents

Struct LayoutConstraints

Namespace
SharpConsoleUI.Layout
Assembly
SharpConsoleUI.dll

Represents layout constraints for measuring controls. Defines minimum and maximum width/height bounds.

public readonly record struct LayoutConstraints : IEquatable<LayoutConstraints>
Implements
Inherited Members
Extension Methods

Remarks

The MaxWidth/MaxHeight bounds are normalized on construction to never fall below their corresponding minimum: a degenerate constraint (e.g. Min=1, Max=0, which can arise when a hosting cell collapses to zero — such as a grid track animated to 0 width) is clamped to Max = Min. This guarantees Min <= Max for every consumer, so controls can safely call Math.Clamp(value, MinWidth, MaxWidth) without it throwing (CLAUDE.md: never feed Math.Clamp a min greater than its max). The positional parameter names are retained for source compatibility.

Constructors

LayoutConstraints(int, int, int, int)

Creates layout constraints, normalizing each maximum up to its corresponding minimum so the resulting bounds always satisfy Min <= Max.

public LayoutConstraints(int MinWidth, int MaxWidth, int MinHeight, int MaxHeight)

Parameters

MinWidth int
MaxWidth int
MinHeight int
MaxHeight int

Fields

UnboundedThreshold

Threshold above which a Max bound is treated as "effectively unbounded". An unbounded constraint starts at MaxValue, but operations like SubtractHeight(int)/SubtractWidth(int) erode it by a few rows/columns (e.g. margins), so an exact == int.MaxValue check is unreliable. No real terminal viewport is anywhere near a billion cells, so any Max bound this large means "no real upper bound was supplied".

public const int UnboundedThreshold = 1000000000

Field Value

int

Properties

HasTightHeight

Gets whether the height is tightly constrained (min == max).

public bool HasTightHeight { get; }

Property Value

bool

HasTightWidth

Gets whether the width is tightly constrained (min == max).

public bool HasTightWidth { get; }

Property Value

bool

IsHeightEffectivelyUnbounded

Gets whether the maximum height is effectively unbounded (no real finite slot supplied).

public bool IsHeightEffectivelyUnbounded { get; }

Property Value

bool

IsTight

Gets whether both dimensions are tightly constrained.

public bool IsTight { get; }

Property Value

bool

IsWidthEffectivelyUnbounded

Gets whether the maximum width is effectively unbounded (no real finite slot supplied).

public bool IsWidthEffectivelyUnbounded { get; }

Property Value

bool

MaxHeight

The maximum height, in cells. Never less than MinHeight.

public int MaxHeight { get; init; }

Property Value

int

MaxSize

Gets the maximum size from these constraints.

public LayoutSize MaxSize { get; }

Property Value

LayoutSize

MaxWidth

The maximum width, in cells. Never less than MinWidth.

public int MaxWidth { get; init; }

Property Value

int

MinHeight

The minimum height, in cells.

public int MinHeight { get; init; }

Property Value

int

MinSize

Gets the minimum size from these constraints.

public LayoutSize MinSize { get; }

Property Value

LayoutSize

MinWidth

The minimum width, in cells.

public int MinWidth { get; init; }

Property Value

int

Unbounded

Gets unbounded constraints (0 to MaxValue).

public static LayoutConstraints Unbounded { get; }

Property Value

LayoutConstraints

Zero

Gets zero-size constraints.

public static LayoutConstraints Zero { get; }

Property Value

LayoutConstraints

Methods

Constrain(LayoutSize)

Constrains a size to fit within these bounds.

public LayoutSize Constrain(LayoutSize size)

Parameters

size LayoutSize

Returns

LayoutSize

Constrain(int, int)

Constrains dimensions to fit within these bounds.

public LayoutSize Constrain(int width, int height)

Parameters

width int
height int

Returns

LayoutSize

Fixed(LayoutSize)

Creates constraints with fixed size.

public static LayoutConstraints Fixed(LayoutSize size)

Parameters

size LayoutSize

Returns

LayoutConstraints

Fixed(int, int)

Creates constraints with fixed width and height.

public static LayoutConstraints Fixed(int width, int height)

Parameters

width int
height int

Returns

LayoutConstraints

Intersect(LayoutConstraints)

Returns constraints that are the intersection of this and another.

public LayoutConstraints Intersect(LayoutConstraints other)

Parameters

other LayoutConstraints

Returns

LayoutConstraints

IsSatisfiedBy(LayoutSize)

Returns whether a size satisfies these constraints.

public bool IsSatisfiedBy(LayoutSize size)

Parameters

size LayoutSize

Returns

bool

Loose(LayoutSize)

Creates constraints with maximum bounds but no minimum.

public static LayoutConstraints Loose(LayoutSize maxSize)

Parameters

maxSize LayoutSize

Returns

LayoutConstraints

Loose(int, int)

Creates constraints with maximum bounds but no minimum.

public static LayoutConstraints Loose(int maxWidth, int maxHeight)

Parameters

maxWidth int
maxHeight int

Returns

LayoutConstraints

SubtractHeight(int)

Returns constraints with the maximum height reduced by the specified amount.

public LayoutConstraints SubtractHeight(int height)

Parameters

height int

Returns

LayoutConstraints

SubtractWidth(int)

Returns constraints with the maximum width reduced by the specified amount.

public LayoutConstraints SubtractWidth(int width)

Parameters

width int

Returns

LayoutConstraints

Tight(LayoutSize)

Creates tight constraints where min equals max.

public static LayoutConstraints Tight(LayoutSize size)

Parameters

size LayoutSize

Returns

LayoutConstraints

Tight(int, int)

Creates tight constraints where min equals max.

public static LayoutConstraints Tight(int width, int height)

Parameters

width int
height int

Returns

LayoutConstraints

ToString()

Returns a string representation of these layout constraints.

public override string ToString()

Returns

string

WithMaxHeight(int)

Returns constraints with a new maximum height.

public LayoutConstraints WithMaxHeight(int maxHeight)

Parameters

maxHeight int

Returns

LayoutConstraints

WithMaxWidth(int)

Returns constraints with a new maximum width.

public LayoutConstraints WithMaxWidth(int maxWidth)

Parameters

maxWidth int

Returns

LayoutConstraints

WithMinHeight(int)

Returns constraints with a new minimum height.

public LayoutConstraints WithMinHeight(int minHeight)

Parameters

minHeight int

Returns

LayoutConstraints

WithMinWidth(int)

Returns constraints with a new minimum width.

public LayoutConstraints WithMinWidth(int minWidth)

Parameters

minWidth int

Returns

LayoutConstraints