diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-02-28 15:50:48 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-02-28 23:54:34 +0100 |
| commit | 3ca5b238238e1128aa7bbfbd5db9e632045d8600 (patch) | |
| tree | 2471f4b340a15695b7f4d518c0b39fabaea676c4 /src/library/place.rs | |
| parent | b63c21c91d99a1554a019dc275f955d3e6a34271 (diff) | |
Reorganize library
Diffstat (limited to 'src/library/place.rs')
| -rw-r--r-- | src/library/place.rs | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/src/library/place.rs b/src/library/place.rs deleted file mode 100644 index 00e72dfb..00000000 --- a/src/library/place.rs +++ /dev/null @@ -1,61 +0,0 @@ -//! Absolute placement of nodes. - -use super::prelude::*; -use super::AlignNode; - -/// Place a node at an absolute position. -#[derive(Debug, Hash)] -pub struct PlaceNode(pub LayoutNode); - -#[class] -impl PlaceNode { - fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> { - let aligns = args.find()?.unwrap_or(Spec::with_x(Some(Align::Left))); - let tx = args.named("dx")?.unwrap_or_default(); - let ty = args.named("dy")?.unwrap_or_default(); - let body: LayoutNode = args.expect("body")?; - Ok(Template::block(Self( - body.moved(Point::new(tx, ty)).aligned(aligns), - ))) - } -} - -impl Layout for PlaceNode { - fn layout( - &self, - ctx: &mut Context, - regions: &Regions, - styles: StyleChain, - ) -> TypResult<Vec<Arc<Frame>>> { - let out_of_flow = self.out_of_flow(); - - // The pod is the base area of the region because for absolute - // placement we don't really care about the already used area. - let pod = { - let finite = regions.base.map(Length::is_finite); - let expand = finite & (regions.expand | out_of_flow); - Regions::one(regions.base, regions.base, expand) - }; - - let mut frames = self.0.layout(ctx, &pod, styles)?; - - // If expansion is off, zero all sizes so that we don't take up any - // space in our parent. Otherwise, respect the expand settings. - let frame = &mut frames[0]; - let target = regions.expand.select(regions.first, Size::zero()); - Arc::make_mut(frame).resize(target, Align::LEFT_TOP); - - Ok(frames) - } -} - -impl PlaceNode { - /// Whether this node wants to be placed relative to its its parent's base - /// origin. Instead of relative to the parent's current flow/cursor - /// position. - pub fn out_of_flow(&self) -> bool { - self.0 - .downcast::<AlignNode>() - .map_or(false, |node| node.aligns.y.is_some()) - } -} |
