From 3ffa7393f0632d9ee5dd9c821685a1a033d5c0ab Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 12 Feb 2023 18:58:39 +0100 Subject: Make all nodes block-level --- src/doc.rs | 6 ++++++ src/export/pdf/page.rs | 1 + src/export/render.rs | 1 + src/geom/axes.rs | 20 ++++++++++++++++++++ src/geom/point.rs | 15 +++++++++++++++ src/geom/smart.rs | 10 ++++++++++ 6 files changed, 53 insertions(+) (limited to 'src') diff --git a/src/doc.rs b/src/doc.rs index 988520c5..47bdb23d 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -267,6 +267,10 @@ impl Frame { /// Attach the metadata from this style chain to the frame. pub fn meta(&mut self, styles: StyleChain) { for meta in styles.get(Meta::DATA) { + if matches!(meta, Meta::Hidden) { + self.clear(); + break; + } self.push(Point::zero(), Element::Meta(meta, self.size)); } } @@ -533,6 +537,8 @@ pub enum Meta { /// An identifiable piece of content that produces something within the /// area this metadata is attached to. Node(StableId, Content), + /// Indicates that the content is hidden. + Hidden, } #[node] diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs index ef6c0ccc..1131f760 100644 --- a/src/export/pdf/page.rs +++ b/src/export/pdf/page.rs @@ -288,6 +288,7 @@ fn write_frame(ctx: &mut PageContext, frame: &Frame) { Element::Meta(meta, size) => match meta { Meta::Link(dest) => write_link(ctx, pos, dest, *size), Meta::Node(_, _) => {} + Meta::Hidden => {} }, } } diff --git a/src/export/render.rs b/src/export/render.rs index b018608c..fcf7458a 100644 --- a/src/export/render.rs +++ b/src/export/render.rs @@ -61,6 +61,7 @@ fn render_frame( Element::Meta(meta, _) => match meta { Meta::Link(_) => {} Meta::Node(_, _) => {} + Meta::Hidden => {} }, } } diff --git a/src/geom/axes.rs b/src/geom/axes.rs index 04023898..48f8c0e8 100644 --- a/src/geom/axes.rs +++ b/src/geom/axes.rs @@ -104,6 +104,16 @@ impl Axes { pub fn max(self, other: Self) -> Self { Self { x: self.x.max(other.x), y: self.y.max(other.y) } } + + /// The minimum of width and height. + pub fn min_by_side(self) -> T { + self.x.min(self.y) + } + + /// The minimum of width and height. + pub fn max_by_side(self) -> T { + self.x.max(self.y) + } } impl Get for Axes { @@ -189,6 +199,16 @@ impl Axes> { } } +impl Axes> { + /// Unwrap the individual fields. + pub fn unwrap_or(self, other: Axes) -> Axes { + Axes { + x: self.x.unwrap_or(other.x), + y: self.y.unwrap_or(other.y), + } + } +} + impl Axes { /// Select `t.x` if `self.x` is true and `f.x` otherwise and same for `y`. pub fn select(self, t: Axes, f: Axes) -> Axes { diff --git a/src/geom/point.rs b/src/geom/point.rs index 34d3dcd8..ce3a6ff2 100644 --- a/src/geom/point.rs +++ b/src/geom/point.rs @@ -35,6 +35,16 @@ impl Point { Self { x: Abs::zero(), y } } + /// The component-wise minimum of this and another point. + pub fn min(self, other: Self) -> Self { + Self { x: self.x.min(other.x), y: self.y.min(other.y) } + } + + /// The component-wise minimum of this and another point. + pub fn max(self, other: Self) -> Self { + Self { x: self.x.max(other.x), y: self.y.max(other.y) } + } + /// Transform the point with the given transformation. pub fn transform(self, ts: Transform) -> Self { Self::new( @@ -42,6 +52,11 @@ impl Point { ts.ky.of(self.x) + ts.sy.of(self.y) + ts.ty, ) } + + /// Convert to a size. + pub fn to_size(self) -> Size { + Size::new(self.x, self.y) + } } impl Numeric for Point { diff --git a/src/geom/smart.rs b/src/geom/smart.rs index d20bcdfe..e115e99d 100644 --- a/src/geom/smart.rs +++ b/src/geom/smart.rs @@ -10,6 +10,16 @@ pub enum Smart { } impl Smart { + /// Whether the value is `Auto`. + pub fn is_auto(&self) -> bool { + matches!(self, Self::Auto) + } + + /// Whether this holds a custom value. + pub fn is_custom(&self) -> bool { + matches!(self, Self::Custom(_)) + } + /// Map the contained custom value with `f`. pub fn map(self, f: F) -> Smart where -- cgit v1.2.3