Skip to content

Class NineGridPlacement

Definition

Namespace: StardewUI.Layout
Assembly: StardewUI.dll

Model for content placement along a nine-segment grid, i.e. all possible combinations of horizontal and vertical Alignment.

[StardewUI.DuckType]
public record NineGridPlacement : IEquatable<StardewUI.Layout.NineGridPlacement>

Inheritance
Object ⇦ NineGridPlacement

Implements
IEquatable<NineGridPlacement>

Members

Constructors

Name Description
NineGridPlacement(Alignment, Alignment, Point) Model for content placement along a nine-segment grid, i.e. all possible combinations of horizontal and vertical Alignment.

Fields

Name Description
StandardPlacements All the standard placements with no Offset, arranged from bottom-left to top-right.

Properties

Name Description
EqualityContract
HorizontalAlignment Content alignment along the horizontal axis.
Offset Absolute axis-independent pixel offset.
VerticalAlignment Content alignment along the vertical axis.

Methods

Name Description
AtPosition(Vector2, Vector2, Alignment, Alignment) Gets the NineGridPlacement for an alignment pair that resolves to a specified exact position.
EqualsIgnoringOffset(NineGridPlacement) Checks if another NineGridPlacement has the same alignments as this one, regardless of offset.
GetMargin() Calculates what margin should be applied to the content container in order to achieve the Offset.
GetNeighbors(Boolean) Gets the NineGridPlacements that neighbor the current placement, i.e. are reachable in a single Snap(Direction, Boolean).
GetPosition(Vector2, Vector2) Computes the position of some content within its container bounds.
IsMiddle() Checks if this placement is aligned to the exact center of the container, not counting Offset.
Nudge(Direction, Int32) Keeps the same alignments, but pushes the content farther in a specific direction.
Parse(string) Parses a NineGridPlacement from its string representation.
Snap(Direction, Boolean) Snaps to an adjacent grid cell.
TryParse(string, NineGridPlacement) Attempts to parse a NineGridPlacement from its string representation.

Details

Constructors

NineGridPlacement(Alignment, Alignment, Point)

Model for content placement along a nine-segment grid, i.e. all possible combinations of horizontal and vertical Alignment.

public NineGridPlacement(StardewUI.Layout.Alignment HorizontalAlignment, StardewUI.Layout.Alignment VerticalAlignment, Microsoft.Xna.Framework.Point Offset);
Parameters

HorizontalAlignment   Alignment
Content alignment along the horizontal axis.

VerticalAlignment   Alignment
Content alignment along the vertical axis.

Offset   Point
Absolute axis-independent pixel offset.


Fields

StandardPlacements

All the standard placements with no Offset, arranged from bottom-left to top-right.

public static readonly System.Collections.Immutable.IImmutableList<StardewUI.Layout.NineGridPlacement> StandardPlacements;
Field Value

IImmutableList<NineGridPlacement>


Properties

EqualityContract

protected System.Type EqualityContract { get; }
Property Value

Type


HorizontalAlignment

Content alignment along the horizontal axis.

public StardewUI.Layout.Alignment HorizontalAlignment { get; set; }
Property Value

Alignment


Offset

Absolute axis-independent pixel offset.

public Microsoft.Xna.Framework.Point Offset { get; set; }
Property Value

Point


VerticalAlignment

Content alignment along the vertical axis.

public StardewUI.Layout.Alignment VerticalAlignment { get; set; }
Property Value

Alignment


Methods

AtPosition(Vector2, Vector2, Alignment, Alignment)

Gets the NineGridPlacement for an alignment pair that resolves to a specified exact position.

public static StardewUI.Layout.NineGridPlacement AtPosition(Microsoft.Xna.Framework.Vector2 position, Microsoft.Xna.Framework.Vector2 size, StardewUI.Layout.Alignment horizontalAlignment, StardewUI.Layout.Alignment verticalAlignment);
Parameters

position   Vector2
The target position on screen or within the container.

size   Vector2
The size of the viewport or container.

horizontalAlignment   Alignment
The desired horizontal alignment.

verticalAlignment   Alignment
The desired vertical alignment.

Returns

NineGridPlacement

A NineGridPlacement whose HorizontalAlignment and VerticalAlignment match the horizontalAlignment and verticalAlignment, respectively, and whose GetPosition(Vector2, Vector2) will resolve to exactly the specified position.


EqualsIgnoringOffset(NineGridPlacement)

Checks if another NineGridPlacement has the same alignments as this one, regardless of offset.

public bool EqualsIgnoringOffset(StardewUI.Layout.NineGridPlacement other);
Parameters

other   NineGridPlacement
The instance to compare.

Returns

Boolean

true if the other instance has the same alignments, otherwise false.


GetMargin()

Calculates what margin should be applied to the content container in order to achieve the Offset.

public StardewUI.Layout.Edges GetMargin();
Returns

Edges

The margin required to apply the current Offset to a layout container whose content alignment matches the current HorizontalAlignment and VerticalAlignment.

Remarks

Based on the model of a Panel or Frame whose layout is set to Fill() its container and who will adopt the HorizontalAlignment and VerticalAlignment of this placement as its own HorizontalContentAlignment and VerticalContentAlignment (or equivalent for other view types).

Depending on the particular alignments, this can apply either positive or negative margin to either the start or end axis (or both).


GetNeighbors(bool)

Gets the NineGridPlacements that neighbor the current placement, i.e. are reachable in a single Snap(Direction, Boolean).

public System.Collections.Generic.IEnumerable<StardewUI.Layout.NineGridPlacement.Neighbor> GetNeighbors(bool avoidMiddle);
Parameters

avoidMiddle   Boolean
Whether to avoid the exact center, i.e. having both HorizontalAlignment and VerticalAlignment be Middle. This is often used for positioning HUD elements which typically are not useful to show in the middle of the screen, and the positioning UI may want to use that space for button prompts instead.

Returns

IEnumerable<Neighbor>


GetPosition(Vector2, Vector2)

Computes the position of some content within its container bounds.

public Microsoft.Xna.Framework.Vector2 GetPosition(Microsoft.Xna.Framework.Vector2 contentSize, Microsoft.Xna.Framework.Vector2 containerSize);
Parameters

contentSize   Vector2
Size of the content to be positioned.

containerSize   Vector2
Size of the container in which the content will be positioned.

Returns

Vector2

The aligned content position, relative to the container.


IsMiddle()

Checks if this placement is aligned to the exact center of the container, not counting Offset.

public bool IsMiddle();
Returns

Boolean


Nudge(Direction, int)

Keeps the same alignments, but pushes the content farther in a specific direction.

public StardewUI.Layout.NineGridPlacement Nudge(StardewUI.Direction direction, int distance);
Parameters

direction   Direction
Direction of the additional offset.

distance   Int32
Pixel distance to offset in the specified direction.

Returns

NineGridPlacement

A new NineGridPlacement whose alignments are the same as the current instance and whose Offset represents a move from the current offset in the specified direction with the specified distance.


Parse(string)

Parses a NineGridPlacement from its string representation.

public static StardewUI.Layout.NineGridPlacement Parse(string value);
Parameters

value   string
The string value to parse.

Returns

NineGridPlacement

The parsed placement.


Snap(Direction, bool)

Snaps to an adjacent grid cell.

public StardewUI.Layout.NineGridPlacement Snap(StardewUI.Direction direction, bool avoidMiddle);
Parameters

direction   Direction
Direction in which to move.

avoidMiddle   Boolean
Whether to avoid the exact center, i.e. having both HorizontalAlignment and VerticalAlignment be Middle. This is often used for positioning HUD elements which typically are not useful to show in the middle of the screen, and the positioning UI may want to use that space for button prompts instead.

Returns

NineGridPlacement

A new NineGridPlacement representing the adjacent cell in the specified direction, or null if there is no adjacent cell (e.g. trying to snap West from a placement that is already at the horizontal Start).

Remarks

Causes the Offset to be reset for the newly-created placement.


TryParse(string, NineGridPlacement)

Attempts to parse a NineGridPlacement from its string representation.

public static bool TryParse(string value, out StardewUI.Layout.NineGridPlacement result);
Parameters

value   string
The string value to parse.

result   NineGridPlacement
If the method returns true, holds the parsed placement; otherwise null.

Returns

Boolean

true if the value was successfully parsed; false if the input was not in a valid format.