Table of Contents

Struct LayoutRect

Namespace
SharpConsoleUI.Layout
Assembly
SharpConsoleUI.dll

Represents a rectangle with position and size. Immutable value type for layout calculations and hit testing. Named LayoutRect to avoid conflicts with System.Drawing.Rectangle during transition.

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

Constructors

LayoutRect(int, int, int, int)

Represents a rectangle with position and size. Immutable value type for layout calculations and hit testing. Named LayoutRect to avoid conflicts with System.Drawing.Rectangle during transition.

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

Parameters

X int
Y int
Width int
Height int

Properties

Bottom

Gets the bottom edge Y coordinate (exclusive).

public int Bottom { get; }

Property Value

int

Center

Gets the center point of this rectangle.

public (int X, int Y) Center { get; }

Property Value

(int absoluteLeft, int absoluteTop)

Empty

Gets an empty rectangle at the origin.

public static LayoutRect Empty { get; }

Property Value

LayoutRect

Height

public int Height { get; init; }

Property Value

int

IsEmpty

Gets whether this rectangle has zero or negative area.

public bool IsEmpty { get; }

Property Value

bool

Location

Gets the top-left position of this rectangle as X, Y coordinates.

public (int X, int Y) Location { get; }

Property Value

(int absoluteLeft, int absoluteTop)

Right

Gets the right edge X coordinate (exclusive).

public int Right { get; }

Property Value

int

Size

Gets the size of this rectangle.

public LayoutSize Size { get; }

Property Value

LayoutSize

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

Contains(LayoutRect)

Determines whether this rectangle fully contains another rectangle.

public bool Contains(LayoutRect other)

Parameters

other LayoutRect

Returns

bool

Contains(Point)

Determines whether this rectangle contains the specified point.

public bool Contains(Point point)

Parameters

point Point

Returns

bool

Contains(int, int)

Determines whether this rectangle contains the specified point.

public bool Contains(int x, int y)

Parameters

x int
y int

Returns

bool

Deflate(int, int)

Returns a new rectangle deflated by the specified amounts on all sides.

public LayoutRect Deflate(int horizontal, int vertical)

Parameters

horizontal int
vertical int

Returns

LayoutRect

FromPositionAndSize(int, int, LayoutSize)

Creates a rectangle from position and size.

public static LayoutRect FromPositionAndSize(int x, int y, LayoutSize size)

Parameters

x int
y int
size LayoutSize

Returns

LayoutRect

FromRectangle(Rectangle)

Creates from System.Drawing.Rectangle.

public static LayoutRect FromRectangle(Rectangle rect)

Parameters

rect Rectangle

Returns

LayoutRect

Inflate(int, int)

Returns a new rectangle inflated by the specified amounts on all sides.

public LayoutRect Inflate(int horizontal, int vertical)

Parameters

horizontal int
vertical int

Returns

LayoutRect

Intersect(LayoutRect)

Returns the intersection of this rectangle with another, or Empty if they don't intersect.

public LayoutRect Intersect(LayoutRect other)

Parameters

other LayoutRect

Returns

LayoutRect

IntersectsWith(LayoutRect)

Determines whether this rectangle intersects with another rectangle.

public bool IntersectsWith(LayoutRect other)

Parameters

other LayoutRect

Returns

bool

Offset(int, int)

Returns a new rectangle offset by the specified amounts.

public LayoutRect Offset(int dx, int dy)

Parameters

dx int
dy int

Returns

LayoutRect

ToRectangle()

Converts to System.Drawing.Rectangle.

public Rectangle ToRectangle()

Returns

Rectangle

ToString()

Returns a string representation of this rectangle.

public override string ToString()

Returns

string

Union(LayoutRect)

Returns the smallest rectangle that contains both this and another rectangle.

public LayoutRect Union(LayoutRect other)

Parameters

other LayoutRect

Returns

LayoutRect

WithPosition(int, int)

Returns a new rectangle with the position set to the specified coordinates.

public LayoutRect WithPosition(int x, int y)

Parameters

x int
y int

Returns

LayoutRect

WithSize(LayoutSize)

Returns a new rectangle with the size set to the specified size.

public LayoutRect WithSize(LayoutSize size)

Parameters

size LayoutSize

Returns

LayoutRect

WithSize(int, int)

Returns a new rectangle with the size set to the specified dimensions.

public LayoutRect WithSize(int width, int height)

Parameters

width int
height int

Returns

LayoutRect