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
Property Value
HorizontalAlignment
Content alignment along the horizontal axis.
Property Value
Offset
Absolute axis-independent pixel offset.
Property Value
VerticalAlignment
Content alignment along the vertical axis.
Property Value
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
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.
Parameters
other
NineGridPlacement
The instance to compare.
Returns
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.
Returns
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
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
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.
Returns
Nudge(Direction, int)
Keeps the same alignments, but pushes the content farther in a specific direction.
Parameters
direction
Direction
Direction of the additional offset.
distance
Int32
Pixel distance to offset in the specified direction
.
Returns
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.
Parameters
value
string
The string value to parse.
Returns
The parsed placement.
Snap(Direction, bool)
Snaps to an adjacent grid cell.
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
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.
Parameters
value
string
The string value to parse.
result
NineGridPlacement
If the method returns true
, holds the parsed placement; otherwise null
.
Returns
true
if the value
was successfully parsed; false
if the input was not in a valid format.