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
| Field | Type | Meaning | Notes / default behavior |
|---|---|---|---|
id | Option<NodeId> | Stable node identity. | Defaults to None. |
runs | Vec<RichTextRun> | The styled runs that make up the text block. | RichText::new(...) fills this for you. |
inline_widgets | Vec<InlineWidgetSpan> | Inline widgets embedded in the text flow. | Usually produced through RichText::from_spans(...), not built manually. |
annotations | Vec<RichTextAnnotation> | Advanced semantic and interaction annotations over byte ranges. | Usually generated from span builders rather than authored by hand. |
semantics | Option<Semantics> | Optional wrapper semantics for the whole block. | Defaults to None. |
Layout and typography table
| Field | Type | Meaning | Notes / default behavior |
|---|---|---|---|
width | Option<f32> | Fixed width. | Defaults to None. |
height | Option<f32> | Fixed height. | Defaults to None. |
min_width | Option<f32> | Minimum width. | Defaults to None. |
max_width | Option<f32> | Maximum width. | Defaults to None. |
min_height | Option<f32> | Minimum height. | Defaults to None. |
max_height | Option<f32> | Maximum height. | Defaults to None. |
wrap | bool | Whether lines may wrap. | RichText::new(...) and from_spans(...) set this to true. Raw Default construction does not. |
text_align | IrTextAlign | Paragraph alignment. | Defaults to the intermediate representation (IR) default. |
text_direction | IrTextDirection | Paragraph direction. | Defaults to the IR default. |
text_width_basis | IrTextWidthBasis | Width calculation policy. | Defaults to the IR default. |
max_lines | Option<usize> | Maximum number of visible lines. | Defaults to None. |
overflow | IrTextOverflow | Overflow behavior for clipped text. | Defaults to visible overflow. |
strut_line_height | Option<f32> | Paragraph strut line height. | Defaults to None. |
text_height_behavior | IrTextHeightBehavior | Paragraph height trimming behavior. | Defaults to the IR default. |
selection_range | Option<(usize, usize)> | Highlighted text selection range. | Defaults to None. |
selection_color | Option<IrColor> | Selection highlight color override. | Defaults to None. |
selection_text_color | Option<IrColor> | Selected text color override. | Defaults to None. |
flex_grow | f32 | Extra width or height the text block may absorb in flex layout. | Defaults to 0.0. |
flex_shrink | f32 | How 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.
Related
Text, RichTextRun, TextRunStyle, and TextContent.