Skip to content

fix(css): parse all common colour and length forms, fail loudly on the rest #104

Description

@LeadcodeDev

Part of #102 — wave 1.

Mini-spec

Goal: accept every colour and length form an author would reasonably write, and fail loudly on the rest instead of silently rendering black or zero.

Invariants

  • No colour string ever resolves to an unintended SColor::BLACK. Either it parses, or it is surfaced as an error.
  • No length string ever silently resolves to 0px.
  • parse_hex_color keeps its current infallible signature so existing call sites are untouched.

Frozen contract (from #102) — this workstream owns and must expose exactly:

pub fn parse_css_color(input: &str) -> Option<(u8, u8, u8, u8)>

Out of scope: wiring a validation-time error for unresolved colours (L4 consumes this API), gradients.

Acceptance

  • #fff, #FFF, #ffff, #ffffff, #ffffffff all parse.
  • rgb(255,255,255), rgba(255,255,255,0.5), hsl(...), hsla(...) parse, with and without spaces.
  • The CSS named-colour set is supported (currently 11 names are hardcoded at paint_pass.rs:1338-1352).
  • An unresolvable colour is reported, not silently blackened.
  • units.rs:139-141 / 163-165 no longer fold an unparseable length into Px(0.0) without a signal.
  • Unit tests cover each accepted form and at least three rejected ones.

Files: crates/rustmotion-core/src/engine/renderer/colors.rs, crates/rustmotion-core/src/engine/paint_pass.rs, crates/rustmotion-core/src/css/units.rs

Verify

rtk cargo test -p rustmotion-core
rtk cargo build --release

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions