Text paragraphs, styling, fontconfig

This commit is contained in:
2026-03-20 20:15:27 -04:00
parent 00fe1daa0c
commit f71e03317d
9 changed files with 687 additions and 43 deletions

View File

@@ -1,5 +1,5 @@
use crate::scene::Color;
use crate::text::{TextStyle, TextWrap};
use crate::text::{TextSpan, TextStyle, TextWrap};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum FlexDirection {
@@ -75,7 +75,7 @@ enum ElementContent {
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct TextNode {
pub text: String,
pub spans: Vec<TextSpan>,
pub style: TextStyle,
}
@@ -96,11 +96,15 @@ impl Element {
}
pub fn text(text: impl Into<String>, style: TextStyle) -> Self {
Self::spans([TextSpan::new(text)], style)
}
pub fn spans(spans: impl IntoIterator<Item = TextSpan>, style: TextStyle) -> Self {
Self {
style: Style::default(),
children: Vec::new(),
content: ElementContent::Text(TextNode {
text: text.into(),
spans: spans.into_iter().collect(),
style,
}),
}
@@ -110,6 +114,10 @@ impl Element {
Self::text(text, style.with_wrap(TextWrap::Word))
}
pub fn rich_paragraph(spans: impl IntoIterator<Item = TextSpan>, style: TextStyle) -> Self {
Self::spans(spans, style.with_wrap(TextWrap::Word))
}
pub fn row() -> Self {
Self::new().direction(FlexDirection::Row)
}