Skip to main content

RichText

Struct RichText 

Source
pub struct RichText {
    pub spans: Vec<RichTextSpan>,
    pub max_width: Option<f32>,
    pub timing: TimingConfig,
    pub style: CssStyle,
    pub timeline: Vec<TimelineStep>,
    pub stagger: Option<f32>,
}
Expand description

Rich text component: renders multiple styled spans on the same line(s).

Fields§

§spans: Vec<RichTextSpan>§max_width: Option<f32>§timing: TimingConfig§style: CssStyle§timeline: Vec<TimelineStep>§stagger: Option<f32>

Implementations§

Source§

impl RichText

Source

pub fn compute_layout( spans: &[RichTextSpan], style: &CssStyle, viewport_width: f32, viewport_height: f32, wrap_width: Option<f32>, visible_chars_progress: f32, ) -> RichTextLayout

Word-wrap spans at wrap_width (None = unconstrained/natural width). visible_chars_progress >= 0.0 truncates the content for the typewriter effect (same char-count semantics as text); -1.0 shows everything (used for intrinsic/natural-size measurement, which must not shrink as the typewriter plays out — layout space is reserved for the full content up front).

Unlike the original implementation (which only ever broke a line at a span boundary — a single long span never wrapped internally), this tokenizes every span’s text into words and packs them greedily across span boundaries, so a long single span wraps like any other text. Whitespace runs collapse to a single rendered space (CSS white-space: normal semantics, matching text’s default wrap behaviour); the exact inter-word spacing of source whitespace is not preserved, matching how wrap_text_with_fallback already treats plain text content.

viewport_width/viewport_height resolve rem/vw/vh on style.font-size (lot B, wave S — this used to go through the context-free font_size_px_or, which silently resolved those units to 0px). Callers with no real per-frame viewport (intrinsic measurement, which runs before layout) should pass a stand-in — see intrinsic::measure_time_font_size_ctx’s doc comment for why 0px is worse than an approximation.

Trait Implementations§

Source§

impl Animatable for RichText

Source§

fn animation_effects(&self) -> &[AnimationEffect]

Source§

fn timeline_steps(&self) -> &[TimelineStep]

Timed animation steps (timeline field): each step’s animations are resolved with delay += step.at. Empty by default.
Source§

impl Debug for RichText

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RichText

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for RichText

Source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
Source§

impl Painter for RichText

Source§

fn paint_content( &self, canvas: &Canvas, layout: &BoxLayout, props: &AnimatedProperties, ctx: &PaintCtx, )

Paint the component’s content into the canvas. The canvas is already translated to the content-box origin and clipped if overflow: hidden was set. Generic decorations (bg, border, shadow) are already painted by the engine. Read more
Source§

fn intrinsic_size( &self, _available: AvailableSize, _ctx: &MeasureCtx, ) -> Option<(f32, f32)>

Optional intrinsic measurement for leaves like text, image, codeblock. Return None to let taffy compute the size from the CSS style alone. available mirrors taffy’s AvailableSpace.
Source§

impl Serialize for RichText

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Styled for RichText

Source§

impl StyledMut for RichText

Source§

fn style_config_mut(&mut self) -> &mut CssStyle

Source§

impl Timed for RichText

Source§

fn timing(&self) -> (Option<f64>, Option<f64>)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.