summaryrefslogtreecommitdiff
path: root/src/library/graphics
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-01 16:56:35 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-02 09:18:33 +0100
commit37ac5d966ebaf97ac79c507028cd5b742b510b89 (patch)
tree249d43ff0f8d880cb5d00c236993f8ff0c1f10d8 /src/library/graphics
parentf547c97072881069417acd3b79b08fb7ecf40ba2 (diff)
More dynamic content representation
Diffstat (limited to 'src/library/graphics')
-rw-r--r--src/library/graphics/hide.rs12
-rw-r--r--src/library/graphics/image.rs10
-rw-r--r--src/library/graphics/line.rs8
-rw-r--r--src/library/graphics/shape.rs16
4 files changed, 29 insertions, 17 deletions
diff --git a/src/library/graphics/hide.rs b/src/library/graphics/hide.rs
index 65684272..fafd7421 100644
--- a/src/library/graphics/hide.rs
+++ b/src/library/graphics/hide.rs
@@ -2,12 +2,12 @@ use crate::library::prelude::*;
/// Hide a node without affecting layout.
#[derive(Debug, Hash)]
-pub struct HideNode(pub LayoutNode);
+pub struct HideNode(pub Content);
-#[node]
+#[node(Layout)]
impl HideNode {
fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> {
- Ok(Content::inline(Self(args.expect("body")?)))
+ Ok(Self(args.expect("body")?).pack())
}
}
@@ -18,10 +18,14 @@ impl Layout for HideNode {
regions: &Regions,
styles: StyleChain,
) -> SourceResult<Vec<Frame>> {
- let mut frames = self.0.layout(world, regions, styles)?;
+ let mut frames = self.0.layout_inline(world, regions, styles)?;
for frame in &mut frames {
frame.clear();
}
Ok(frames)
}
+
+ fn level(&self) -> Level {
+ Level::Inline
+ }
}
diff --git a/src/library/graphics/image.rs b/src/library/graphics/image.rs
index 343b4788..9c3a775a 100644
--- a/src/library/graphics/image.rs
+++ b/src/library/graphics/image.rs
@@ -8,7 +8,7 @@ use crate::library::text::TextNode;
#[derive(Debug, Hash)]
pub struct ImageNode(pub Image);
-#[node]
+#[node(Layout)]
impl ImageNode {
/// How the image should adjust itself to a given area.
pub const FIT: ImageFit = ImageFit::Cover;
@@ -32,9 +32,7 @@ impl ImageNode {
let width = args.named("width")?;
let height = args.named("height")?;
- Ok(Content::inline(
- ImageNode(image).pack().sized(Axes::new(width, height)),
- ))
+ Ok(ImageNode(image).pack().boxed(Axes::new(width, height)))
}
}
@@ -97,6 +95,10 @@ impl Layout for ImageNode {
Ok(vec![frame])
}
+
+ fn level(&self) -> Level {
+ Level::Inline
+ }
}
/// How an image should adjust itself to a given area.
diff --git a/src/library/graphics/line.rs b/src/library/graphics/line.rs
index 78878014..c2f89404 100644
--- a/src/library/graphics/line.rs
+++ b/src/library/graphics/line.rs
@@ -9,7 +9,7 @@ pub struct LineNode {
delta: Axes<Rel<Length>>,
}
-#[node]
+#[node(Layout)]
impl LineNode {
/// How to stroke the line.
#[property(resolve, fold)]
@@ -32,7 +32,7 @@ impl LineNode {
}
};
- Ok(Content::inline(Self { origin, delta }))
+ Ok(Self { origin, delta }.pack())
}
}
@@ -65,6 +65,10 @@ impl Layout for LineNode {
Ok(vec![frame])
}
+
+ fn level(&self) -> Level {
+ Level::Inline
+ }
}
castable! {
diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs
index 7a742109..608c9842 100644
--- a/src/library/graphics/shape.rs
+++ b/src/library/graphics/shape.rs
@@ -5,7 +5,7 @@ use crate::library::text::TextNode;
/// Place a node into a sizable and fillable shape.
#[derive(Debug, Hash)]
-pub struct ShapeNode<const S: ShapeKind>(pub Option<LayoutNode>);
+pub struct ShapeNode<const S: ShapeKind>(pub Option<Content>);
/// Place a node into a square.
pub type SquareNode = ShapeNode<SQUARE>;
@@ -19,7 +19,7 @@ pub type CircleNode = ShapeNode<CIRCLE>;
/// Place a node into an ellipse.
pub type EllipseNode = ShapeNode<ELLIPSE>;
-#[node]
+#[node(Layout)]
impl<const S: ShapeKind> ShapeNode<S> {
/// How to fill the shape.
pub const FILL: Option<Paint> = None;
@@ -55,9 +55,7 @@ impl<const S: ShapeKind> ShapeNode<S> {
size => size,
};
- Ok(Content::inline(
- Self(args.eat()?).pack().sized(Axes::new(width, height)),
- ))
+ Ok(Self(args.eat()?).pack().boxed(Axes::new(width, height)))
}
fn set(...) {
@@ -92,7 +90,7 @@ impl<const S: ShapeKind> Layout 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);
- frames = child.layout(world, &pod, styles)?;
+ frames = child.layout_inline(world, &pod, styles)?;
for frame in frames.iter_mut() {
frame.apply_role(Role::GenericBlock);
@@ -112,7 +110,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
pod.first = Size::splat(length);
pod.expand = Axes::splat(true);
- frames = child.layout(world, &pod, styles)?;
+ frames = child.layout_inline(world, &pod, styles)?;
}
} else {
// The default size that a shape takes on if it has no child and
@@ -175,6 +173,10 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> {
Ok(frames)
}
+
+ fn level(&self) -> Level {
+ Level::Inline
+ }
}
/// A category of shape.