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
MediumFraction
The desktop fraction used by Medium (60%).
public const double MediumFraction = 0.6
Field Value
SmallFraction
The desktop fraction used by Small (40%).
public const double SmallFraction = 0.4
Field Value
Properties
AnchorValue
public Anchor AnchorValue { get; }
Property Value
FractionX
public double FractionX { get; }
Property Value
FractionY
public double FractionY { get; }
Property Value
Height
Gets the explicit height in cells (valid for CenterExplicit and Anchor).
public int Height { get; }
Property Value
Kind
Gets the discriminator identifying which factory produced this placement.
public PlacementKind Kind { get; }
Property Value
Margin
Gets the margin in cells from the anchored edge (valid for Anchor).
public int Margin { get; }
Property Value
Maximized
Gets a placement that fills the entire usable desktop. Equivalent to Snap(SnapZone.Full).
public static Placement Maximized { get; }
Property Value
Preset
Gets the size preset (valid when Kind is CenterPreset).
public SizePreset Preset { get; }
Property Value
Width
Gets the explicit width in cells (valid for CenterExplicit and Anchor).
public int Width { get; }
Property Value
Zone
public SnapZone Zone { get; }
Property Value
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
anchorAnchorThe corner, edge, or center to align the window to.
widthintThe desired window width in cells.
heightintThe desired window height in cells.
marginintThe 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
presetSizePreset
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
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
otherPlacementAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
anchorAnchorThe corner, edge, or center to align the window to.
fractionXdoubleThe window width as a fraction (0..1) of the usable desktop width.
fractionYdoubleThe 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
presetSizePresetThe 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
zoneSnapZoneThe 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
Returns
- bool
trueif the placements are equal; otherwisefalse.
operator !=(Placement, Placement)
Determines whether two placements differ by value.
public static bool operator !=(Placement left, Placement right)
Parameters
Returns
- bool
trueif the placements differ; otherwisefalse.