Module calc

Source
Expand description

This module provide a calc CSS function.

§Usage

Most usecases doesn’t need to use Calc type or calc function, because all unit types impl Add, Sub, Mul, Div and the output is Calc type.

You really don’t need to think much about this, because all you need to do to use the calc function is to use +, -, *, / just like normal Rust code

§Examples

use css_style::unit::{px, vh, vw, percent};

let height = vh(20) * 2.0;
assert_eq!("calc(20.00vh * 2)", height.to_string());

let width = 7.5 * vw(50) + px(80) / 2.5;
assert_eq!("calc((7.5 * 50.00vw) + (80.00px / 2.5))", width.to_string());

// you can control the ordering using parentheses
let width = 7.5 * (vw(50) + px(80)) / 2.5;
assert_eq!("calc((7.5 * (50.00vw + 80.00px)) / 2.5)", width.to_string());

// not Div and Mul only accept {number}s
// This doesn't compile:
// let x = px(50) / px(10);
// OR
// let x = px(50) * px(10);

Enums§

Calc
A type that represent a calc CSS function
CalcArgument

Functions§

calc