Skip to content

Struct Length

Definition

Namespace: StardewUI.Layout
Assembly: StardewUI.dll

Specifies how to calculate the length of a single dimension (width or height).

[StardewUI.DuckType]
public readonly struct Length : IEquatable<StardewUI.Layout.Length>

Inheritance
ObjectValueType ⇦ Length

Implements
IEquatable<Length>

Members

Constructors

Name Description
Length(LengthType, Single) Specifies how to calculate the length of a single dimension (width or height).

Properties

Name Description
Type Specifies how to interpret the Value.
Value The dimension value, with behavior determined by Type.

Methods

Name Description
Content() Creates a new Length having Content.
Parse(ReadOnlySpan<Char>) Parses a Length from its string representation.
Parse(string) Parses a Length from its string representation.
Percent(Single) Creates a new Length having Percent and the specified percent size.
Px(Single) Creates a new Length having Px and the specified pixel size.
Resolve(Single, Func<Single>) Resolves an actual (pixel) length.
Stretch() Creates a new Length having Stretch.
ToString() (Overrides Object.ToString())

Details

Constructors

Length(LengthType, float)

Specifies how to calculate the length of a single dimension (width or height).

public Length(StardewUI.Layout.LengthType Type, float Value);
Parameters

Type   LengthType
Specifies how to interpret the Value.

Value   Single
The dimension value, with behavior determined by Type.


Properties

Type

Specifies how to interpret the Value.

public StardewUI.Layout.LengthType Type { get; set; }
Property Value

LengthType


Value

The dimension value, with behavior determined by Type.

public float Value { get; set; }
Property Value

Single


Methods

Content()

Creates a new Length having Content.

public static StardewUI.Layout.Length Content();
Returns

Length


Parse(ReadOnlySpan<Char>)

Parses a Length from its string representation.

public static StardewUI.Layout.Length Parse(ReadOnlySpan<System.Char> value);
Parameters

value   ReadOnlySpan<Char>
The string representation of the Length.

Returns

Length

The parsed Length.


Parse(string)

Parses a Length from its string representation.

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

value   string
The string representation of the Length.

Returns

Length

The parsed Length.


Percent(float)

Creates a new Length having Percent and the specified percent size.

public static StardewUI.Layout.Length Percent(float value);
Parameters

value   Single
The length in 100-based percent units (e.g. 50.0 is 50%).

Returns

Length


Px(float)

Creates a new Length having Px and the specified pixel size.

public static StardewUI.Layout.Length Px(float value);
Parameters

value   Single
The length in pixels.

Returns

Length


Resolve(float, Func<Single>)

Resolves an actual (pixel) length.

public float Resolve(float availableLength, Func<System.Single> getContentLength);
Parameters

availableLength   Single
The remaining space available.

getContentLength   Func<Single>
A function to get the length of inner content. Will not be called unless the LengthType requires it.

Returns

Single

Remarks

This is a convenience method for common layout scenarios, where content length is relatively simple to compute. Its use is optional; complex widgets can use any means they prefer to compute ContentSize.

The result is intentionally not constrained to availableLength, which is only used for the Stretch method. This allows callers to check if the bounds were exceeded (e.g. to render a scroll bar, ellipsis, etc.) before clamping it.


Stretch()

Creates a new Length having Stretch.

public static StardewUI.Layout.Length Stretch();
Returns

Length


ToString()

public override string ToString();
Returns

string