diff options
| author | Laurenz <laurmaedje@gmail.com> | 2025-07-08 10:52:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-08 08:52:43 +0000 |
| commit | 0a3c6939dd274f40672484695d909c2cc0d0d755 (patch) | |
| tree | 465c10338230b895fdd06c8b3491f1734e8a2932 /crates/typst-library/src/visualize | |
| parent | 36ecbb2c8dccc1a31c43fee1466f1425844d8607 (diff) | |
Rewrite foundations of native elements (#6547)
Diffstat (limited to 'crates/typst-library/src/visualize')
| -rw-r--r-- | crates/typst-library/src/visualize/curve.rs | 1 | ||||
| -rw-r--r-- | crates/typst-library/src/visualize/image/mod.rs | 17 | ||||
| -rw-r--r-- | crates/typst-library/src/visualize/line.rs | 4 | ||||
| -rw-r--r-- | crates/typst-library/src/visualize/path.rs | 1 | ||||
| -rw-r--r-- | crates/typst-library/src/visualize/polygon.rs | 5 | ||||
| -rw-r--r-- | crates/typst-library/src/visualize/shape.rs | 34 |
6 files changed, 18 insertions, 44 deletions
diff --git a/crates/typst-library/src/visualize/curve.rs b/crates/typst-library/src/visualize/curve.rs index 50944a51..587f0d4a 100644 --- a/crates/typst-library/src/visualize/curve.rs +++ b/crates/typst-library/src/visualize/curve.rs @@ -86,7 +86,6 @@ pub struct CurveElem { /// down, up, down, up, down, /// ) /// ``` - #[resolve] #[fold] pub stroke: Smart<Option<Stroke>>, diff --git a/crates/typst-library/src/visualize/image/mod.rs b/crates/typst-library/src/visualize/image/mod.rs index f5109798..48a14f0e 100644 --- a/crates/typst-library/src/visualize/image/mod.rs +++ b/crates/typst-library/src/visualize/image/mod.rs @@ -160,7 +160,6 @@ pub struct ImageElem { Some(Spanned { v: Smart::Auto, .. }) => Some(Smart::Auto), None => None, })] - #[borrowed] pub icc: Smart<Derived<DataSource, Bytes>>, } @@ -199,22 +198,22 @@ impl ImageElem { let source = Derived::new(DataSource::Bytes(bytes), loaded); let mut elem = ImageElem::new(source); if let Some(format) = format { - elem.push_format(format); + elem.format.set(format); } if let Some(width) = width { - elem.push_width(width); + elem.width.set(width); } if let Some(height) = height { - elem.push_height(height); + elem.height.set(height); } if let Some(alt) = alt { - elem.push_alt(alt); + elem.alt.set(alt); } if let Some(fit) = fit { - elem.push_fit(fit); + elem.fit.set(fit); } if let Some(scaling) = scaling { - elem.push_scaling(scaling); + elem.scaling.set(scaling); } Ok(elem.pack().spanned(span)) } @@ -223,8 +222,8 @@ impl ImageElem { impl Show for Packed<ImageElem> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { Ok(BlockElem::single_layouter(self.clone(), engine.routines.layout_image) - .with_width(self.width(styles)) - .with_height(self.height(styles)) + .with_width(self.width.get(styles)) + .with_height(self.height.get(styles)) .pack() .spanned(self.span())) } diff --git a/crates/typst-library/src/visualize/line.rs b/crates/typst-library/src/visualize/line.rs index 689321f1..d058b926 100644 --- a/crates/typst-library/src/visualize/line.rs +++ b/crates/typst-library/src/visualize/line.rs @@ -22,15 +22,12 @@ pub struct LineElem { /// The start point of the line. /// /// Must be an array of exactly two relative lengths. - #[resolve] pub start: Axes<Rel<Length>>, /// The point where the line ends. - #[resolve] pub end: Option<Axes<Rel<Length>>>, /// The line's length. This is only respected if `end` is `{none}`. - #[resolve] #[default(Abs::pt(30.0).into())] pub length: Rel<Length>, @@ -50,7 +47,6 @@ pub struct LineElem { /// line(stroke: (paint: blue, thickness: 1pt, dash: ("dot", 2pt, 4pt, 2pt))), /// ) /// ``` - #[resolve] #[fold] pub stroke: Stroke, } diff --git a/crates/typst-library/src/visualize/path.rs b/crates/typst-library/src/visualize/path.rs index 968146cd..e19e091d 100644 --- a/crates/typst-library/src/visualize/path.rs +++ b/crates/typst-library/src/visualize/path.rs @@ -55,7 +55,6 @@ pub struct PathElem { /// /// Can be set to `{none}` to disable the stroke or to `{auto}` for a /// stroke of `{1pt}` black if and if only if no fill is given. - #[resolve] #[fold] pub stroke: Smart<Option<Stroke>>, diff --git a/crates/typst-library/src/visualize/polygon.rs b/crates/typst-library/src/visualize/polygon.rs index 42b08343..d75e1a65 100644 --- a/crates/typst-library/src/visualize/polygon.rs +++ b/crates/typst-library/src/visualize/polygon.rs @@ -43,7 +43,6 @@ pub struct PolygonElem { /// /// Can be set to `{none}` to disable the stroke or to `{auto}` for a /// stroke of `{1pt}` black if and if only if no fill is given. - #[resolve] #[fold] pub stroke: Smart<Option<Stroke>>, @@ -117,10 +116,10 @@ impl PolygonElem { let mut elem = PolygonElem::new(vertices); if let Some(fill) = fill { - elem.push_fill(fill); + elem.fill.set(fill); } if let Some(stroke) = stroke { - elem.push_stroke(stroke); + elem.stroke.set(stroke); } elem.pack().spanned(span) } diff --git a/crates/typst-library/src/visualize/shape.rs b/crates/typst-library/src/visualize/shape.rs index ff05be2b..f21bf93e 100644 --- a/crates/typst-library/src/visualize/shape.rs +++ b/crates/typst-library/src/visualize/shape.rs @@ -63,7 +63,6 @@ pub struct RectElem { /// rect(stroke: 2pt + red), /// ) /// ``` - #[resolve] #[fold] pub stroke: Smart<Sides<Option<Option<Stroke>>>>, @@ -101,20 +100,17 @@ pub struct RectElem { /// ), /// ) /// ``` - #[resolve] #[fold] pub radius: Corners<Option<Rel<Length>>>, /// How much to pad the rectangle's content. /// See the [box's documentation]($box.inset) for more details. - #[resolve] #[fold] #[default(Sides::splat(Some(Abs::pt(5.0).into())))] pub inset: Sides<Option<Rel<Length>>>, /// How much to expand the rectangle's size without affecting the layout. /// See the [box's documentation]($box.outset) for more details. - #[resolve] #[fold] pub outset: Sides<Option<Rel<Length>>>, @@ -123,15 +119,14 @@ pub struct RectElem { /// When this is omitted, the rectangle takes on a default size of at most /// `{45pt}` by `{30pt}`. #[positional] - #[borrowed] pub body: Option<Content>, } impl Show for Packed<RectElem> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { Ok(BlockElem::single_layouter(self.clone(), engine.routines.layout_rect) - .with_width(self.width(styles)) - .with_height(self.height(styles)) + .with_width(self.width.get(styles)) + .with_height(self.height.get(styles)) .pack() .spanned(self.span())) } @@ -186,26 +181,22 @@ pub struct SquareElem { /// How to stroke the square. See the /// [rectangle's documentation]($rect.stroke) for more details. - #[resolve] #[fold] pub stroke: Smart<Sides<Option<Option<Stroke>>>>, /// How much to round the square's corners. See the /// [rectangle's documentation]($rect.radius) for more details. - #[resolve] #[fold] pub radius: Corners<Option<Rel<Length>>>, /// How much to pad the square's content. See the /// [box's documentation]($box.inset) for more details. - #[resolve] #[fold] #[default(Sides::splat(Some(Abs::pt(5.0).into())))] pub inset: Sides<Option<Rel<Length>>>, /// How much to expand the square's size without affecting the layout. See /// the [box's documentation]($box.outset) for more details. - #[resolve] #[fold] pub outset: Sides<Option<Rel<Length>>>, @@ -215,15 +206,14 @@ pub struct SquareElem { /// When this is omitted, the square takes on a default size of at most /// `{30pt}`. #[positional] - #[borrowed] pub body: Option<Content>, } impl Show for Packed<SquareElem> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { Ok(BlockElem::single_layouter(self.clone(), engine.routines.layout_square) - .with_width(self.width(styles)) - .with_height(self.height(styles)) + .with_width(self.width.get(styles)) + .with_height(self.height.get(styles)) .pack() .spanned(self.span())) } @@ -257,20 +247,17 @@ pub struct EllipseElem { /// How to stroke the ellipse. See the /// [rectangle's documentation]($rect.stroke) for more details. - #[resolve] #[fold] pub stroke: Smart<Option<Stroke>>, /// How much to pad the ellipse's content. See the /// [box's documentation]($box.inset) for more details. - #[resolve] #[fold] #[default(Sides::splat(Some(Abs::pt(5.0).into())))] pub inset: Sides<Option<Rel<Length>>>, /// How much to expand the ellipse's size without affecting the layout. See /// the [box's documentation]($box.outset) for more details. - #[resolve] #[fold] pub outset: Sides<Option<Rel<Length>>>, @@ -279,15 +266,14 @@ pub struct EllipseElem { /// When this is omitted, the ellipse takes on a default size of at most /// `{45pt}` by `{30pt}`. #[positional] - #[borrowed] pub body: Option<Content>, } impl Show for Packed<EllipseElem> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { Ok(BlockElem::single_layouter(self.clone(), engine.routines.layout_ellipse) - .with_width(self.width(styles)) - .with_height(self.height(styles)) + .with_width(self.width.get(styles)) + .with_height(self.height.get(styles)) .pack() .spanned(self.span())) } @@ -347,36 +333,32 @@ pub struct CircleElem { /// How to stroke the circle. See the /// [rectangle's documentation]($rect.stroke) for more details. - #[resolve] #[fold] #[default(Smart::Auto)] pub stroke: Smart<Option<Stroke>>, /// How much to pad the circle's content. See the /// [box's documentation]($box.inset) for more details. - #[resolve] #[fold] #[default(Sides::splat(Some(Abs::pt(5.0).into())))] pub inset: Sides<Option<Rel<Length>>>, /// How much to expand the circle's size without affecting the layout. See /// the [box's documentation]($box.outset) for more details. - #[resolve] #[fold] pub outset: Sides<Option<Rel<Length>>>, /// The content to place into the circle. The circle expands to fit this /// content, keeping the 1-1 aspect ratio. #[positional] - #[borrowed] pub body: Option<Content>, } impl Show for Packed<CircleElem> { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> { Ok(BlockElem::single_layouter(self.clone(), engine.routines.layout_circle) - .with_width(self.width(styles)) - .with_height(self.height(styles)) + .with_width(self.width.get(styles)) + .with_height(self.height.get(styles)) .pack() .spanned(self.span())) } |
