diff options
Diffstat (limited to 'src/layout/stack.rs')
| -rw-r--r-- | src/layout/stack.rs | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/layout/stack.rs b/src/layout/stack.rs index 9d2540e9..e98be7ed 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -1,65 +1,65 @@ use super::*; -/// A node that stacks and align its children. +/// A node that stacks its children. #[derive(Debug, Clone, PartialEq)] -pub struct Stack { +pub struct NodeStack { /// The `main` and `cross` directions of this stack. /// /// The children are stacked along the `main` direction. The `cross` /// direction is required for aligning the children. - pub flow: Flow, + pub dirs: LayoutDirs, /// How to align this stack in _its_ parent. - pub align: BoxAlign, + pub align: ChildAlign, /// Whether to expand the axes to fill the area or to fit the content. pub expansion: Gen<Expansion>, /// The nodes to be stacked. - pub children: Vec<LayoutNode>, + pub children: Vec<Node>, } -impl Layout for Stack { +impl Layout for NodeStack { fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Layouted { let mut layouter = StackLayouter::new(self, areas.clone()); for child in &self.children { match child.layout(ctx, &layouter.areas) { Layouted::Spacing(spacing) => layouter.push_spacing(spacing), - Layouted::Layout(layout, align) => layouter.push_layout(layout, align), - Layouted::Layouts(layouts, align) => { - for layout in layouts { - layouter.push_layout(layout, align); + Layouted::Frame(frame, align) => layouter.push_frame(frame, align), + Layouted::Frames(frames, align) => { + for frame in frames { + layouter.push_frame(frame, align); } } } } - Layouted::Layouts(layouter.finish(), self.align) + Layouted::Frames(layouter.finish(), self.align) } } -impl From<Stack> for LayoutNode { - fn from(stack: Stack) -> Self { - Self::dynamic(stack) +impl From<NodeStack> for Node { + fn from(stack: NodeStack) -> Self { + Self::any(stack) } } struct StackLayouter<'a> { - stack: &'a Stack, + stack: &'a NodeStack, main: SpecAxis, - flow: Flow, + dirs: LayoutDirs, areas: Areas, - finished: Vec<BoxLayout>, - layouts: Vec<(Length, BoxLayout, BoxAlign)>, + finished: Vec<Frame>, + frames: Vec<(Length, Frame, ChildAlign)>, used: Gen<Length>, ruler: Align, } impl<'a> StackLayouter<'a> { - fn new(stack: &'a Stack, areas: Areas) -> Self { + fn new(stack: &'a NodeStack, areas: Areas) -> Self { Self { stack, - main: stack.flow.main.axis(), - flow: stack.flow, + main: stack.dirs.main.axis(), + dirs: stack.dirs, areas, finished: vec![], - layouts: vec![], + frames: vec![], used: Gen::ZERO, ruler: Align::Start, } @@ -72,23 +72,23 @@ impl<'a> StackLayouter<'a> { self.used.main += capped; } - fn push_layout(&mut self, layout: BoxLayout, align: BoxAlign) { + fn push_frame(&mut self, frame: Frame, align: ChildAlign) { if self.ruler > align.main { self.finish_area(); } - while !self.areas.current.rem.fits(layout.size) { + while !self.areas.current.rem.fits(frame.size) { if self.areas.in_full_last() { // TODO: Diagnose once the necessary spans exist. - let _ = warning!("cannot fit box into any area"); + let _ = warning!("cannot fit frame into any area"); break; } else { self.finish_area(); } } - let size = layout.size.switch(self.flow); - self.layouts.push((self.used.main, layout, align)); + let size = frame.size.switch(self.dirs); + self.frames.push((self.used.main, frame, align)); *self.areas.current.rem.get_mut(self.main) -= size.main; self.used.main += size.main; @@ -98,7 +98,7 @@ impl<'a> StackLayouter<'a> { fn finish_area(&mut self) { let full_size = { - let full = self.areas.current.full.switch(self.flow); + let full = self.areas.current.full.switch(self.dirs); Gen::new( match self.stack.expansion.main { Expansion::Fill => full.main, @@ -111,13 +111,13 @@ impl<'a> StackLayouter<'a> { ) }; - let mut output = BoxLayout::new(full_size.switch(self.flow).to_size()); + let mut output = Frame::new(full_size.switch(self.dirs).to_size()); - for (before, layout, align) in std::mem::take(&mut self.layouts) { - let child_size = layout.size.switch(self.flow); + for (before, frame, align) in std::mem::take(&mut self.frames) { + let child_size = frame.size.switch(self.dirs); // Align along the main axis. - let main = align.main.resolve(if self.flow.main.is_positive() { + let main = align.main.resolve(if self.dirs.main.is_positive() { let after_with_self = self.used.main - before; before .. full_size.main - after_with_self } else { @@ -127,14 +127,14 @@ impl<'a> StackLayouter<'a> { }); // Align along the cross axis. - let cross = align.cross.resolve(if self.flow.cross.is_positive() { + let cross = align.cross.resolve(if self.dirs.cross.is_positive() { Length::ZERO .. full_size.cross - child_size.cross } else { full_size.cross - child_size.cross .. Length::ZERO }); - let pos = Gen::new(main, cross).switch(self.flow).to_point(); - output.push_layout(pos, layout); + let pos = Gen::new(main, cross).switch(self.dirs).to_point(); + output.push_frame(pos, frame); } self.finished.push(output); @@ -144,7 +144,7 @@ impl<'a> StackLayouter<'a> { self.ruler = Align::Start; } - fn finish(mut self) -> Vec<BoxLayout> { + fn finish(mut self) -> Vec<Frame> { self.finish_area(); self.finished } |
