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/text.rs | |
| parent | 42500d5ed85539c5ab04dd3544beaf802da29be9 (diff) | |
Switch back to custom geometry types, unified with layout primitives 🏞
Diffstat (limited to 'src/layout/text.rs')
| -rw-r--r-- | src/layout/text.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/layout/text.rs b/src/layout/text.rs new file mode 100644 index 00000000..fafc1b14 --- /dev/null +++ b/src/layout/text.rs @@ -0,0 +1,51 @@ +use std::fmt::{self, Debug, Formatter}; +use std::rc::Rc; + +use fontdock::{FallbackTree, FontVariant}; + +use super::*; +use crate::shaping; + +/// A text node. +#[derive(Clone, PartialEq)] +pub struct Text { + pub text: String, + pub size: Length, + pub dir: Dir, + pub fallback: Rc<FallbackTree>, + pub variant: FontVariant, + pub aligns: Gen<Align>, +} + +#[async_trait(?Send)] +impl Layout for Text { + async fn layout( + &self, + ctx: &mut LayoutContext, + _constraints: LayoutConstraints, + ) -> Vec<LayoutItem> { + let mut loader = ctx.loader.borrow_mut(); + let boxed = shaping::shape( + &self.text, + self.size, + self.dir, + &mut loader, + &self.fallback, + self.variant, + ) + .await; + vec![LayoutItem::Box(boxed, self.aligns)] + } +} + +impl Debug for Text { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!(f, "Text({})", self.text) + } +} + +impl From<Text> for LayoutNode { + fn from(text: Text) -> Self { + Self::Text(text) + } +} |
