Table of Contents

Struct Placement

Namespace
SharpConsoleUI.Layout
Assembly
SharpConsoleUI.dll

An immutable, value-comparable description of where a window should be positioned and sized relative to the live usable desktop. A Placement carries only intent; the concrete pixel/cell bounds are computed by Resolve(Placement) against the current desktop geometry, so the same placement re-resolves correctly after a resize.

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

Remarks

Create instances via the factory statics (Snap(SnapZone), Center(SizePreset), Center(int, int), Anchor(Anchor, int, int, int), Fraction(Anchor, double, double), or Maximized). Because this is a readonly struct it has structural value equality, so two placements built from identical arguments compare equal.

Fields

LargeFraction

The desktop fraction used by Large (85%).

public const double LargeFraction = 0.85

Field Value

double

MediumFraction

The desktop fraction used by Medium (60%).

public const double MediumFraction = 0.6

Field Value

double

SmallFraction

The desktop fraction used by Small (40%).

public const double SmallFraction = 0.4

Field Value

double

Properties

AnchorValue

Gets the anchor (valid when Kind is Anchor or Fraction).

public Anchor AnchorValue { get; }

Property Value

Anchor

FractionX

Gets the horizontal desktop fraction (valid when Kind is Fraction).

public double FractionX { get; }

Property Value

double

FractionY

Gets the vertical desktop fraction (valid when Kind is Fraction).

public double FractionY { get; }

Property Value

double

Height

Gets the explicit height in cells (valid for CenterExplicit and Anchor).

public int Height { get; }

Property Value

int

Kind

Gets the discriminator identifying which factory produced this placement.

public PlacementKind Kind { get; }

Property Value

PlacementKind

Margin

Gets the margin in cells from the anchored edge (valid for Anchor).

public int Margin { get; }

Property Value

int

Maximized

Gets a placement that fills the entire usable desktop. Equivalent to Snap(SnapZone.Full).

public static Placement Maximized { get; }

Property Value

Placement

Preset

Gets the size preset (valid when Kind is CenterPreset).

public SizePreset Preset { get; }

Property Value

SizePreset

Width

Gets the explicit width in cells (valid for CenterExplicit and Anchor).

public int Width { get; }

Property Value

int

Zone

Gets the snap zone (valid when Kind is Snap).

public SnapZone Zone { get; }

Property Value

SnapZone

Methods

Anchor(Anchor, int, int, int)

Creates an anchored placement with an explicit size in cells and an optional margin from the anchored edge(s).

public static Placement Anchor(Anchor anchor, int width, int height, int margin = 0)

Parameters

anchor Anchor

The corner, edge, or center to align the window to.

width int

The desired window width in cells.

height int

The desired window height in cells.

margin int

The margin in cells from the anchored edge(s). Defaults to 0.

Returns

Placement

An anchored placement with the given size and margin.

Center(SizePreset)

Creates a centered placement sized as a fraction of the usable desktop per the given preset.

public static Placement Center(SizePreset preset)

Parameters

preset SizePreset

The size preset (Small, Medium, or Large).

Returns

Placement

A centered placement sized from the preset.

Center(int, int)

Creates a centered placement with an explicit size in cells. The size is clamped to the usable desktop.

public static Placement Center(int width, int height)

Parameters

width int

The desired window width in cells.

height int

The desired window height in cells.

Returns

Placement

A centered placement with the given size.

Equals(Placement)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Placement other)

Parameters

other Placement

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Fraction(Anchor, double, double)

Creates an anchored placement sized as a fraction of the usable desktop in each dimension.

public static Placement Fraction(Anchor anchor, double fractionX, double fractionY)

Parameters

anchor Anchor

The corner, edge, or center to align the window to.

fractionX double

The window width as a fraction (0..1) of the usable desktop width.

fractionY double

The window height as a fraction (0..1) of the usable desktop height.

Returns

Placement

A fraction-sized anchored placement.

FractionFor(SizePreset)

Gets the desktop fraction associated with a SizePreset.

public static double FractionFor(SizePreset preset)

Parameters

preset SizePreset

The preset to resolve.

Returns

double

The fraction (0..1) of the usable desktop in each dimension.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Snap(SnapZone)

Creates a placement that tiles the window into the given zone of the usable desktop.

public static Placement Snap(SnapZone zone)

Parameters

zone SnapZone

The half or quadrant zone to snap into.

Returns

Placement

A snap placement for the specified zone.

Operators

operator ==(Placement, Placement)

Determines whether two placements are equal by value.

public static bool operator ==(Placement left, Placement right)

Parameters

left Placement

The first placement.

right Placement

The second placement.

Returns

bool

true if the placements are equal; otherwise false.

operator !=(Placement, Placement)

Determines whether two placements differ by value.

public static bool operator !=(Placement left, Placement right)

Parameters

left Placement

The first placement.

right Placement

The second placement.

Returns

bool

true if the placements differ; otherwise false.