logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Struct LayoutSize

    Describes how much space a child takes along its container's main axis, expressed in the same vocabulary a web designer uses in CSS: auto, 260px, 1fr, 30%, with optional min/max clamps (CSS min-/max-width|height / grid minmax()).

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetType()
    Namespace: Serenity.Ui.Domain.Entities
    Assembly: Serenity.Ui.Domain.dll
    Syntax
    public struct LayoutSize
    Remarks

    The translation of these units onto Unity layout primitives is an implementation detail of the infrastructure layer (see the Unity layout builder); authors only ever think in CSS terms.

    Fields

    HasMax

    Whether Max should be applied as an upper clamp (in pixels).

    Declaration
    public bool HasMax
    Field Value
    Type Description
    bool

    HasMin

    Whether Min should be applied as a lower clamp (in pixels).

    Declaration
    public bool HasMin
    Field Value
    Type Description
    bool

    Max

    Maximum size in pixels when HasMax is true.

    Declaration
    public float Max
    Field Value
    Type Description
    float

    Min

    Minimum size in pixels when HasMin is true.

    Declaration
    public float Min
    Field Value
    Type Description
    float

    Unit

    The unit that gives Value its meaning.

    Declaration
    public LayoutSizeUnit Unit
    Field Value
    Type Description
    LayoutSizeUnit

    Value

    The magnitude, interpreted by Unit: pixels for FIXED, a weight for FLEX, a 0..100 percentage for PERCENT, and ignored for AUTO.

    Declaration
    public float Value
    Field Value
    Type Description
    float

    Methods

    Auto()

    A content-sized child (CSS auto).

    Declaration
    public static LayoutSize Auto()
    Returns
    Type Description
    LayoutSize

    Clamp(float)

    Applies the configured Min/Max clamps to a resolved pixel size.

    Declaration
    public float Clamp(float resolvedPixels)
    Parameters
    Type Name Description
    float resolvedPixels

    A concrete pixel size to clamp.

    Returns
    Type Description
    float

    The clamped pixel size.

    Fixed(float)

    A child of exactly pixels px (CSS fixed width/height).

    Declaration
    public static LayoutSize Fixed(float pixels)
    Parameters
    Type Name Description
    float pixels
    Returns
    Type Description
    LayoutSize

    Flex(float)

    A child taking weight share of leftover space (CSS fr).

    Declaration
    public static LayoutSize Flex(float weight = 1)
    Parameters
    Type Name Description
    float weight
    Returns
    Type Description
    LayoutSize

    Parse(string)

    Parses a single CSS-style token into a LayoutSize: auto, 260px, 1fr, or 30%. A bare number is treated as pixels. Useful for grid track lists and programmatic authoring; min/max are not part of the token grammar.

    Declaration
    public static LayoutSize Parse(string token)
    Parameters
    Type Name Description
    string token

    The CSS-style size token to parse.

    Returns
    Type Description
    LayoutSize

    The parsed LayoutSize.

    Exceptions
    Type Condition
    FormatException

    Thrown when the token cannot be parsed.

    Percent(float)

    A child sized to percent (0..100) of the parent's main axis.

    Declaration
    public static LayoutSize Percent(float percent)
    Parameters
    Type Name Description
    float percent
    Returns
    Type Description
    LayoutSize

    ToString()

    Returns a CSS-like representation, e.g. 260px, 1fr, 30%, auto.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string
    Overrides
    ValueType.ToString()

    WithMax(float)

    Returns a copy of this size with a maximum-pixels clamp applied.

    Declaration
    public LayoutSize WithMax(float max)
    Parameters
    Type Name Description
    float max
    Returns
    Type Description
    LayoutSize

    WithMin(float)

    Returns a copy of this size with a minimum-pixels clamp applied.

    Declaration
    public LayoutSize WithMin(float min)
    Parameters
    Type Name Description
    float min
    Returns
    Type Description
    LayoutSize
    In this article
    © 2026 Serenity. All Rights Reserved