diff options
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/flex.rs | 12 | ||||
| -rw-r--r-- | src/layout/mod.rs | 1 | ||||
| -rw-r--r-- | src/layout/stacked.rs | 6 | ||||
| -rw-r--r-- | src/layout/tree.rs | 19 |
4 files changed, 19 insertions, 19 deletions
diff --git a/src/layout/flex.rs b/src/layout/flex.rs index 3155a13a..bae700ce 100644 --- a/src/layout/flex.rs +++ b/src/layout/flex.rs @@ -67,7 +67,7 @@ impl FlexLayouter { /// Create a new flex layouter. pub fn new(ctx: FlexContext) -> FlexLayouter { let stack = StackLayouter::new(StackContext { - spaces: ctx.spaces, + spaces: ctx.spaces.clone(), axes: ctx.axes, shrink_to_fit: ctx.shrink_to_fit, }); @@ -118,7 +118,7 @@ impl FlexLayouter { } /// Update the axes in use by this flex layouter. - pub fn set_axes(&self, axes: LayoutAxes) { + pub fn set_axes(&mut self, axes: LayoutAxes) { self.units.push(FlexUnit::SetAxes(axes)); } @@ -246,7 +246,7 @@ impl FlexLayouter { Ok(()) } - fn finish_aligned_run(&mut self) -> LayoutResult<()> { + fn finish_aligned_run(&mut self) { let anchor = self.ctx.axes.primary.anchor(self.merged_dimensions.x); let factor = if self.ctx.axes.primary.axis.is_positive() { 1 } else { -1 }; @@ -259,13 +259,11 @@ impl FlexLayouter { self.merged_dimensions.y = crate::size::max(self.merged_dimensions.y, self.run.size.y); self.run.size = Size2D::zero(); - - Ok(()) } /// This layouter's context. - pub fn ctx(&self) -> FlexContext { - self.ctx + pub fn ctx(&self) -> &FlexContext { + &self.ctx } pub fn remaining(&self) -> LayoutResult<LayoutSpaces> { diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 420c90bc..fb63ff86 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1,6 +1,5 @@ //! The core layouting engine. -use std::borrow::Cow; use std::io::{self, Write}; use smallvec::SmallVec; diff --git a/src/layout/stacked.rs b/src/layout/stacked.rs index 77af6f38..8113a4b7 100644 --- a/src/layout/stacked.rs +++ b/src/layout/stacked.rs @@ -93,7 +93,7 @@ impl StackLayouter { } /// Update the axes in use by this stack layouter. - pub fn set_axes(&self, axes: LayoutAxes) { + pub fn set_axes(&mut self, axes: LayoutAxes) { if axes != self.ctx.axes { self.finish_boxes(); self.usable = self.remains(); @@ -171,8 +171,8 @@ impl StackLayouter { } /// This layouter's context. - pub fn ctx(&self) -> StackContext { - self.ctx + pub fn ctx(&self) -> &StackContext { + &self.ctx } /// The (generalized) usable area of the current space. diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 4742de23..11e83209 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -11,21 +11,21 @@ pub fn layout_tree(tree: &SyntaxTree, ctx: LayoutContext) -> LayoutResult<MultiL struct TreeLayouter<'a, 'p> { ctx: LayoutContext<'a, 'p>, flex: FlexLayouter, - style: Cow<'a, TextStyle>, + style: TextStyle, } impl<'a, 'p> TreeLayouter<'a, 'p> { /// Create a new layouter. fn new(ctx: LayoutContext<'a, 'p>) -> TreeLayouter<'a, 'p> { TreeLayouter { - ctx, flex: FlexLayouter::new(FlexContext { flex_spacing: flex_spacing(&ctx.style), - spaces: ctx.spaces, + spaces: ctx.spaces.clone(), axes: ctx.axes, shrink_to_fit: ctx.shrink_to_fit, }), - style: Cow::Borrowed(ctx.style), + style: ctx.style.clone(), + ctx, } } @@ -52,9 +52,9 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { } } - Node::ToggleItalics => self.style.to_mut().toggle_class(FontClass::Italic), - Node::ToggleBold => self.style.to_mut().toggle_class(FontClass::Bold), - Node::ToggleMonospace => self.style.to_mut().toggle_class(FontClass::Monospace), + Node::ToggleItalics => self.style.toggle_class(FontClass::Italic), + Node::ToggleBold => self.style.toggle_class(FontClass::Bold), + Node::ToggleMonospace => self.style.toggle_class(FontClass::Monospace), Node::Func(func) => self.layout_func(func)?, } @@ -85,13 +85,16 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { Command::Add(layout) => self.flex.add(layout), Command::AddMultiple(layouts) => self.flex.add_multiple(layouts), + Command::AddPrimarySpace(space) => self.flex.add_primary_space(space), + Command::AddSecondarySpace(space) => self.flex.add_secondary_space(space)?, + Command::FinishRun => self.flex.add_run_break(), Command::FinishBox => self.flex.finish_box()?, Command::FinishLayout => self.flex.finish_layout(true)?, Command::BreakParagraph => self.break_paragraph()?, - Command::SetStyle(style) => *self.style.to_mut() = style, + Command::SetStyle(style) => self.style = style, Command::SetAxes(axes) => { self.flex.set_axes(axes); self.ctx.axes = axes; |
