summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-02-12 18:58:39 +0100
committerLaurenz <laurmaedje@gmail.com>2023-02-12 19:57:28 +0100
commit3ffa7393f0632d9ee5dd9c821685a1a033d5c0ab (patch)
treeaf09b0683352c4028436a2e5251dce54cf41d4aa /src
parentf4856c18b9cf3f6952276cc61b557aebeb2fa651 (diff)
Make all nodes block-level
Diffstat (limited to 'src')
-rw-r--r--src/doc.rs6
-rw-r--r--src/export/pdf/page.rs1
-rw-r--r--src/export/render.rs1
-rw-r--r--src/geom/axes.rs20
-rw-r--r--src/geom/point.rs15
-rw-r--r--src/geom/smart.rs10
6 files changed, 53 insertions, 0 deletions
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<T: Ord> Axes<T> {
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<T> Get<Axis> for Axes<T> {
@@ -189,6 +199,16 @@ impl<T> Axes<Option<T>> {
}
}
+impl<T> Axes<Smart<T>> {
+ /// Unwrap the individual fields.
+ pub fn unwrap_or(self, other: Axes<T>) -> Axes<T> {
+ Axes {
+ x: self.x.unwrap_or(other.x),
+ y: self.y.unwrap_or(other.y),
+ }
+ }
+}
+
impl Axes<bool> {
/// Select `t.x` if `self.x` is true and `f.x` otherwise and same for `y`.
pub fn select<T>(self, t: Axes<T>, f: Axes<T>) -> Axes<T> {
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<T> {
}
impl<T> Smart<T> {
+ /// 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<F, U>(self, f: F) -> Smart<U>
where