diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-28 17:57:16 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-28 17:57:16 +0100 |
| commit | 836692e73cff0356e409a9ba5b4887b86809d4ca (patch) | |
| tree | e174178047c368c66746ee073eea1b3129825479 /src/doc.rs | |
| parent | 989d170dc7318ca3cbaa5b76760eb14f4e6a8605 (diff) | |
Widow and orphan prevention
Diffstat (limited to 'src/doc.rs')
| -rw-r--r-- | src/doc.rs | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -32,7 +32,7 @@ pub struct Metadata { } /// A partial layout result. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Clone, Eq, PartialEq)] pub struct Fragment(Vec<Frame>); impl Fragment { @@ -60,6 +60,11 @@ impl Fragment { self.0.into_iter().next().unwrap() } + /// Extract the frames. + pub fn into_frames(self) -> Vec<Frame> { + self.0 + } + /// Iterate over the contained frames. pub fn iter(&self) -> std::slice::Iter<Frame> { self.0.iter() @@ -71,6 +76,15 @@ impl Fragment { } } +impl Debug for Fragment { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self.0.as_slice() { + [frame] => frame.fmt(f), + frames => frames.fmt(f), + } + } +} + impl IntoIterator for Fragment { type Item = Frame; type IntoIter = std::vec::IntoIter<Frame>; @@ -121,6 +135,11 @@ impl Frame { Self { size, baseline: None, elements: Arc::new(vec![]) } } + /// Whether the frame contains no elements. + pub fn is_empty(&self) -> bool { + self.elements.is_empty() + } + /// The size of the frame. pub fn size(&self) -> Size { self.size |
