diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-07 15:17:13 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-07 15:17:13 +0100 |
| commit | 25b5bd117529cd04bb789e1988eb3a3db8025a0e (patch) | |
| tree | 2fbb4650903123da047a1f1f11a0abda95286e12 /library/src/shared/ext.rs | |
| parent | 6ab7760822ccd24b4ef126d4737d41f1be15fe19 (diff) | |
Fully untyped model
Diffstat (limited to 'library/src/shared/ext.rs')
| -rw-r--r-- | library/src/shared/ext.rs | 94 |
1 files changed, 15 insertions, 79 deletions
diff --git a/library/src/shared/ext.rs b/library/src/shared/ext.rs index 3e600b8d..83e62ac4 100644 --- a/library/src/shared/ext.rs +++ b/library/src/shared/ext.rs @@ -24,49 +24,43 @@ pub trait ContentExt { /// Transform this content's contents without affecting layout. fn moved(self, delta: Axes<Rel<Length>>) -> Self; - - /// Fill the frames resulting from a content. - fn filled(self, fill: Paint) -> Self; - - /// Stroke the frames resulting from a content. - fn stroked(self, stroke: Stroke) -> Self; } impl ContentExt for Content { fn strong(self) -> Self { - crate::text::StrongNode(self).pack() + crate::text::StrongNode::new(self).pack() } fn emph(self) -> Self { - crate::text::EmphNode(self).pack() + crate::text::EmphNode::new(self).pack() } fn underlined(self) -> Self { - crate::text::UnderlineNode(self).pack() + crate::text::UnderlineNode::new(self).pack() } fn linked(self, dest: Destination) -> Self { - self.styled(Meta::DATA, vec![Meta::Link(dest.clone())]) + self.styled(MetaNode::DATA, vec![Meta::Link(dest.clone())]) } fn aligned(self, aligns: Axes<Option<GenAlign>>) -> Self { - self.styled(crate::layout::AlignNode::ALIGNS, aligns) + self.styled(crate::layout::AlignNode::ALIGNMENT, aligns) } fn padded(self, padding: Sides<Rel<Length>>) -> Self { - crate::layout::PadNode { padding, body: self }.pack() + crate::layout::PadNode::new(self) + .with_left(padding.left) + .with_top(padding.top) + .with_right(padding.right) + .with_bottom(padding.bottom) + .pack() } fn moved(self, delta: Axes<Rel<Length>>) -> Self { - crate::layout::MoveNode { delta, body: self }.pack() - } - - fn filled(self, fill: Paint) -> Self { - FillNode { fill, child: self }.pack() - } - - fn stroked(self, stroke: Stroke) -> Self { - StrokeNode { stroke, child: self }.pack() + crate::layout::MoveNode::new(self) + .with_dx(delta.x) + .with_dy(delta.y) + .pack() } } @@ -89,61 +83,3 @@ impl StyleMapExt for StyleMap { ); } } - -/// Fill the frames resulting from content. -#[capable(Layout)] -#[derive(Debug, Hash)] -struct FillNode { - /// How to fill the frames resulting from the `child`. - fill: Paint, - /// The content whose frames should be filled. - child: Content, -} - -#[node] -impl FillNode {} - -impl Layout for FillNode { - fn layout( - &self, - vt: &mut Vt, - styles: StyleChain, - regions: Regions, - ) -> SourceResult<Fragment> { - let mut fragment = self.child.layout(vt, styles, regions)?; - for frame in &mut fragment { - let shape = Geometry::Rect(frame.size()).filled(self.fill); - frame.prepend(Point::zero(), Element::Shape(shape)); - } - Ok(fragment) - } -} - -/// Stroke the frames resulting from content. -#[capable(Layout)] -#[derive(Debug, Hash)] -struct StrokeNode { - /// How to stroke the frames resulting from the `child`. - stroke: Stroke, - /// The content whose frames should be stroked. - child: Content, -} - -#[node] -impl StrokeNode {} - -impl Layout for StrokeNode { - fn layout( - &self, - vt: &mut Vt, - styles: StyleChain, - regions: Regions, - ) -> SourceResult<Fragment> { - let mut fragment = self.child.layout(vt, styles, regions)?; - for frame in &mut fragment { - let shape = Geometry::Rect(frame.size()).stroked(self.stroke); - frame.prepend(Point::zero(), Element::Shape(shape)); - } - Ok(fragment) - } -} |
