summaryrefslogtreecommitdiff
path: root/library/src/shared
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-07 15:17:13 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-07 15:17:13 +0100
commit25b5bd117529cd04bb789e1988eb3a3db8025a0e (patch)
tree2fbb4650903123da047a1f1f11a0abda95286e12 /library/src/shared
parent6ab7760822ccd24b4ef126d4737d41f1be15fe19 (diff)
Fully untyped model
Diffstat (limited to 'library/src/shared')
-rw-r--r--library/src/shared/behave.rs5
-rw-r--r--library/src/shared/ext.rs94
2 files changed, 17 insertions, 82 deletions
diff --git a/library/src/shared/behave.rs b/library/src/shared/behave.rs
index ec8fade9..74c4d151 100644
--- a/library/src/shared/behave.rs
+++ b/library/src/shared/behave.rs
@@ -1,9 +1,8 @@
//! Node interaction.
-use typst::model::{capability, Content, StyleChain, StyleVec, StyleVecBuilder};
+use typst::model::{Content, StyleChain, StyleVec, StyleVecBuilder};
/// How a node interacts with other nodes.
-#[capability]
pub trait Behave {
/// The node's interaction behaviour.
fn behaviour(&self) -> Behaviour;
@@ -23,7 +22,7 @@ pub enum Behaviour {
/// after it. Furthermore, per consecutive run of weak nodes, only one
/// survives: The one with the lowest weakness level (or the larger one if
/// there is a tie).
- Weak(u8),
+ Weak(usize),
/// A node that enables adjacent weak nodes to exist. The default.
Supportive,
/// A node that destroys adjacent weak nodes.
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)
- }
-}