summaryrefslogtreecommitdiff
path: root/src/layout/background.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-20 20:19:30 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-20 20:19:30 +0100
commit898728f260923a91444eb23b522d0abf01a4299b (patch)
tree64fdd3f78e16e6428e765a8e2d99c3cd910bd9df /src/layout/background.rs
parent6cb9fe9064a037224b6560b69b441b72e787fa94 (diff)
Square, circle and ellipse 🔵
Diffstat (limited to 'src/layout/background.rs')
-rw-r--r--src/layout/background.rs29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/layout/background.rs b/src/layout/background.rs
index bb155073..17280a86 100644
--- a/src/layout/background.rs
+++ b/src/layout/background.rs
@@ -3,25 +3,38 @@ use super::*;
/// A node that places a rectangular filled background behind its child.
#[derive(Debug, Clone, PartialEq)]
pub struct BackgroundNode {
+ /// The kind of shape to use as a background.
+ pub shape: BackgroundShape,
/// The background fill.
pub fill: Fill,
/// The child node to be filled.
pub child: Node,
}
+/// The kind of shape to use as a background.
+#[derive(Debug, Clone, PartialEq)]
+pub enum BackgroundShape {
+ Rect,
+ Ellipse,
+}
+
impl Layout for BackgroundNode {
fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Fragment {
- let mut layouted = self.child.layout(ctx, areas);
+ let mut fragment = self.child.layout(ctx, areas);
+
+ for frame in fragment.frames_mut() {
+ let (point, shape) = match self.shape {
+ BackgroundShape::Rect => (Point::ZERO, Shape::Rect(frame.size)),
+ BackgroundShape::Ellipse => {
+ (frame.size.to_point() / 2.0, Shape::Ellipse(frame.size))
+ }
+ };
- for frame in layouted.frames_mut() {
- let element = Element::Geometry(Geometry {
- shape: Shape::Rect(frame.size),
- fill: self.fill,
- });
- frame.elements.insert(0, (Point::ZERO, element));
+ let element = Element::Geometry(Geometry { shape, fill: self.fill });
+ frame.elements.insert(0, (point, element));
}
- layouted
+ fragment
}
}