diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-07-29 11:35:49 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-07-29 11:35:49 +0200 |
| commit | 312dcd070cf79c1dd5503f90ef10588fe4612108 (patch) | |
| tree | d995673742bfddbc107dc8d384e1d8ecd4d0ccb6 /src/layout | |
| parent | 6ebe6218343a520dce2a5e560edbdc6fa0e9e44b (diff) | |
Move EcoString and OptionExt into util
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/incremental.rs | 45 | ||||
| -rw-r--r-- | src/layout/mod.rs | 1 | ||||
| -rw-r--r-- | src/layout/par.rs | 3 |
3 files changed, 6 insertions, 43 deletions
diff --git a/src/layout/incremental.rs b/src/layout/incremental.rs index cbd55330..352434ed 100644 --- a/src/layout/incremental.rs +++ b/src/layout/incremental.rs @@ -269,46 +269,9 @@ impl Constraints { let current = regions.current.to_spec(); let base = regions.base.to_spec(); - self.exact.horizontal.set_if_some(current.horizontal); - self.exact.vertical.set_if_some(current.vertical); - self.base.horizontal.set_if_some(base.horizontal); - self.base.vertical.set_if_some(base.vertical); - } -} - -/// Extends length-related options by providing convenience methods for setting -/// minimum and maximum lengths on them, even if they are `None`. -pub trait OptionExt { - /// Sets `other` as the value if `self` is `None` or if it contains a - /// value larger than `other`. - fn set_min(&mut self, other: Length); - - /// Sets `other` as the value if `self` is `None` or if it contains a - /// value smaller than `other`. - fn set_max(&mut self, other: Length); - - /// Sets `other` as the value if `self` is `Some`. - fn set_if_some(&mut self, other: Length); -} - -impl OptionExt for Option<Length> { - fn set_min(&mut self, other: Length) { - match self { - Some(x) => x.set_min(other), - None => *self = Some(other), - } - } - - fn set_max(&mut self, other: Length) { - match self { - Some(x) => x.set_max(other), - None => *self = Some(other), - } - } - - fn set_if_some(&mut self, other: Length) { - if self.is_some() { - *self = Some(other); - } + self.exact.horizontal.and_set(Some(current.horizontal)); + self.exact.vertical.and_set(Some(current.vertical)); + self.base.horizontal.and_set(Some(base.horizontal)); + self.base.vertical.and_set(Some(base.vertical)); } } diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 0f88d150..56e0687a 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -32,6 +32,7 @@ use std::rc::Rc; use crate::font::FontCache; use crate::geom::*; use crate::image::ImageCache; +use crate::util::OptionExt; use crate::Context; /// Layout a tree into a collection of frames. diff --git a/src/layout/par.rs b/src/layout/par.rs index 56847b9b..03d7efd5 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -5,9 +5,8 @@ use unicode_bidi::{BidiInfo, Level}; use xi_unicode::LineBreakIterator; use super::*; -use crate::eco::EcoString; use crate::exec::TextState; -use crate::util::{RangeExt, SliceExt}; +use crate::util::{EcoString, RangeExt, SliceExt}; type Range = std::ops::Range<usize>; |
