diff options
| author | Eric Biedert <github@ericbiedert.de> | 2023-09-26 11:42:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-26 11:42:05 +0200 |
| commit | c8ebcd70d6b2b9b3ad5142411305d766cc2d0c2e (patch) | |
| tree | f3167f3d685606f3eea5bfe3ebb2ba8f986abc2f /crates/typst-library/src/layout | |
| parent | c55901e972f6671ecfe05358a96f85f34c703cc0 (diff) | |
Resolve spacing before comparing (#2235)
Diffstat (limited to 'crates/typst-library/src/layout')
| -rw-r--r-- | crates/typst-library/src/layout/spacing.rs | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/crates/typst-library/src/layout/spacing.rs b/crates/typst-library/src/layout/spacing.rs index 50f66a8e..cf69f6d9 100644 --- a/crates/typst-library/src/layout/spacing.rs +++ b/crates/typst-library/src/layout/spacing.rs @@ -1,5 +1,3 @@ -use std::cmp::Ordering; - use crate::prelude::*; /// Inserts horizontal spacing into a paragraph. @@ -64,9 +62,19 @@ impl Behave for HElem { } } - fn larger(&self, prev: &Content) -> bool { - let Some(prev) = prev.to::<Self>() else { return false }; - self.amount() > prev.amount() + fn larger( + &self, + prev: &(Content, Behaviour, StyleChain), + styles: StyleChain, + ) -> bool { + let Some(other) = prev.0.to::<Self>() else { return false }; + match (self.amount(), other.amount()) { + (Spacing::Fr(this), Spacing::Fr(other)) => this > other, + (Spacing::Rel(this), Spacing::Rel(other)) => { + this.resolve(styles) > other.resolve(prev.2) + } + _ => false, + } } } @@ -156,9 +164,19 @@ impl Behave for VElem { } } - fn larger(&self, prev: &Content) -> bool { - let Some(prev) = prev.to::<Self>() else { return false }; - self.amount() > prev.amount() + fn larger( + &self, + prev: &(Content, Behaviour, StyleChain), + styles: StyleChain, + ) -> bool { + let Some(other) = prev.0.to::<Self>() else { return false }; + match (self.amount(), other.amount()) { + (Spacing::Fr(this), Spacing::Fr(other)) => this > other, + (Spacing::Rel(this), Spacing::Rel(other)) => { + this.resolve(styles) > other.resolve(prev.2) + } + _ => false, + } } } @@ -216,16 +234,6 @@ impl From<Fr> for Spacing { } } -impl PartialOrd for Spacing { - fn partial_cmp(&self, other: &Self) -> Option<Ordering> { - match (self, other) { - (Self::Rel(a), Self::Rel(b)) => a.partial_cmp(b), - (Self::Fr(a), Self::Fr(b)) => a.partial_cmp(b), - _ => None, - } - } -} - cast! { Spacing, self => match self { |
