diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-10-16 22:32:40 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-10-16 22:32:40 +0200 |
| commit | e87a34a4d0bf967427e2443f9f48026d09ccd5db (patch) | |
| tree | d1163980613526f9b211c710a9bb52b2893f0839 /src/layout/mod.rs | |
| parent | 58693486f97ddbb34595efa1a81a4e7b1d3204c9 (diff) | |
Rearrange layouting contexts ♻
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index a5dfa0ad..fccbe8c8 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -126,10 +126,22 @@ impl<'a> IntoIterator for &'a MultiLayout { /// The general context for layouting. #[derive(Debug, Copy, Clone)] pub struct LayoutContext<'a, 'p> { + /// The font loader to retrieve fonts from when typesetting text + /// using [`layout_text`]. pub loader: &'a SharedFontLoader<'p>, + /// The style to set text with. This includes sizes and font classes + /// which determine which font from the loaders selection is used. pub style: &'a TextStyle, + /// The alignment to use for the content. + pub alignment: Alignment, + /// The primary space to layout in. pub space: LayoutSpace, - pub extra_space: Option<LayoutSpace>, + /// The additional spaces which are used when the primary space + /// cannot fit the whole content. + pub followup_spaces: Option<LayoutSpace>, + /// Whether to shrink the dimensions to fit the content or the keep the + /// dimensions from the layout spaces. + pub shrink_to_fit: bool, } /// Spacial layouting constraints. @@ -139,11 +151,6 @@ pub struct LayoutSpace { pub dimensions: Size2D, /// Padding that should be respected on each side. pub padding: SizeBox, - /// The alignment to use for the content. - pub alignment: Alignment, - /// Whether to shrink the dimensions to fit the content or the keep the - /// dimensions from the layout space. - pub shrink_to_fit: bool, } impl LayoutSpace { @@ -151,6 +158,14 @@ impl LayoutSpace { pub fn usable(&self) -> Size2D { self.dimensions.unpadded(self.padding) } + + /// A layout without padding and dimensions reduced by the padding. + pub fn usable_space(&self) -> LayoutSpace { + LayoutSpace { + dimensions: self.usable(), + padding: SizeBox::zero(), + } + } } /// Where to align content. |
