From 80e076814dde330fb2136172580f11e939bc6601 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Sat, 6 Feb 2021 12:30:44 +0100 Subject: =?UTF-8?q?Merge=20`rect`=20and=20`box`=20=F0=9F=A6=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/background.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/layout/background.rs (limited to 'src/layout/background.rs') diff --git a/src/layout/background.rs b/src/layout/background.rs new file mode 100644 index 00000000..94d5bf45 --- /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 whose sides to pad. + pub child: NodeFixed, +} + +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 for NodeAny { + fn from(background: NodeBackground) -> Self { + Self::new(background) + } +} -- cgit v1.2.3 From a6cae89b47246a235ed7b1093747c6f3bcb64da4 Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Sat, 6 Feb 2021 12:54:44 +0100 Subject: =?UTF-8?q?Generalize=20child=20of=20NodeBackground=20=F0=9F=8D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/background.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/layout/background.rs') diff --git a/src/layout/background.rs b/src/layout/background.rs index 94d5bf45..07248e02 100644 --- a/src/layout/background.rs +++ b/src/layout/background.rs @@ -5,8 +5,8 @@ use super::*; pub struct NodeBackground { /// The background fill. pub fill: Fill, - /// The child node whose sides to pad. - pub child: NodeFixed, + /// The child node to be filled in. + pub child: Node, } impl Layout for NodeBackground { -- cgit v1.2.3