diff options
| author | cashmere <cashmere@autistici.org> | 2026-07-28 20:14:51 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-07-28 20:14:51 +0200 |
| commit | 32438ce25f69de99d2523b98237f62cfa90890d7 (patch) | |
| tree | 3a712c347dec0889bdea3328b4c817c2d9392b27 /rust/crates/graphics/src/gradient/ast.rs | |
| parent | f5a82152394fde4d8f740f664ab7737b82861618 (diff) | |
| download | opencut-32438ce25f69de99d2523b98237f62cfa90890d7.tar.gz | |
feat: port domain crates to Rust (session 1 complete)
All green: cargo test --workspace (~300 tests, 0 failures).
- timeline (45): placement, resize/ripple, split, snap, retime,
audio separation, scene helpers
- animation (73): bezier solver, channel sampling, keyframe ops,
split/clamp/clone, param definitions
- commands (9): Command trait, BatchCommand, history, 19 concrete
commands, freeze-frame port 1:1
- audio (22): audible collection, range mixing, mastering limiter,
rms/peak buckets
- text (19): cosmic-text layout/measure/raster, backgrounds,
decorations
- graphics (52): full CSS gradient parser, tiny-skia raster,
4 shape definitions
- effect-defs (16): blur definition, registry, pass resolution
- mask-defs (19): all 9 mask renderers via tiny-skia
- renderer (6): node model + scene builder port
- desktop: GPUI projects screen wired to ProjectStore
- scene: factory (web defaults: v32, Main Track, 1920x1080, 30fps)
Diffstat (limited to 'rust/crates/graphics/src/gradient/ast.rs')
| -rw-r--r-- | rust/crates/graphics/src/gradient/ast.rs | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/rust/crates/graphics/src/gradient/ast.rs b/rust/crates/graphics/src/gradient/ast.rs new file mode 100644 index 00000000..d3336fea --- /dev/null +++ b/rust/crates/graphics/src/gradient/ast.rs @@ -0,0 +1,105 @@ +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum GradientKind { + Linear, + RepeatingLinear, + Radial, + RepeatingRadial, +} + +impl GradientKind { + pub fn as_str(&self) -> &'static str { + match self { + GradientKind::Linear => "linear-gradient", + GradientKind::RepeatingLinear => "repeating-linear-gradient", + GradientKind::Radial => "radial-gradient", + GradientKind::RepeatingRadial => "repeating-radial-gradient", + } + } + + pub fn is_linear(&self) -> bool { + matches!(self, GradientKind::Linear | GradientKind::RepeatingLinear) + } +} + +#[derive(Debug, Clone, PartialEq)] +pub enum LinearOrientation { + Directional(String), + Angular(String), +} + +#[derive(Debug, Clone, PartialEq)] +pub enum Distance { + Percent(String), + PositionKeyword(String), + Calc(String), + Px(String), + Em(String), +} + +#[derive(Debug, Clone, PartialEq, Default)] +pub struct Position { + pub x: Option<Distance>, + pub y: Option<Distance>, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ShapeKind { + Circle, + Ellipse, +} + +#[derive(Debug, Clone, PartialEq)] +pub enum ShapeStyle { + Distance(Distance), + ExtentKeyword(String), + Position(Position), +} + +#[derive(Debug, Clone, PartialEq)] +pub struct Shape { + pub value: ShapeKind, + pub style: Option<ShapeStyle>, + pub at: Option<Position>, +} + +#[derive(Debug, Clone, PartialEq)] +pub enum RadialOrientation { + Shape(Shape), + ExtentKeyword { + value: String, + at: Option<Position>, + }, + DefaultRadial { + at: Position, + }, +} + +#[derive(Debug, Clone, PartialEq)] +pub enum GradientOrientation { + Linear(LinearOrientation), + Radial(Vec<RadialOrientation>), +} + +#[derive(Debug, Clone, PartialEq)] +pub enum Color { + Hex(String), + Literal(String), + Rgb(Vec<String>), + Rgba(Vec<String>), + Hsl([String; 3]), + Hsla([String; 4]), + Var(String), +} + +#[derive(Debug, Clone, PartialEq)] +pub struct ColorStop { + pub color: Color, + pub length: Option<Distance>, +} + +#[derive(Debug, Clone, PartialEq)] +pub struct GradientAst { + pub kind: GradientKind, + pub orientation: Option<GradientOrientation>, + pub color_stops: Vec<ColorStop>, +} |
