diff options
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/actions.rs | 8 | ||||
| -rw-r--r-- | src/layout/flex.rs | 6 | ||||
| -rw-r--r-- | src/layout/mod.rs | 27 | ||||
| -rw-r--r-- | src/layout/text.rs | 4 | ||||
| -rw-r--r-- | src/layout/tree.rs | 3 |
5 files changed, 26 insertions, 22 deletions
diff --git a/src/layout/actions.rs b/src/layout/actions.rs index 2528fc85..a8abf9f0 100644 --- a/src/layout/actions.rs +++ b/src/layout/actions.rs @@ -63,7 +63,7 @@ debug_display!(LayoutAction); /// be added at a position, effectively translating all movement actions inside the layout /// by the position. #[derive(Debug, Clone)] -pub struct LayoutActionList { +pub struct LayoutActions { pub origin: Size2D, actions: Vec<LayoutAction>, active_font: (usize, Size), @@ -71,10 +71,10 @@ pub struct LayoutActionList { next_font: Option<(usize, Size)>, } -impl LayoutActionList { +impl LayoutActions { /// Create a new action list. - pub fn new() -> LayoutActionList { - LayoutActionList { + pub fn new() -> LayoutActions { + LayoutActions { actions: vec![], origin: Size2D::zero(), active_font: (std::usize::MAX, Size::zero()), diff --git a/src/layout/flex.rs b/src/layout/flex.rs index 13901968..d984860a 100644 --- a/src/layout/flex.rs +++ b/src/layout/flex.rs @@ -1,5 +1,7 @@ use super::*; +/// The flex layouter first arranges boxes along a primary and if necessary also +/// along a secondary axis. #[derive(Debug, Clone)] pub struct FlexLayouter { axes: LayoutAxes, @@ -22,7 +24,7 @@ enum FlexUnit { #[derive(Debug, Clone)] struct FlexLine { usable: Size, - actions: LayoutActionList, + actions: LayoutActions, combined_dimensions: Size2D, } @@ -30,7 +32,7 @@ impl FlexLine { fn new(usable: Size) -> FlexLine { FlexLine { usable, - actions: LayoutActionList::new(), + actions: LayoutActions::new(), combined_dimensions: Size2D::zero(), } } diff --git a/src/layout/mod.rs b/src/layout/mod.rs index e31d2c17..afdab1ef 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -26,7 +26,7 @@ pub mod layouters { pub use super::text::{layout_text, TextContext}; } -pub use actions::{LayoutAction, LayoutActionList}; +pub use actions::{LayoutAction, LayoutActions}; pub use layouters::*; /// A collection of layouts. @@ -75,7 +75,7 @@ pub struct LayoutSpace { pub padding: SizeBox, /// Whether to expand the dimensions of the resulting layout to the full /// dimensions of this space or to shrink them to fit the content for the - /// vertical and horizontal axis. + /// horizontal and vertical axis. pub expand: (bool, bool), } @@ -324,17 +324,6 @@ impl Alignment { } } -/// The specialized anchor position for an item with the given alignment in a -/// container with a given size along the given axis. -pub fn anchor(axis: Axis, size: Size, alignment: Alignment) -> Size { - use Alignment::*; - match (axis.is_positive(), alignment) { - (true, Origin) | (false, End) => Size::zero(), - (_, Center) => size / 2, - (true, End) | (false, Origin) => size, - } -} - /// Whitespace between boxes with different interaction properties. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum SpacingKind { @@ -368,6 +357,18 @@ impl LastSpacing { } } +/// The specialized anchor position for an item with the given alignment in a +/// container with a given size along the given axis. +#[allow(dead_code)] +fn anchor(axis: Axis, size: Size, alignment: Alignment) -> Size { + use Alignment::*; + match (axis.is_positive(), alignment) { + (true, Origin) | (false, End) => Size::zero(), + (_, Center) => size / 2, + (true, End) | (false, Origin) => size, + } +} + /// Layout components that can be serialized. pub trait Serialize { /// Serialize the data structure into an output writable. diff --git a/src/layout/text.rs b/src/layout/text.rs index 8a0e7cec..b5ff192e 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -26,7 +26,7 @@ pub fn layout_text(text: &str, ctx: TextContext) -> LayoutResult<Layout> { struct TextLayouter<'a, 'p> { ctx: TextContext<'a, 'p>, text: &'a str, - actions: LayoutActionList, + actions: LayoutActions, buffer: String, active_font: usize, width: Size, @@ -39,7 +39,7 @@ impl<'a, 'p> TextLayouter<'a, 'p> { TextLayouter { ctx, text, - actions: LayoutActionList::new(), + actions: LayoutActions::new(), buffer: String::new(), active_font: std::usize::MAX, width: Size::zero(), diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 4370ceab..f36516c1 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -1,6 +1,7 @@ use smallvec::smallvec; use super::*; +/// Layout a syntax tree into a multibox. pub fn layout_tree(tree: &SyntaxTree, ctx: LayoutContext) -> LayoutResult<MultiLayout> { let mut layouter = TreeLayouter::new(ctx); layouter.layout(tree)?; @@ -75,7 +76,7 @@ impl<'a, 'p> TreeLayouter<'a, 'p> { fn layout_func(&mut self, func: &FuncCall) -> LayoutResult<()> { let spaces = self.flex.remaining(); - let commands = func.call.layout(LayoutContext { + let commands = func.0.layout(LayoutContext { loader: self.ctx.loader, style: &self.style, top_level: false, |
