Table of Contents

Struct CssAngle

Namespace
Egami.Css
Assembly
Egami.Css.dll

An angle, converted to degrees from deg, grad, rad or turn.

public readonly record struct CssAngle : IEquatable<CssAngle>
Implements
Inherited Members

Examples

bool isLength = CssLength.TryParse("1.5em", out CssLength length);       // (1.5, CssUnit.Em)
new CssLength(1, CssUnit.In).TryToPixels(out double px);  // 96
bool isAngle = CssAngle.TryParse("0.25turn", out CssAngle angle);        // 90 degrees
bool isUrl = CssUrl.TryParse("url('pattern.svg#dots')", out CssUrl url);

// calc(), min(), max() and clamp(): the consumer says what each unit is worth.
bool isCalc = CssCalc.TryParse("calc(100% - 2em)", out CssCalc? calc);
double width = calc!.Resolve(unit => unit switch
{
    CssUnit.Percent => 3,   // a percent of a 300px box
    CssUnit.Em => 16,
    CssUnit.Px => 1,
    _ => double.NaN,
});                                                       // 268

Constructors

CssAngle(double)

An angle, converted to degrees from deg, grad, rad or turn.

public CssAngle(double Degrees)

Parameters

Degrees double

The angle in degrees.

Examples

bool isLength = CssLength.TryParse("1.5em", out CssLength length);       // (1.5, CssUnit.Em)
new CssLength(1, CssUnit.In).TryToPixels(out double px);  // 96
bool isAngle = CssAngle.TryParse("0.25turn", out CssAngle angle);        // 90 degrees
bool isUrl = CssUrl.TryParse("url('pattern.svg#dots')", out CssUrl url);

// calc(), min(), max() and clamp(): the consumer says what each unit is worth.
bool isCalc = CssCalc.TryParse("calc(100% - 2em)", out CssCalc? calc);
double width = calc!.Resolve(unit => unit switch
{
    CssUnit.Percent => 3,   // a percent of a 300px box
    CssUnit.Em => 16,
    CssUnit.Px => 1,
    _ => double.NaN,
});                                                       // 268

Properties

Degrees

The angle in degrees.

public double Degrees { get; init; }

Property Value

double

Radians

Gets the angle in radians.

public double Radians { get; }

Property Value

double

Methods

ToString()

Formats the angle as CSS text in degrees.

public override string ToString()

Returns

string

The text.

TryParse(CssComponentValue, bool, out CssAngle)

Parses one component value as an angle.

public static bool TryParse(CssComponentValue value, bool allowNumber, out CssAngle angle)

Parameters

value CssComponentValue

The component value.

allowNumber bool

Whether a unitless number counts as degrees, as in SVG and in the hue of hsl().

angle CssAngle

The angle.

Returns

bool

True when the value is an angle.

TryParse(string, out CssAngle)

Parses an angle with its unit, such as 45deg, 0.25turn or 1.2rad.

public static bool TryParse(string text, out CssAngle angle)

Parameters

text string

The CSS text.

angle CssAngle

The angle.

Returns

bool

True when the text is one angle.