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
Rect(int, int, int, int)
Rectangle defined by position and size.
public Rect(int X, int Y, int Width, int Height)
Parameters
Properties
Bottom
Bottom edge Y coordinate (Y + Height).
public int Bottom { get; }
Property Value
Center
Center point of the rectangle.
public Vec2 Center { get; }
Property Value
Height
public int Height { get; init; }
Property Value
IsEmpty
True when the rect has no area (width or height is zero or negative).
public bool IsEmpty { get; }
Property Value
Position
Top-left position as Vec2.
public Vec2 Position { get; }
Property Value
Right
Right edge X coordinate (X + Width).
public int Right { get; }
Property Value
Size
Size as Vec2.
public Vec2 Size { get; }
Property Value
Width
public int Width { get; init; }
Property Value
X
public int X { get; init; }
Property Value
Y
public int Y { get; init; }
Property Value
Methods
Clamp(Rect)
Move this rect inside bounds, shrinking it if it's larger than the bounds.
public Rect Clamp(Rect bounds)
Parameters
boundsRect
Returns
Columns()
Each column of this rect, left to right, as a rect of width 1.
public IEnumerable<Rect> Columns()
Returns
Contains(Vec2)
Check if a point is inside this rect.
public bool Contains(Vec2 pos)
Parameters
posVec2
Returns
Contains(int, int)
Check if a point is inside this rect.
public bool Contains(int x, int y)
Parameters
Returns
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
marginMargin
Returns
Intersect(Rect)
The overlap of two rects. If they don't overlap, the result is empty.
public Rect Intersect(Rect other)
Parameters
otherRect
Returns
Rows()
Each row of this rect, top to bottom, as a rect of height 1.
public IEnumerable<Rect> Rows()
Returns
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
marginint
Returns
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
Returns
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
topHeightint
Returns
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
leftWidthint