Table of Contents

Class CssTransformList

Namespace
Egami.Css
Assembly
Egami.Css.dll

A CSS transform value (CSS Transforms 1), or SVG's transform attribute: a list of transform functions applied left to right, as nested coordinate systems.

public sealed class CssTransformList
Inheritance
CssTransformList
Inherited Members

Examples

// A CSS transform list, its matrix, and the functions it holds.
bool isTransform = CssTransformList.TryParse("translate(10px, 50%) rotate(45deg) scale(2)", out CssTransformList? css);
Matrix3x2 matrix = css!.ToMatrix((length, isX) => length.Unit == CssUnit.Percent ? length.Value * (isX ? 2 : 1) : length.Value);

foreach (CssTransformFunction function in css.Functions)
{
    string kind = function switch
    {
        CssTranslateTransform t => $"translate {t.X} {t.Y}",
        CssRotateTransform r => $"rotate {r.Degrees} about ({r.CenterX}, {r.CenterY})",
        CssScaleTransform s => $"scale {s.X} {s.Y}",
        CssSkewTransform k => $"skew {k.XDegrees} {k.YDegrees}",
        CssMatrixTransform m => $"matrix {m.A} {m.B} {m.C} {m.D} {m.E} {m.F}",
        CssUnsupportedTransform u => $"{u.Name} (3D, ignored)",
        _ => "",
    };
}

bool isOrigin = CssTransformOrigin.TryParse("left bottom", out CssTransformOrigin origin); // (0%, 100%, 0)

Properties

Functions

Gets the transform functions, in order; empty for none.

public IReadOnlyList<CssTransformFunction> Functions { get; }

Property Value

IReadOnlyList<CssTransformFunction>

HasUnsupported

Gets whether a 3D function was parsed that ToMatrix(Func<CssLength, bool, double>) ignores.

public bool HasUnsupported { get; }

Property Value

bool

IsNone

Gets whether the list is none (no functions).

public bool IsNone { get; }

Property Value

bool

Methods

ToMatrix()

Combines the functions into one matrix, with lengths converted by their absolute units (a percentage counts as 0).

public Matrix3x2 ToMatrix()

Returns

Matrix3x2

The matrix.

ToMatrix(Func<CssLength, bool, double>)

Combines the functions into one matrix, the first function outermost.

public Matrix3x2 ToMatrix(Func<CssLength, bool, double> resolve)

Parameters

resolve Func<CssLength, bool, double>

Converts a length (possibly a percentage of the reference box) to pixels; the flag is true for the x axis.

Returns

Matrix3x2

The matrix, for row vectors as System.Numerics uses them.

TryParse(IReadOnlyList<CssComponentValue>, out CssTransformList?)

Parses component values as a CSS transform value.

public static bool TryParse(IReadOnlyList<CssComponentValue> values, out CssTransformList? list)

Parameters

values IReadOnlyList<CssComponentValue>

The component values.

list CssTransformList

The transform list.

Returns

bool

True when valid.

TryParse(string, out CssTransformList?)

Parses a CSS transform value, such as translate(10px, 50%) rotate(45deg) or none.

public static bool TryParse(string text, out CssTransformList? list)

Parameters

text string

The CSS text.

list CssTransformList

The transform list.

Returns

bool

True when valid.