summaryrefslogtreecommitdiff
path: root/src/layout/background.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-10-13 18:33:10 +0200
committerLaurenz <laurmaedje@gmail.com>2021-10-23 20:22:47 +0200
commit1e74f7c407e42174b631cb7477f3c88252da7e25 (patch)
tree53c0510b6503c434c9ba470b188d9e737ce1c3cf /src/layout/background.rs
parent5f4dde0a6b32c7620b29af30f69591cf3995af9b (diff)
New `ShapeNode`
Replaces `BackgroundNode` and `FixedNode`
Diffstat (limited to 'src/layout/background.rs')
-rw-r--r--src/layout/background.rs55
1 files changed, 0 insertions, 55 deletions
diff --git a/src/layout/background.rs b/src/layout/background.rs
deleted file mode 100644
index 09282260..00000000
--- a/src/layout/background.rs
+++ /dev/null
@@ -1,55 +0,0 @@
-use super::*;
-
-/// A node that places a rectangular filled background behind its child.
-#[derive(Debug)]
-#[cfg_attr(feature = "layout-cache", derive(Hash))]
-pub struct BackgroundNode {
- /// The kind of shape to use as a background.
- pub shape: BackgroundShape,
- /// Background color / texture.
- pub fill: Paint,
- /// The child node to be filled.
- pub child: LayoutNode,
-}
-
-/// The kind of shape to use as a background.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
-pub enum BackgroundShape {
- Rect,
- Ellipse,
-}
-
-impl Layout for BackgroundNode {
- fn layout(
- &self,
- ctx: &mut LayoutContext,
- regions: &Regions,
- ) -> Vec<Constrained<Rc<Frame>>> {
- let mut frames = self.child.layout(ctx, regions);
-
- for Constrained { item: frame, .. } in &mut frames {
- let (point, geometry) = match self.shape {
- BackgroundShape::Rect => (Point::zero(), Geometry::Rect(frame.size)),
- BackgroundShape::Ellipse => {
- (frame.size.to_point() / 2.0, Geometry::Ellipse(frame.size))
- }
- };
-
- // Create a new frame with the background geometry and the child's
- // frame.
- let empty = Frame::new(frame.size, frame.baseline);
- let prev = std::mem::replace(frame, Rc::new(empty));
- let new = Rc::make_mut(frame);
- new.push(point, Element::Geometry(geometry, self.fill));
- new.push_frame(Point::zero(), prev);
- }
-
- frames
- }
-}
-
-impl From<BackgroundNode> for LayoutNode {
- fn from(background: BackgroundNode) -> Self {
- Self::new(background)
- }
-}