pub struct Text { /* private fields */ }Expand description
Multi-line Unicode text: a ParagraphStyle shaped into a ParagraphLayout,
plus ink and one optional reveal effect. cosmic-text is the sole paragraph
shaper, and unhinted skrifa outlines enter the ordinary shared fill pipeline.
Static drawing, handwriting and part animation all read the same layout.
Implementations§
Source§impl Text
impl Text
Sourcepub fn try_animate_parts_at(
&self,
context: &SceneContext<'_>,
delay: Duration,
style: impl Fn(&TextPart) -> PartStyle,
) -> Result<Node, ValidationError>
pub fn try_animate_parts_at( &self, context: &SceneContext<'_>, delay: Duration, style: impl Fn(&TextPart) -> PartStyle, ) -> Result<Node, ValidationError>
Evaluates part styles synchronously at explicit scene-local signed time, without reshaping for animation. Source bounds and line wrapping stay fixed; returned node bounds also include transformed animation ink. Measured paragraph baseline is retained for horizontal Row alignment.
Source§impl Text
impl Text
Sourcepub fn from_font(
text: &str,
font: &FontFace,
size: f64,
paint: impl Into<Paint>,
) -> Result<Self, ValidationError>
pub fn from_font( text: &str, font: &FontFace, size: f64, paint: impl Into<Paint>, ) -> Result<Self, ValidationError>
Builds and validates text using one explicit immutable font face.
Sourcepub fn new(text: impl Into<Arc<str>>) -> Self
pub fn new(text: impl Into<Arc<str>>) -> Self
Creates a paragraph with size 24, line height 1.3 and white fill.
Sourcepub fn rich(spans: impl IntoIterator<Item = TextSpan>) -> Self
pub fn rich(spans: impl IntoIterator<Item = TextSpan>) -> Self
Creates rich spans, whose unset styles inherit paragraph defaults.
Sourcepub fn from_paragraph(paragraph: ParagraphStyle) -> Self
pub fn from_paragraph(paragraph: ParagraphStyle) -> Self
Wraps a paragraph description with white fill and no effect.
Sourcepub fn paragraph(&self) -> &ParagraphStyle
pub fn paragraph(&self) -> &ParagraphStyle
The paragraph description this text shapes.
Sourcepub fn family(self, family: impl Into<Arc<str>>) -> Self
pub fn family(self, family: impl Into<Arc<str>>) -> Self
Selects an explicit family; empty uses the library’s generic default.
Sourcepub fn weight(self, weight: FontWeight) -> Self
pub fn weight(self, weight: FontWeight) -> Self
Selects OpenType weight; variable weight participates in glyph identity.
Sourcepub fn fill(self, paint: impl Into<Paint>) -> Self
pub fn fill(self, paint: impl Into<Paint>) -> Self
Sets paint without invalidating shaped geometry.
Sourcepub fn stroke(self, width: f64, paint: impl Into<Paint>) -> Self
pub fn stroke(self, width: f64, paint: impl Into<Paint>) -> Self
Adds stroke after filling; existing bounded stroke rules apply.
Sourcepub fn line_height(self, height: f64) -> Self
pub fn line_height(self, height: f64) -> Self
Sets a positive relative line-height multiplier.
Sourcepub fn letter_spacing(self, spacing: f64) -> Self
pub fn letter_spacing(self, spacing: f64) -> Self
Sets logical tracking, converted to em internally for shaping.
Sourcepub fn alignment(self, alignment: TextAlignment) -> Self
pub fn alignment(self, alignment: TextAlignment) -> Self
Selects bidirectional-aware paragraph alignment.
Sourcepub fn fonts(self, fonts: &FontLibrary) -> Self
pub fn fonts(self, fonts: &FontLibrary) -> Self
Binds an explicit font snapshot, overriding a DrawContext environment.
Sourcepub fn split(self, split: TextSplit) -> Self
pub fn split(self, split: TextSplit) -> Self
Selects grapheme, word-boundary or wrapped-line parts.
Sourcepub fn visible_parts(self, count: usize) -> Self
pub fn visible_parts(self, count: usize) -> Self
Keeps original layout while drawing only the first logical parts.
Sourcepub fn write(self, progress: f64) -> Self
pub fn write(self, progress: f64) -> Self
Defers vector handwriting to compilation with the current font environment. It replaces any earlier part animation.
Sourcepub fn animate_parts(
self,
delay: Duration,
style: impl Fn(&TextPart) -> PartStyle + Send + Sync + 'static,
) -> Self
pub fn animate_parts( self, delay: Duration, style: impl Fn(&TextPart) -> PartStyle + Send + Sync + 'static, ) -> Self
Defers per-part style evaluation to scene-local drawing time. It replaces any earlier handwriting.
Sourcepub fn fit_lines(
&self,
max_lines: usize,
fonts: &FontLibrary,
) -> Result<(Self, bool), ValidationError>
pub fn fit_lines( &self, max_lines: usize, fonts: &FontLibrary, ) -> Result<(Self, bool), ValidationError>
Precomputes a paragraph limited to 1..=512 lines; see
ParagraphStyle::fit_lines. Ink and effects are retained.
Sourcepub fn layout(
&self,
fonts: &FontLibrary,
) -> Result<Arc<ParagraphLayout>, ValidationError>
pub fn layout( &self, fonts: &FontLibrary, ) -> Result<Arc<ParagraphLayout>, ValidationError>
Shapes once per text-style/font snapshot, returning actual line/ink metrics.
Sourcepub fn write_with_context(
&self,
progress: f64,
context: &DrawContext,
) -> Result<Node, ValidationError>
pub fn write_with_context( &self, progress: f64, context: &DrawContext, ) -> Result<Node, ValidationError>
Applies the common vector handwriting effect with default contour/fill handoff. Bind fonts on this Text or supply them in the DrawContext.
Sourcepub fn vector_tree(
&self,
context: &DrawContext,
) -> Result<Arc<VectorTree>, ValidationError>
pub fn vector_tree( &self, context: &DrawContext, ) -> Result<Arc<VectorTree>, ValidationError>
Exports original shared glyph curves, color layers, bitmap strikes and source ranges into the common vector model. No second shaping pass occurs.
Sourcepub fn vector_tree_of(
&self,
layout: &ParagraphLayout,
) -> Result<Arc<VectorTree>, ValidationError>
pub fn vector_tree_of( &self, layout: &ParagraphLayout, ) -> Result<Arc<VectorTree>, ValidationError>
Exports the glyphs of an already shaped layout, honoring visibility, fills and stroke of this text.
Trait Implementations§
Source§impl DeferredContent for Text
impl DeferredContent for Text
Source§fn resolve(&self, context: &DrawContext) -> Result<Node, ValidationError>
fn resolve(&self, context: &DrawContext) -> Result<Node, ValidationError>
context.Auto Trait Implementations§
impl !RefUnwindSafe for Text
impl !UnwindSafe for Text
impl Forget for Text
impl Freeze for Text
impl Move for Text
impl Send for Text
impl Sync for Text
impl Unpin for Text
impl UnsafeUnpin for Text
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Output> IntoSceneOutput for Output
impl<Output> IntoSceneOutput for Output
Source§impl<Value> NodeModifiers for Value
impl<Value> NodeModifiers for Value
Source§fn layered_shadow(self, color: Color, radius: f64, offset: Vector2) -> Node
fn layered_shadow(self, color: Color, radius: f64, offset: Vector2) -> Node
Source§fn elevated(self, elevation: Elevation) -> Node
fn elevated(self, elevation: Elevation) -> Node
Elevation.