style::values::specified::calc

Type Alias CalcNode

Source
pub type CalcNode = GenericCalcNode<Leaf>;
Expand description

A calc node representation for specified values.

Aliased Type§

enum CalcNode {
Show 14 variants Leaf(Leaf), Negate(Box<GenericCalcNode<Leaf>>), Invert(Box<GenericCalcNode<Leaf>>), Sum(OwnedSlice<GenericCalcNode<Leaf>>), Product(OwnedSlice<GenericCalcNode<Leaf>>), MinMax(OwnedSlice<GenericCalcNode<Leaf>>, MinMaxOp), Clamp { min: Box<GenericCalcNode<Leaf>>, center: Box<GenericCalcNode<Leaf>>, max: Box<GenericCalcNode<Leaf>>, }, Round { strategy: RoundingStrategy, value: Box<GenericCalcNode<Leaf>>, step: Box<GenericCalcNode<Leaf>>, }, ModRem { dividend: Box<GenericCalcNode<Leaf>>, divisor: Box<GenericCalcNode<Leaf>>, op: ModRemOp, }, Hypot(OwnedSlice<GenericCalcNode<Leaf>>), Abs(Box<GenericCalcNode<Leaf>>), Sign(Box<GenericCalcNode<Leaf>>), Anchor(Box<GenericAnchorFunction<Box<GenericCalcNode<Leaf>>, Box<GenericCalcNode<Leaf>>>>), AnchorSize(Box<GenericAnchorSizeFunction<Box<GenericCalcNode<Leaf>>>>),
}

Variants§

§

Leaf(Leaf)

A leaf node.

§

Negate(Box<GenericCalcNode<Leaf>>)

A node that negates its child, e.g. Negate(1) == -1.

§

Invert(Box<GenericCalcNode<Leaf>>)

A node that inverts its child, e.g. Invert(10) == 1 / 10 == 0.1. The child must always resolve to a number unit.

§

Sum(OwnedSlice<GenericCalcNode<Leaf>>)

A sum node, representing a + b + c where a, b, and c are the arguments.

§

Product(OwnedSlice<GenericCalcNode<Leaf>>)

A product node, representing a * b * c where a, b, and c are the arguments.

§

MinMax(OwnedSlice<GenericCalcNode<Leaf>>, MinMaxOp)

A min or max function.

§

Clamp

A clamp() function.

Fields

§min: Box<GenericCalcNode<Leaf>>

The minimum value.

§center: Box<GenericCalcNode<Leaf>>

The central value.

§max: Box<GenericCalcNode<Leaf>>

The maximum value.

§

Round

A round() function.

Fields

§strategy: RoundingStrategy

The rounding strategy.

§value: Box<GenericCalcNode<Leaf>>

The value to round.

§step: Box<GenericCalcNode<Leaf>>

The step value.

§

ModRem

A mod() or rem() function.

Fields

§dividend: Box<GenericCalcNode<Leaf>>

The dividend calculation.

§divisor: Box<GenericCalcNode<Leaf>>

The divisor calculation.

§op: ModRemOp

Is the function mod or rem?

§

Hypot(OwnedSlice<GenericCalcNode<Leaf>>)

A hypot() function

§

Abs(Box<GenericCalcNode<Leaf>>)

An abs() function.

§

Sign(Box<GenericCalcNode<Leaf>>)

A sign() function.

§

Anchor(Box<GenericAnchorFunction<Box<GenericCalcNode<Leaf>>, Box<GenericCalcNode<Leaf>>>>)

An anchor() function.

§

AnchorSize(Box<GenericAnchorSizeFunction<Box<GenericCalcNode<Leaf>>>>)

An anchor-size() function.

Implementations§

Source§

impl CalcNode

Source

fn parse_one<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed: AllowParse, ) -> Result<Self, ParseError<'i>>

Tries to parse a single element in the expression, that is, a <length>, <angle>, <time>, <percentage>, <resolution>, etc.

May return a “complex” CalcNode, in the presence of a parenthesized expression, for example.

Source

pub fn parse<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, allowed: AllowParse, ) -> Result<Self, ParseError<'i>>

Parse a top-level calc expression, with all nested sub-expressions.

This is in charge of parsing, for example, 2 + 3 * 100%.

Source

fn parse_angle_argument<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, ) -> Result<CSSFloat, ParseError<'i>>

Source

fn parse_number_argument<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, ) -> Result<CSSFloat, ParseError<'i>>

Source

fn parse_argument<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed: AllowParse, ) -> Result<Self, ParseError<'i>>

Source

fn parse_product<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, allowed: AllowParse, ) -> Result<Self, ParseError<'i>>

Parse a top-level calc expression, and all the products that may follow, and stop as soon as a non-product expression is found.

This should parse correctly:

  • 2
  • 2 * 2
  • 2 * 2 + 2 (but will leave the + 2 unparsed).
Source

fn try_resolve<'i, 't, F>( input: &Parser<'i, 't>, closure: F, ) -> Result<CSSFloat, ParseError<'i>>
where F: FnOnce() -> Result<CSSFloat, ()>,

Source

pub fn into_length_or_percentage( self, clamping_mode: AllowedNumericType, ) -> Result<CalcLengthPercentage, ()>

Tries to simplify this expression into a <length> or <percentage> value.

Source

fn to_time(&self, clamping_mode: Option<AllowedNumericType>) -> Result<Time, ()>

Tries to simplify this expression into a <time> value.

Source

fn to_resolution(&self) -> Result<Resolution, ()>

Tries to simplify the expression into a <resolution> value.

Source

fn to_angle(&self) -> Result<Angle, ()>

Tries to simplify this expression into an Angle value.

Source

fn to_number(&self) -> Result<CSSFloat, ()>

Tries to simplify this expression into a <number> value.

Source

fn to_percentage(&self) -> Result<CSSFloat, ()>

Tries to simplify this expression into a <percentage> value.

Source

pub fn math_function<'i>( _: &ParserContext<'_>, name: &CowRcStr<'i>, location: SourceLocation, ) -> Result<MathFunction, ParseError<'i>>

Given a function name, and the location from where the token came from, return a mathematical function corresponding to that name or an error.

Source

pub fn parse_integer<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CSSInteger, ParseError<'i>>

Convenience parsing function for integers.

Source

pub fn parse_length_or_percentage<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, allow_anchor: AllowAnchorPositioningFunctions, ) -> Result<CalcLengthPercentage, ParseError<'i>>

Convenience parsing function for <length> | <percentage>, and, optionally, anchor().

Source

pub fn parse_percentage<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CSSFloat, ParseError<'i>>

Convenience parsing function for percentages.

Source

pub fn parse_length<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, ) -> Result<CalcLengthPercentage, ParseError<'i>>

Convenience parsing function for <length>.

Source

pub fn parse_number<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<CSSFloat, ParseError<'i>>

Convenience parsing function for <number>.

Source

pub fn parse_angle<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<Angle, ParseError<'i>>

Convenience parsing function for <angle>.

Source

pub fn parse_time<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType, function: MathFunction, ) -> Result<Time, ParseError<'i>>

Convenience parsing function for <time>.

Source

pub fn parse_resolution<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, function: MathFunction, ) -> Result<Resolution, ParseError<'i>>

Convenience parsing function for <resolution>.