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
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
Properties
HasTightHeight
Gets whether the height is tightly constrained (min == max).
public bool HasTightHeight { get; }
Property Value
HasTightWidth
Gets whether the width is tightly constrained (min == max).
public bool HasTightWidth { get; }
Property Value
IsHeightEffectivelyUnbounded
Gets whether the maximum height is effectively unbounded (no real finite slot supplied).
public bool IsHeightEffectivelyUnbounded { get; }
Property Value
IsTight
Gets whether both dimensions are tightly constrained.
public bool IsTight { get; }
Property Value
IsWidthEffectivelyUnbounded
Gets whether the maximum width is effectively unbounded (no real finite slot supplied).
public bool IsWidthEffectivelyUnbounded { get; }
Property Value
MaxHeight
The maximum height, in cells. Never less than MinHeight.
public int MaxHeight { get; init; }
Property Value
MaxSize
Gets the maximum size from these constraints.
public LayoutSize MaxSize { get; }
Property Value
MaxWidth
The maximum width, in cells. Never less than MinWidth.
public int MaxWidth { get; init; }
Property Value
MinHeight
The minimum height, in cells.
public int MinHeight { get; init; }
Property Value
MinSize
Gets the minimum size from these constraints.
public LayoutSize MinSize { get; }
Property Value
MinWidth
The minimum width, in cells.
public int MinWidth { get; init; }
Property Value
Unbounded
Gets unbounded constraints (0 to MaxValue).
public static LayoutConstraints Unbounded { get; }
Property Value
Zero
Gets zero-size constraints.
public static LayoutConstraints Zero { get; }
Property Value
Methods
Constrain(LayoutSize)
Constrains a size to fit within these bounds.
public LayoutSize Constrain(LayoutSize size)
Parameters
sizeLayoutSize
Returns
Constrain(int, int)
Constrains dimensions to fit within these bounds.
public LayoutSize Constrain(int width, int height)
Parameters
Returns
Fixed(LayoutSize)
Creates constraints with fixed size.
public static LayoutConstraints Fixed(LayoutSize size)
Parameters
sizeLayoutSize
Returns
Fixed(int, int)
Creates constraints with fixed width and height.
public static LayoutConstraints Fixed(int width, int height)
Parameters
Returns
Intersect(LayoutConstraints)
Returns constraints that are the intersection of this and another.
public LayoutConstraints Intersect(LayoutConstraints other)
Parameters
otherLayoutConstraints
Returns
IsSatisfiedBy(LayoutSize)
Returns whether a size satisfies these constraints.
public bool IsSatisfiedBy(LayoutSize size)
Parameters
sizeLayoutSize
Returns
Loose(LayoutSize)
Creates constraints with maximum bounds but no minimum.
public static LayoutConstraints Loose(LayoutSize maxSize)
Parameters
maxSizeLayoutSize
Returns
Loose(int, int)
Creates constraints with maximum bounds but no minimum.
public static LayoutConstraints Loose(int maxWidth, int maxHeight)
Parameters
Returns
SubtractHeight(int)
Returns constraints with the maximum height reduced by the specified amount.
public LayoutConstraints SubtractHeight(int height)
Parameters
heightint
Returns
SubtractWidth(int)
Returns constraints with the maximum width reduced by the specified amount.
public LayoutConstraints SubtractWidth(int width)
Parameters
widthint
Returns
Tight(LayoutSize)
Creates tight constraints where min equals max.
public static LayoutConstraints Tight(LayoutSize size)
Parameters
sizeLayoutSize
Returns
Tight(int, int)
Creates tight constraints where min equals max.
public static LayoutConstraints Tight(int width, int height)
Parameters
Returns
ToString()
Returns a string representation of these layout constraints.
public override string ToString()
Returns
WithMaxHeight(int)
Returns constraints with a new maximum height.
public LayoutConstraints WithMaxHeight(int maxHeight)
Parameters
maxHeightint
Returns
WithMaxWidth(int)
Returns constraints with a new maximum width.
public LayoutConstraints WithMaxWidth(int maxWidth)
Parameters
maxWidthint
Returns
WithMinHeight(int)
Returns constraints with a new minimum height.
public LayoutConstraints WithMinHeight(int minHeight)
Parameters
minHeightint
Returns
WithMinWidth(int)
Returns constraints with a new minimum width.
public LayoutConstraints WithMinWidth(int minWidth)
Parameters
minWidthint