pub struct RichText {Show 13 fields
pub key: Option<KeyRef>,
pub text: Rc<dyn InlineSpan>,
pub text_align: TextAlign,
pub text_direction: Option<TextDirection>,
pub soft_wrap: bool,
pub overflow: TextOverflow,
pub text_scaler: TextScaler,
pub max_lines: Option<i32>,
pub strut_style: Option<StrutStyle>,
pub text_width_basis: TextWidthBasis,
pub text_height_behavior: Option<TextHeightBehavior>,
pub selection_registrar: Option<Retained<AnySelectionRegistrar>>,
pub selection_color: Option<Color>,
/* private fields */
}Expand description
A paragraph of rich text.
The RichText widget displays text that uses multiple different styles. The text to
display is described using a tree of TextSpan objects, each of which has an
associated style that is used for that subtree. The text might break across multiple
lines or might all be displayed on the same line depending on the layout constraints.
Text displayed in a RichText widget must be explicitly styled. When picking which
style to use, consider using DefaultTextStyle::of the current BuildContext to
provide defaults. For more details on how to style text in a RichText widget, see the
documentation for TextStyle.
Consider using the Text widget to integrate with the DefaultTextStyle
automatically. When all the text uses the same style, the default constructor is less
verbose. The Text::rich constructor allows you to style multiple spans with the
default text style while still allowing specified styles per span.
RichText::new(
TextSpan::new()
.text("Hello ")
.style(DefaultTextStyle::of(app, context).style)
.children(vec![
TextSpan::new().text("bold").style(TextStyle::new().font_weight(FontWeight::BOLD)).into_span(),
TextSpan::new().text(" world!").into_span(),
])
.into_span(),
)See also:
TextStyle, which discusses how to style text.TextSpan, which is used to describe the text in a paragraph.Text, which automatically applies the ambient styles described by aDefaultTextStyleto a single string.Text::rich, a text widget that provides similar functionality asRichText.Text::richwill inheritTextStylefromDefaultTextStyle.
Dart’s named constructor arguments are the fluent setters
(RichText::new(span).text_align(TextAlign::Center)).
Fields§
§key: Option<KeyRef>§text: Rc<dyn InlineSpan>The text to display in this widget.
text_align: TextAlignHow the text should be aligned horizontally.
text_direction: Option<TextDirection>The directionality of the text.
This decides how text_align values like TextAlign::Start and TextAlign::End
are interpreted.
This is also used to disambiguate how to render bidirectional text. For example, if
the text is an English phrase followed by a Hebrew phrase, in a
TextDirection::Ltr context the English phrase will be on the left and the Hebrew
phrase to its right, while in a TextDirection::Rtl context, the English phrase
will be on the right and the Hebrew phrase on its left.
Defaults to the ambient Directionality, if any. If there is no ambient
Directionality, then this must not be None.
soft_wrap: boolWhether the text should break at soft line breaks.
If false, the glyphs in the text will be positioned as if there was unlimited horizontal space.
overflow: TextOverflowHow visual overflow should be handled.
text_scaler: TextScalerThe font scaling strategy to use when laying out and rendering the text.
max_lines: Option<i32>An optional maximum number of lines for the text to span, wrapping if necessary. If
the text exceeds the given number of lines, it will be truncated according to
overflow.
If this is 1, text will not wrap. Otherwise, text will be wrapped at the edge of the box.
strut_style: Option<StrutStyle>The strut style to use. Strut style defines the strut, which sets minimum vertical layout metrics.
text_width_basis: TextWidthBasisDefines how to measure the width of the rendered text.
text_height_behavior: Option<TextHeightBehavior>Defines how to apply TextStyle.height over and under text.
selection_registrar: Option<Retained<AnySelectionRegistrar>>The SelectionRegistrar this rich text is
subscribed to.
If this is set, selection_color must be non-null.
selection_color: Option<Color>The color to use when painting the selection.
Implementations§
Source§impl RichText
impl RichText
Sourcepub fn new(text: Rc<dyn InlineSpan>) -> RichText
pub fn new(text: Rc<dyn InlineSpan>) -> RichText
Creates a paragraph of rich text.
The max_lines property may be None (and indeed defaults to None), but if it is
not None, it must be greater than zero.
The text_direction, if None, defaults to the ambient Directionality, which in
that case must not be null.
Sourcepub fn text_align(self, text_align: TextAlign) -> RichText
pub fn text_align(self, text_align: TextAlign) -> RichText
Dart RichText(textAlign:).
Sourcepub fn text_direction(self, text_direction: TextDirection) -> RichText
pub fn text_direction(self, text_direction: TextDirection) -> RichText
Dart RichText(textDirection:).
Sourcepub fn overflow(self, overflow: TextOverflow) -> RichText
pub fn overflow(self, overflow: TextOverflow) -> RichText
Dart RichText(overflow:).
Sourcepub fn text_scaler(self, text_scaler: TextScaler) -> RichText
pub fn text_scaler(self, text_scaler: TextScaler) -> RichText
Dart RichText(textScaler:).
Sourcepub fn max_lines(self, max_lines: i32) -> RichText
pub fn max_lines(self, max_lines: i32) -> RichText
Dart RichText(maxLines:). Must be greater than zero.
Sourcepub fn strut_style(self, strut_style: StrutStyle) -> RichText
pub fn strut_style(self, strut_style: StrutStyle) -> RichText
Dart RichText(strutStyle:).
Sourcepub fn text_width_basis(self, text_width_basis: TextWidthBasis) -> RichText
pub fn text_width_basis(self, text_width_basis: TextWidthBasis) -> RichText
Dart RichText(textWidthBasis:).
Sourcepub fn text_height_behavior(
self,
text_height_behavior: TextHeightBehavior,
) -> RichText
pub fn text_height_behavior( self, text_height_behavior: TextHeightBehavior, ) -> RichText
Dart RichText(textHeightBehavior:).
Sourcepub fn selection_registrar(
self,
registrar: Retained<AnySelectionRegistrar>,
) -> RichText
pub fn selection_registrar( self, registrar: Retained<AnySelectionRegistrar>, ) -> RichText
Dart RichText(selectionRegistrar:).
Sourcepub fn selection_color(self, color: Color) -> RichText
pub fn selection_color(self, color: Color) -> RichText
Dart RichText(selectionColor:).
Trait Implementations§
Source§impl RenderObjectWidget for RichText
impl RenderObjectWidget for RichText
Source§type RenderObject = RenderParagraph
type RenderObject = RenderParagraph
covariant RenderObject parameter type.Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn create_render_object(
&self,
app: &mut App,
context: AnyElement,
) -> AnyRenderObject
fn create_render_object( &self, app: &mut App, context: AnyElement, ) -> AnyRenderObject
RenderObject class that this widget represents, using the
configuration described by this widget. Read moreSource§fn update_render_object(
&self,
app: &mut App,
context: AnyElement,
render_object: RenderHandle<RenderParagraph>,
)
fn update_render_object( &self, app: &mut App, context: AnyElement, render_object: RenderHandle<RenderParagraph>, )
create_render_object. Read moreSource§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
toStringShort, for a widget that names itself apart from its type, as
SizedBox.expand does; see Widget::to_string_short.Source§fn debug_visit_onstage_children(
&self,
app: &App,
children: &[AnyElement],
visitor: &mut dyn FnMut(AnyElement),
)
fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )
debugVisitOnstageChildren of the element this widget makes, for a widget whose
Dart element subclass overrides it only to hide children (_OffstageElement,
_IndexedStackElement): calls visitor for each of children, in order, that is
onstage. Waft’s generic single- and multi-child elements stand in for those subclasses
and ask their widget here; an element of a widget’s own overrides
Element::debug_visit_onstage_children instead.Source§fn did_unmount_render_object(
&self,
app: &mut App,
render_object: RenderHandle<Self::RenderObject>,
)
fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<Self::RenderObject>, )
RenderObject will be of the same type as returned by this object’s
create_render_object.Auto Trait Implementations§
impl !RefUnwindSafe for RichText
impl !Send for RichText
impl !Sync for RichText
impl !UnwindSafe for RichText
impl Forget for RichText
impl Freeze for RichTextwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn InlineSpan> is !null: Freeze,
PhantomData<RcInner<dyn InlineSpan>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Rc<dyn Widget>>: Freeze,
*const TextScaler is !null: Freeze,
PhantomData<TextScaler>: Freeze,
PhantomData<u8>: Freeze,
PhantomData<String>: Freeze,
NonZero<u32>: Freeze,
&'static SelectionRegistrarVTable: Freeze,
*const RcInner<Keep> is !null: Freeze,
PhantomData<RcInner<Keep>>: Freeze,
impl Move for RichText
impl Unpin for RichText
impl UnsafeUnpin for RichTextwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn InlineSpan> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn InlineSpan>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Rc<dyn Widget>>: UnsafeUnpin,
*const TextScaler is !null: UnsafeUnpin,
PhantomData<TextScaler>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
NonZeroU32Inner: UnsafeUnpin,
&'static SelectionRegistrarVTable: UnsafeUnpin,
*const RcInner<Keep> is !null: UnsafeUnpin,
PhantomData<RcInner<Keep>>: UnsafeUnpin,
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<W> IntoWidget<MultiChildRenderObjectKind> for Wwhere
W: MultiChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: ContainerRenderObjectMixin,
impl<W> IntoWidget<MultiChildRenderObjectKind> for Wwhere
W: MultiChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: ContainerRenderObjectMixin,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.