Skip to main content

RichText

RichText is the widget for text that cannot stay uniform.

Use it when one block of text needs multiple styles, inline emphasis, mixed semantics, or even inline widgets. If the whole string shares one style, Text is usually the clearer choice.

Example

use fission::core::ui::{RichText, RichTextRun};

let node = RichText::new(vec![
RichTextRun::new("Build status: "),
RichTextRun::new("Passed")
.weight(700)
.color(view.env.theme.tokens.colors.primary),
])
.max_lines(1)
.into_node();

This keeps one logical sentence together while still giving the status word special emphasis.

Content table

FieldTypeMeaningNotes / default behavior
idOption<NodeId>Stable node identity.Defaults to None.
runsVec<RichTextRun>The styled runs that make up the text block.RichText::new(...) fills this for you.
inline_widgetsVec<InlineWidgetSpan>Inline widgets embedded in the text flow.Usually produced through RichText::from_spans(...), not built manually.
annotationsVec<RichTextAnnotation>Advanced semantic and interaction annotations over byte ranges.Usually generated from span builders rather than authored by hand.
semanticsOption<Semantics>Optional wrapper semantics for the whole block.Defaults to None.

Layout and typography table

FieldTypeMeaningNotes / default behavior
widthOption<f32>Fixed width.Defaults to None.
heightOption<f32>Fixed height.Defaults to None.
min_widthOption<f32>Minimum width.Defaults to None.
max_widthOption<f32>Maximum width.Defaults to None.
min_heightOption<f32>Minimum height.Defaults to None.
max_heightOption<f32>Maximum height.Defaults to None.
wrapboolWhether lines may wrap.RichText::new(...) and from_spans(...) set this to true. Raw Default construction does not.
text_alignIrTextAlignParagraph alignment.Defaults to the intermediate representation (IR) default.
text_directionIrTextDirectionParagraph direction.Defaults to the IR default.
text_width_basisIrTextWidthBasisWidth calculation policy.Defaults to the IR default.
max_linesOption<usize>Maximum number of visible lines.Defaults to None.
overflowIrTextOverflowOverflow behavior for clipped text.Defaults to visible overflow.
strut_line_heightOption<f32>Paragraph strut line height.Defaults to None.
text_height_behaviorIrTextHeightBehaviorParagraph height trimming behavior.Defaults to the IR default.
selection_rangeOption<(usize, usize)>Highlighted text selection range.Defaults to None.
selection_colorOption<IrColor>Selection highlight color override.Defaults to None.
selection_text_colorOption<IrColor>Selected text color override.Defaults to None.
flex_growf32Extra width or height the text block may absorb in flex layout.Defaults to 0.0.
flex_shrinkf32How much the block may shrink in tight layouts.Defaults to 0.0.

Practical model

There are two common ways to build rich text. For simple styling changes, RichText::new(vec![...runs...]) is enough. For more advanced cases such as inline widgets, hoverable spans, or nested semantics, the span-based constructors are the better fit because they generate the annotations and inline-widget bookkeeping for you.

In both cases, the widget stays declarative. You are still describing the paragraph from state, not mutating a text object in place.

Specific advice

Reach for RichText because the content truly needs mixed styling or inline semantics, not because it feels more powerful. When uniform text is enough, Text is easier to read and maintain.

Text, RichTextRun, TextRunStyle, and TextContent.