From 095fa52be5d7ed135f39553359e0253cfea6b71b Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 17 Nov 2021 23:09:23 +0100 Subject: Placed node --- src/layout/mod.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/layout') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 33502fff..3ac32722 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -19,7 +19,7 @@ use crate::font::FontStore; use crate::frame::Frame; use crate::geom::{Align, Linear, Spec}; use crate::image::ImageStore; -use crate::library::{AlignNode, DocumentNode, SizedNode}; +use crate::library::{AlignNode, DocumentNode, MoveNode, SizedNode}; use crate::Context; /// Layout a document node into a collection of frames. @@ -104,21 +104,27 @@ impl PackedNode { } /// Force a size for this node. - pub fn sized(self, width: Option, height: Option) -> PackedNode { - if width.is_some() || height.is_some() { - Layout::pack(SizedNode { - child: self, - sizing: Spec::new(width, height), - }) + pub fn sized(self, w: Option, h: Option) -> Self { + if w.is_some() || h.is_some() { + SizedNode { child: self, sizing: Spec::new(w, h) }.pack() } else { self } } /// Set alignments for this node. - pub fn aligned(self, x: Option, y: Option) -> PackedNode { + pub fn aligned(self, x: Option, y: Option) -> Self { if x.is_some() || y.is_some() { - Layout::pack(AlignNode { child: self, aligns: Spec::new(x, y) }) + AlignNode { child: self, aligns: Spec::new(x, y) }.pack() + } else { + self + } + } + + /// Move this node's contents without affecting layout. + pub fn moved(self, dx: Option, dy: Option) -> Self { + if dx.is_some() || dy.is_some() { + MoveNode { child: self, offset: Spec::new(dx, dy) }.pack() } else { self } -- cgit v1.2.3