Struct CssAngle
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
DegreesdoubleThe 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
Radians
Gets the angle in radians.
public double Radians { get; }
Property Value
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
valueCssComponentValueThe component value.
allowNumberboolWhether a unitless number counts as degrees, as in SVG and in the hue of
hsl().angleCssAngleThe 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
Returns
- bool
True when the text is one angle.