diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-28 12:40:16 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-28 12:40:16 +0100 |
| commit | 989d170dc7318ca3cbaa5b76760eb14f4e6a8605 (patch) | |
| tree | 0a486ddb4d339b8a43313f7c6e18b9595b8fd955 /library/src/graphics | |
| parent | 7caf98fe42797eab59a39ef71071030c9790245a (diff) | |
Fragments
Diffstat (limited to 'library/src/graphics')
| -rw-r--r-- | library/src/graphics/hide.rs | 18 | ||||
| -rw-r--r-- | library/src/graphics/image.rs | 12 | ||||
| -rw-r--r-- | library/src/graphics/line.rs | 14 | ||||
| -rw-r--r-- | library/src/graphics/shape.rs | 16 |
4 files changed, 35 insertions, 25 deletions
diff --git a/library/src/graphics/hide.rs b/library/src/graphics/hide.rs index 3a21c2c7..64cbee64 100644 --- a/library/src/graphics/hide.rs +++ b/library/src/graphics/hide.rs @@ -4,22 +4,26 @@ use crate::prelude::*; #[derive(Debug, Hash)] pub struct HideNode(pub Content); -#[node(LayoutInline)] +#[node(Layout, Inline)] impl HideNode { fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> { Ok(Self(args.expect("body")?).pack()) } } -impl LayoutInline for HideNode { - fn layout_inline( +impl Layout for HideNode { + fn layout( &self, world: Tracked<dyn World>, styles: StyleChain, regions: &Regions, - ) -> SourceResult<Frame> { - let mut frame = self.0.layout_inline(world, styles, regions)?; - frame.clear(); - Ok(frame) + ) -> SourceResult<Fragment> { + let mut fragment = self.0.layout(world, styles, regions)?; + for frame in &mut fragment { + frame.clear(); + } + Ok(fragment) } } + +impl Inline for HideNode {} diff --git a/library/src/graphics/image.rs b/library/src/graphics/image.rs index de3384df..2c58496c 100644 --- a/library/src/graphics/image.rs +++ b/library/src/graphics/image.rs @@ -9,7 +9,7 @@ use crate::text::LinkNode; #[derive(Debug, Hash)] pub struct ImageNode(pub Image); -#[node(LayoutInline)] +#[node(Layout, Inline)] impl ImageNode { /// How the image should adjust itself to a given area. pub const FIT: ImageFit = ImageFit::Cover; @@ -37,13 +37,13 @@ impl ImageNode { } } -impl LayoutInline for ImageNode { - fn layout_inline( +impl Layout for ImageNode { + fn layout( &self, _: Tracked<dyn World>, styles: StyleChain, regions: &Regions, - ) -> SourceResult<Frame> { + ) -> SourceResult<Fragment> { let pxw = self.0.width() as f64; let pxh = self.0.height() as f64; let px_ratio = pxw / pxh; @@ -94,10 +94,12 @@ impl LayoutInline for ImageNode { frame.link(url.clone()); } - Ok(frame) + Ok(Fragment::frame(frame)) } } +impl Inline for ImageNode {} + /// How an image should adjust itself to a given area. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum ImageFit { diff --git a/library/src/graphics/line.rs b/library/src/graphics/line.rs index 11f0be32..8acf5bb6 100644 --- a/library/src/graphics/line.rs +++ b/library/src/graphics/line.rs @@ -9,7 +9,7 @@ pub struct LineNode { delta: Axes<Rel<Length>>, } -#[node(LayoutInline)] +#[node(Layout, Inline)] impl LineNode { /// How to stroke the line. #[property(resolve, fold)] @@ -36,13 +36,13 @@ impl LineNode { } } -impl LayoutInline for LineNode { - fn layout_inline( +impl Layout for LineNode { + fn layout( &self, _: Tracked<dyn World>, styles: StyleChain, regions: &Regions, - ) -> SourceResult<Frame> { + ) -> SourceResult<Fragment> { let stroke = styles.get(Self::STROKE).unwrap_or_default(); let origin = self @@ -58,11 +58,13 @@ impl LayoutInline for LineNode { .map(|(l, b)| l.relative_to(b)); let target = regions.expand.select(regions.first, Size::zero()); - let mut frame = Frame::new(target); + let mut frame = Frame::new(target); let shape = Geometry::Line(delta.to_point()).stroked(stroke); frame.push(origin.to_point(), Element::Shape(shape)); - Ok(frame) + Ok(Fragment::frame(frame)) } } + +impl Inline for LineNode {} diff --git a/library/src/graphics/shape.rs b/library/src/graphics/shape.rs index 4c9fec07..114182e5 100644 --- a/library/src/graphics/shape.rs +++ b/library/src/graphics/shape.rs @@ -19,7 +19,7 @@ pub type CircleNode = ShapeNode<CIRCLE>; /// A ellipse with optional content. pub type EllipseNode = ShapeNode<ELLIPSE>; -#[node(LayoutInline)] +#[node(Layout, Inline)] impl<const S: ShapeKind> ShapeNode<S> { /// How to fill the shape. pub const FILL: Option<Paint> = None; @@ -72,13 +72,13 @@ impl<const S: ShapeKind> ShapeNode<S> { } } -impl<const S: ShapeKind> LayoutInline for ShapeNode<S> { - fn layout_inline( +impl<const S: ShapeKind> Layout for ShapeNode<S> { + fn layout( &self, world: Tracked<dyn World>, styles: StyleChain, regions: &Regions, - ) -> SourceResult<Frame> { + ) -> SourceResult<Fragment> { let mut frame; if let Some(child) = &self.0 { let mut inset = styles.get(Self::INSET); @@ -90,7 +90,7 @@ impl<const S: ShapeKind> LayoutInline for ShapeNode<S> { let child = child.clone().padded(inset.map(|side| side.map(Length::from))); let mut pod = Regions::one(regions.first, regions.base, regions.expand); - frame = child.layout_inline(world, styles, &pod)?; + frame = child.layout(world, styles, &pod)?.into_frame(); // Relayout with full expansion into square region to make sure // the result is really a square or circle. @@ -106,7 +106,7 @@ impl<const S: ShapeKind> LayoutInline for ShapeNode<S> { pod.first = Size::splat(length); pod.expand = Axes::splat(true); - frame = child.layout_inline(world, styles, &pod)?; + frame = child.layout(world, styles, &pod)?.into_frame(); } } else { // The default size that a shape takes on if it has no child and @@ -165,10 +165,12 @@ impl<const S: ShapeKind> LayoutInline for ShapeNode<S> { frame.link(url.clone()); } - Ok(frame) + Ok(Fragment::frame(frame)) } } +impl<const S: ShapeKind> Inline for ShapeNode<S> {} + /// A category of shape. pub type ShapeKind = usize; |
