diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-07 18:04:29 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-07 18:04:29 +0200 |
| commit | 4bb6240b401605ef6d905273db07545e14f9a21f (patch) | |
| tree | b01163a5fce3fe62d16abcbdabf37bc373617ff1 /src/library/layout | |
| parent | 1192132dc0a9e991953fd29e93f87c8437a53ea0 (diff) | |
Make `Relative` generic
Diffstat (limited to 'src/library/layout')
| -rw-r--r-- | src/library/layout/columns.rs | 4 | ||||
| -rw-r--r-- | src/library/layout/grid.rs | 4 | ||||
| -rw-r--r-- | src/library/layout/pad.rs | 6 | ||||
| -rw-r--r-- | src/library/layout/page.rs | 14 | ||||
| -rw-r--r-- | src/library/layout/spacing.rs | 2 |
5 files changed, 15 insertions, 15 deletions
diff --git a/src/library/layout/columns.rs b/src/library/layout/columns.rs index 56e55d57..1cb45c37 100644 --- a/src/library/layout/columns.rs +++ b/src/library/layout/columns.rs @@ -14,7 +14,7 @@ pub struct ColumnsNode { #[node] impl ColumnsNode { /// The size of the gutter space between each column. - pub const GUTTER: Relative = Ratio::new(0.04).into(); + pub const GUTTER: Relative<Length> = Ratio::new(0.04).into(); fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { Ok(Content::block(Self { @@ -33,7 +33,7 @@ impl Layout for ColumnsNode { ) -> TypResult<Vec<Arc<Frame>>> { // Separating the infinite space into infinite columns does not make // much sense. - if regions.first.x.is_infinite() { + if !regions.first.x.is_finite() { return self.child.layout(ctx, regions, styles); } diff --git a/src/library/layout/grid.rs b/src/library/layout/grid.rs index ee485bd2..b1e5e54c 100644 --- a/src/library/layout/grid.rs +++ b/src/library/layout/grid.rs @@ -58,7 +58,7 @@ pub enum TrackSizing { Auto, /// A track size specified in absolute terms and relative to the parent's /// size. - Relative(Relative), + Relative(Relative<Length>), /// A track size specified as a fraction of the remaining free space in the /// parent. Fractional(Fraction), @@ -422,7 +422,7 @@ impl<'a> GridLayouter<'a> { fn layout_relative_row( &mut self, ctx: &mut Context, - v: Relative, + v: Relative<Length>, y: usize, ) -> TypResult<()> { let resolved = v.resolve(self.regions.base.y); diff --git a/src/library/layout/pad.rs b/src/library/layout/pad.rs index 1ec5f124..b7470540 100644 --- a/src/library/layout/pad.rs +++ b/src/library/layout/pad.rs @@ -4,7 +4,7 @@ use crate::library::prelude::*; #[derive(Debug, Hash)] pub struct PadNode { /// The amount of padding. - pub padding: Sides<Relative>, + pub padding: Sides<Relative<Length>>, /// The child node whose sides to pad. pub child: LayoutNode, } @@ -54,7 +54,7 @@ impl Layout for PadNode { } /// Shrink a size by padding relative to the size itself. -fn shrink(size: Size, padding: Sides<Relative>) -> Size { +fn shrink(size: Size, padding: Sides<Relative<Length>>) -> Size { size - padding.resolve(size).sum_by_axis() } @@ -77,7 +77,7 @@ fn shrink(size: Size, padding: Sides<Relative>) -> Size { /// <=> w - p.rel * w - p.abs = s /// <=> (1 - p.rel) * w = s + p.abs /// <=> w = (s + p.abs) / (1 - p.rel) -fn grow(size: Size, padding: Sides<Relative>) -> Size { +fn grow(size: Size, padding: Sides<Relative<Length>>) -> Size { size.zip(padding.sum_by_axis()) .map(|(s, p)| (s + p.abs).safe_div(1.0 - p.rel.get())) } diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs index abe1786f..37a87ae2 100644 --- a/src/library/layout/page.rs +++ b/src/library/layout/page.rs @@ -16,13 +16,13 @@ impl PageNode { /// Whether the page is flipped into landscape orientation. pub const FLIPPED: bool = false; /// The left margin. - pub const LEFT: Smart<Relative> = Smart::Auto; + pub const LEFT: Smart<Relative<Length>> = Smart::Auto; /// The right margin. - pub const RIGHT: Smart<Relative> = Smart::Auto; + pub const RIGHT: Smart<Relative<Length>> = Smart::Auto; /// The top margin. - pub const TOP: Smart<Relative> = Smart::Auto; + pub const TOP: Smart<Relative<Length>> = Smart::Auto; /// The bottom margin. - pub const BOTTOM: Smart<Relative> = Smart::Auto; + pub const BOTTOM: Smart<Relative<Length>> = Smart::Auto; /// The page's background color. pub const FILL: Option<Paint> = None; /// How many columns the page has. @@ -85,7 +85,7 @@ impl PageNode { } let mut min = width.min(height); - if min.is_infinite() { + if !min.is_finite() { min = Paper::A4.width(); } @@ -115,7 +115,7 @@ impl PageNode { } // Layout the child. - let regions = Regions::repeat(size, size, size.map(Length::is_finite)); + let regions = Regions::repeat(size, size, size.map(Numeric::is_finite)); let mut frames = child.layout(ctx, ®ions, styles)?; let header = styles.get(Self::HEADER); @@ -133,7 +133,7 @@ impl PageNode { let pos = Point::new(padding.left, y); let w = size.x - padding.left - padding.right; let area = Size::new(w, h); - let pod = Regions::one(area, area, area.map(Length::is_finite)); + let pod = Regions::one(area, area, area.map(Numeric::is_finite)); let sub = Layout::layout(&content, ctx, &pod, styles)?.remove(0); Arc::make_mut(frame).push_frame(pos, sub); } diff --git a/src/library/layout/spacing.rs b/src/library/layout/spacing.rs index 633093e9..e9837ef5 100644 --- a/src/library/layout/spacing.rs +++ b/src/library/layout/spacing.rs @@ -24,7 +24,7 @@ impl VNode { #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum Spacing { /// Spacing specified in absolute terms and relative to the parent's size. - Relative(Relative), + Relative(Relative<Length>), /// Spacing specified as a fraction of the remaining free space in the parent. Fractional(Fraction), } |
