summaryrefslogtreecommitdiff
path: root/src/layout/background.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-02-06 13:07:25 +0100
committerGitHub <noreply@github.com>2021-02-06 13:07:25 +0100
commitbfc2f5aefc6c407de0b699b31dafd835fc2c9be3 (patch)
tree67c23ec9df3b9f535faf5fbd443e85d9a7813d37 /src/layout/background.rs
parentdacd7dadc04d4538f1063a86afd676695c7471ab (diff)
parenta6cae89b47246a235ed7b1093747c6f3bcb64da4 (diff)
Merge pull request #17 from typst/rects
Add rectangle function 🎛
Diffstat (limited to 'src/layout/background.rs')
-rw-r--r--src/layout/background.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/layout/background.rs b/src/layout/background.rs
new file mode 100644
index 00000000..07248e02
--- /dev/null
+++ b/src/layout/background.rs
@@ -0,0 +1,37 @@
+use super::*;
+
+/// A node that represents a rectangular box.
+#[derive(Debug, Clone, PartialEq)]
+pub struct NodeBackground {
+ /// The background fill.
+ pub fill: Fill,
+ /// The child node to be filled in.
+ pub child: Node,
+}
+
+impl Layout for NodeBackground {
+ fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Layouted {
+ let mut layouted = self.child.layout(ctx, areas);
+
+ if let Some(first) = layouted.frames_mut().first_mut() {
+ first.elements.insert(
+ 0,
+ (
+ Point::ZERO,
+ Element::Geometry(Geometry {
+ shape: Shape::Rect(first.size),
+ fill: self.fill.clone(),
+ }),
+ ),
+ )
+ }
+
+ layouted
+ }
+}
+
+impl From<NodeBackground> for NodeAny {
+ fn from(background: NodeBackground) -> Self {
+ Self::new(background)
+ }
+}