Sign in

    mizchi/crater/types does not have a README file

    BoundingRect

    pub(all) struct BoundingRect {
    x : Double
    y : Double
    width : Double
    height : Double
    }

    BoundingRect - the output of layout computation Matches browser's getBoundingClientRect()

    BoundingRect::area

    fn BoundingRect::area(self : BoundingRect) -> Double

    Calculate the area of the bounding rect

    BoundingRect::bottom

    fn BoundingRect::bottom(self : BoundingRect) -> Double

    Get the bottom edge (y + height)

    BoundingRect::new

    fn BoundingRect::new(x : Double, y : Double, width : Double, height : Double) -> BoundingRect

    BoundingRect::right

    fn BoundingRect::right(self : BoundingRect) -> Double

    Get the right edge (x + width)

    BoundingRect::union

    fn BoundingRect::union(self : BoundingRect, other : BoundingRect) -> BoundingRect

    Calculate union of two bounding rects

    BoundingRect::zero

    ClipRect

    pub(all) enum ClipRect {
    Auto
    Rect(Double, Double, Double, Double)
    }

    CSS clip property value clip: rect(top, right, bottom, left) or auto Note: This is a deprecated property, but still widely used for accessibility
    impl Eq for ClipRect
    impl Show for ClipRect

    ClipRect::default

    fn ClipRect::default() -> ClipRect

    Color

    pub(all) struct Color {
    r : Int
    g : Int
    b : Int
    a : Double
    }

    RGBA color with 8-bit channels and alpha
    impl Eq for Color
    impl Show for Color

    Color::black

    fn Color::black() -> Color

    Black color

    Color::is_opaque

    fn Color::is_opaque(self : Color) -> Bool

    Color::is_transparent

    fn Color::is_transparent(self : Color) -> Bool

    Color::rgb

    fn Color::rgb(r : Int, g : Int, b : Int) -> Color

    Color::rgba

    fn Color::rgba(r : Int, g : Int, b : Int, a : Double) -> Color

    Color::to_hex

    fn Color::to_hex(self : Color) -> String

    Convert to CSS hex string (#rrggbb or #rrggbbaa)

    Color::to_rgba_string

    fn Color::to_rgba_string(self : Color) -> String

    Convert to CSS rgba() string

    Color::transparent

    fn Color::transparent() -> Color

    Transparent color (alpha = 0)

    Color::white

    fn Color::white() -> Color

    White color

    Dimension

    pub(all) enum Dimension {
    Length(Double)
    Percent(Double)
    Auto
    MinContent
    MaxContent
    FitContent(Double)
    }

    CSS dimension value: length, percentage, auto, or intrinsic sizing keywords
    impl Eq for Dimension
    impl Show for Dimension

    Dimension::eq_length

    fn Dimension::eq_length(self : Dimension, value : Double) -> Bool

    Check if dimension equals a specific length value

    Dimension::eq_percent

    fn Dimension::eq_percent(self : Dimension, value : Double) -> Bool

    Check if dimension equals a specific percent value

    Dimension::is_definite

    fn Dimension::is_definite(self : Dimension) -> Bool

    Check if dimension is a definite value (Length or Percent)

    Dimension::is_intrinsic

    fn Dimension::is_intrinsic(self : Dimension) -> Bool

    Check if dimension requires intrinsic sizing

    Dimension::resolve

    fn Dimension::resolve(self : Dimension, context : Double) -> Double?

    Resolve dimension to concrete value context: parent size for percentage calculation Note: MinContent, MaxContent, FitContent return None - they need intrinsic size calculation

    Dimension::resolve_or

    fn Dimension::resolve_or(self : Dimension, context : Double, fallback : Double) -> Double

    Resolve with fallback value for Auto

    Dimension::resolve_or_intrinsic

    fn Dimension::resolve_or_intrinsic(self : Dimension, context : Double, fallback : Double) -> Double

    Resolve dimension to length, treating intrinsic keywords as fallback

    Line

    pub struct Line[T] {
    start : T
    end : T
    }

    A line segment with start and end points
    impl Show for Line[T]

    Line::new

    fn[T] Line::new(start : T, end : T) -> Line[T]

    Point

    pub struct Point[T] {
    x : T
    y : T
    }

    2D point with x and y coordinates
    impl Show for Point[T]

    Point::map

    fn[T, U] Point::map(self : Point[T], f : (T) -> U) -> Point[U]

    Point::new

    fn[T] Point::new(x : T, y : T) -> Point[T]

    Point::zero

    fn Point::zero() -> Point[Double]

    Rect

    pub(all) struct Rect[T] {
    left : T
    right : T
    top : T
    bottom : T
    }

    Rectangle with left, right, top, bottom edges Used for margin, padding, border, inset
    impl Show for Rect[T]

    Rect::all

    fn[T] Rect::all(value : T) -> Rect[T]

    Create a rect with all sides set to the same value

    Rect::horizontal_sum

    fn Rect::horizontal_sum(self : Rect[Double]) -> Double

    Sum of left and right (horizontal axis)

    Rect::map

    fn[T, U] Rect::map(self : Rect[T], f : (T) -> U) -> Rect[U]

    Rect::new

    fn[T] Rect::new(left : T, right : T, top : T, bottom : T) -> Rect[T]

    Rect::vertical_sum

    fn Rect::vertical_sum(self : Rect[Double]) -> Double

    Sum of top and bottom (vertical axis)

    Rect::zero

    fn Rect::zero() -> Rect[Double]

    Size

    pub struct Size[T] {
    width : T
    height : T
    }

    2D size with width and height
    impl Show for Size[T]

    Size::map

    fn[T, U] Size::map(self : Size[T], f : (T) -> U) -> Size[U]

    Size::new

    fn[T] Size::new(width : T, height : T) -> Size[T]

    Size::zero

    fn Size::zero() -> Size[Double]

    apply_aspect_ratio_height

    fn apply_aspect_ratio_height(width : Double, aspect_ratio : Double?) -> Double?

    Apply aspect ratio to calculate height from width. Returns height if aspect_ratio is defined, otherwise returns None.

    apply_aspect_ratio_width

    fn apply_aspect_ratio_width(height : Double, aspect_ratio : Double?) -> Double?

    Apply aspect ratio to calculate width from height. Returns width if aspect_ratio is defined, otherwise returns None.

    clamp

    fn clamp(value : Double, min_val : Double, max_val : Double) -> Double

    Clamp a value between min and max CSS spec: min takes precedence over max when they conflict So apply max first (value cannot exceed max), then min (value cannot go below min)

    max

    fn max(a : Double, b : Double) -> Double

    min

    fn min(a : Double, b : Double) -> Double

    resolve_dimensions_with_aspect_ratio

    fn resolve_dimensions_with_aspect_ratio(width : Double?, height : Double?, aspect_ratio : Double?, min_width : Double, max_width : Double, min_height : Double, max_height : Double) -> (Double?, Double?)

    Resolve dimensions with aspect ratio. Given known dimension (width or height), aspect_ratio, and min/max constraints, returns the final (width, height) pair.

    • If width is known, height = width / aspect_ratio
    • If height is known, width = height * aspect_ratio
    • If both are known, aspect_ratio overrides the height
    • Min/max constraints are applied after aspect ratio calculation

    resolve_rect

    fn resolve_rect(rect : Rect[Dimension], parent_width : Double) -> Rect[Double]

    Resolve a Rect[Dimension] (margin/padding/border) to Rect[Double] Uses parent_width for percentage resolution (CSS spec: percentages resolve against width)

    resolve_rect_intrinsic

    fn resolve_rect_intrinsic(rect : Rect[Dimension]) -> Rect[Double]

    Resolve a dimension rect for intrinsic sizing Percentages resolve to 0 in intrinsic sizing contexts

    Source Files