Table of Contents

Struct Rect

Namespace
MiniTui
Assembly
MiniTui.dll

Rectangle defined by position and size.

public readonly record struct Rect : IEquatable<Rect>
Implements
Inherited Members

Constructors

Rect(Vec2, Vec2)

Create a rect from position and size vectors.

public Rect(Vec2 pos, Vec2 size)

Parameters

pos Vec2
size Vec2

Rect(int, int, int, int)

Rectangle defined by position and size.

public Rect(int X, int Y, int Width, int Height)

Parameters

X int
Y int
Width int
Height int

Properties

Bottom

Bottom edge Y coordinate (Y + Height).

public int Bottom { get; }

Property Value

int

Center

Center point of the rectangle.

public Vec2 Center { get; }

Property Value

Vec2

Height

public int Height { get; init; }

Property Value

int

IsEmpty

True when the rect has no area (width or height is zero or negative).

public bool IsEmpty { get; }

Property Value

bool

Position

Top-left position as Vec2.

public Vec2 Position { get; }

Property Value

Vec2

Right

Right edge X coordinate (X + Width).

public int Right { get; }

Property Value

int

Size

Size as Vec2.

public Vec2 Size { get; }

Property Value

Vec2

Width

public int Width { get; init; }

Property Value

int

X

public int X { get; init; }

Property Value

int

Y

public int Y { get; init; }

Property Value

int

Methods

Clamp(Rect)

Move this rect inside bounds, shrinking it if it's larger than the bounds.

public Rect Clamp(Rect bounds)

Parameters

bounds Rect

Returns

Rect

Columns()

Each column of this rect, left to right, as a rect of width 1.

public IEnumerable<Rect> Columns()

Returns

IEnumerable<Rect>

Contains(Vec2)

Check if a point is inside this rect.

public bool Contains(Vec2 pos)

Parameters

pos Vec2

Returns

bool

Contains(int, int)

Check if a point is inside this rect.

public bool Contains(int x, int y)

Parameters

x int
y int

Returns

bool

Inner(Margin)

Returns the area inside margin. Sizes never go below zero; an axis that doesn't fit collapses to its center.

public Rect Inner(Margin margin)

Parameters

margin Margin

Returns

Rect

Intersect(Rect)

The overlap of two rects. If they don't overlap, the result is empty.

public Rect Intersect(Rect other)

Parameters

other Rect

Returns

Rect

Rows()

Each row of this rect, top to bottom, as a rect of height 1.

public IEnumerable<Rect> Rows()

Returns

IEnumerable<Rect>

Shrink(int)

Returns a new rect with margins subtracted from all sides. Sizes never go below zero; an over-shrunk rect collapses to its center.

public Rect Shrink(int margin)

Parameters

margin int

Returns

Rect

Shrink(int, int)

Returns a new rect with different margins for horizontal and vertical. Sizes never go below zero; an over-shrunk rect collapses to its center.

public Rect Shrink(int horizontal, int vertical)

Parameters

horizontal int
vertical int

Returns

Rect

SplitHorizontal(int)

Split horizontally at a given row offset from top, returns (top, bottom). The offset is clamped to the rect, so neither part has a negative height.

public (Rect Top, Rect Bottom) SplitHorizontal(int topHeight)

Parameters

topHeight int

Returns

(Rect Top, Rect Bottom)

SplitVertical(int)

Split vertically at a given column offset from left, returns (left, right). The offset is clamped to the rect, so neither part has a negative width.

public (Rect Left, Rect Right) SplitVertical(int leftWidth)

Parameters

leftWidth int

Returns

(Rect Top, Rect Bottom)