diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-10 22:19:36 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-10 22:19:36 +0200 |
| commit | 92c01da36016e94ff20163806ddcbcf7e33d4031 (patch) | |
| tree | 1a900b3c11edcc93e9153fada3ce92310db5768b /src/layout/spacing.rs | |
| parent | 42500d5ed85539c5ab04dd3544beaf802da29be9 (diff) | |
Switch back to custom geometry types, unified with layout primitives 🏞
Diffstat (limited to 'src/layout/spacing.rs')
| -rw-r--r-- | src/layout/spacing.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/layout/spacing.rs b/src/layout/spacing.rs new file mode 100644 index 00000000..9eac1ad5 --- /dev/null +++ b/src/layout/spacing.rs @@ -0,0 +1,51 @@ +use std::fmt::{self, Debug, Formatter}; + +use super::*; + +/// A node that inserts spacing. +#[derive(Copy, Clone, PartialEq)] +pub struct Spacing { + pub amount: Length, + pub softness: Softness, +} + +#[async_trait(?Send)] +impl Layout for Spacing { + async fn layout( + &self, + _: &mut LayoutContext, + _: LayoutConstraints, + ) -> Vec<LayoutItem> { + vec![LayoutItem::Spacing(self.amount)] + } +} + +impl Debug for Spacing { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self.softness { + Softness::Soft => write!(f, "Soft({})", self.amount), + Softness::Hard => write!(f, "Hard({})", self.amount), + } + } +} + +impl From<Spacing> for LayoutNode { + fn from(spacing: Spacing) -> Self { + Self::Spacing(spacing) + } +} + +/// Defines how spacing interacts with surrounding spacing. +/// +/// Hard spacing assures that a fixed amount of spacing will always be inserted. +/// Soft spacing will be consumed by previous soft spacing or neighbouring hard +/// spacing and can be used to insert overridable spacing, e.g. between words or +/// paragraphs. +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] +pub enum Softness { + /// Soft spacing is not laid out if it directly follows other soft spacing + /// or if it touches hard spacing. + Soft, + /// Hard spacing is always laid out and consumes surrounding soft spacing. + Hard, +} |
