pub struct WidgetSpan {
pub child: WidgetRef,
pub alignment: PlaceholderAlignment,
pub baseline: Option<TextBaseline>,
pub style: Option<TextStyle>,
}Expand description
An immutable widget that is embedded inline within text.
The child property is the widget that will be embedded. Children are
constrained by the width of the paragraph.
The child property may contain its own Widget children (if applicable),
including Text and RichText widgets which may include additional WidgetSpans.
Child Text and RichText widgets will be laid out independently and occupy a rectangular
space in the parent text layout.
WidgetSpans will be ignored when passed into a TextPainter
directly. To properly layout and paint the WidgetSpan, WidgetSpan should be passed
into a Text::rich widget.
Text::rich(
TextSpan::new()
.children(vec![
TextSpan::new().text("Flutter is").into_span(),
WidgetSpan::new(SizedBox::new().width(120.0).height(50.0).child(Card::new(...)))
.into_span(),
TextSpan::new().text("the best!").into_span(),
])
.into_span(),
)WidgetSpan contributes the semantics of the WidgetSpan::child to the semantics
tree.
See also:
TextSpan, a node that represents text in anInlineSpantree.Text, a widget for showing uniformly-styled text.RichText, a widget for finer control of text rendering.TextPainter, a class for paintingInlineSpanobjects on aCanvas.
Dart’s named constructor arguments are the fluent setters; the constructor’s assert runs
in into_span, once every setter has had its say.
Fields§
§child: WidgetRefThe widget to embed inline within text.
alignment: PlaceholderAlignmentHow the placeholder aligns vertically with the text.
baseline: Option<TextBaseline>The TextBaseline to align against when using PlaceholderAlignment::Baseline,
PlaceholderAlignment::AboveBaseline, and PlaceholderAlignment::BelowBaseline.
style: Option<TextStyle>The TextStyle to apply to this span; only the decoration, foreground, background,
and spacing options are used.
Implementations§
Source§impl WidgetSpan
impl WidgetSpan
Sourcepub fn new<K>(child: impl IntoWidget<K>) -> WidgetSpan
pub fn new<K>(child: impl IntoWidget<K>) -> WidgetSpan
Creates a WidgetSpan with the given values.
The child property is the widget that will be embedded. Children are
constrained by the width of the paragraph.
The child property may contain its own Widget children (if
applicable), including Text and RichText widgets which may include additional
WidgetSpans. Child Text and RichText widgets will be laid out independently and
occupy a rectangular space in the parent text layout.
A TextStyle may be provided with the style property, but only the
decoration, foreground, background, and spacing options will be used.
Sourcepub fn alignment(self, alignment: PlaceholderAlignment) -> WidgetSpan
pub fn alignment(self, alignment: PlaceholderAlignment) -> WidgetSpan
Dart WidgetSpan(alignment:).
Sourcepub fn baseline(self, baseline: TextBaseline) -> WidgetSpan
pub fn baseline(self, baseline: TextBaseline) -> WidgetSpan
Dart WidgetSpan(baseline:).
Sourcepub fn style(self, style: TextStyle) -> WidgetSpan
pub fn style(self, style: TextStyle) -> WidgetSpan
Dart WidgetSpan(style:).
Sourcepub fn into_span(self) -> InlineSpanRef
pub fn into_span(self) -> InlineSpanRef
The span as a shared InlineSpanRef.
A baseline alignment needs a baseline.
Sourcepub fn extract_from_inline_span(
span: &dyn InlineSpan,
text_scaler: &TextScaler,
) -> Vec<WidgetRef>
pub fn extract_from_inline_span( span: &dyn InlineSpan, text_scaler: &TextScaler, ) -> Vec<WidgetRef>
Helper function for extracting WidgetSpans in preorder, from the given
InlineSpan as a list of widgets.
The text_scaler is the scaling strategy for scaling the content.
This function is used by EditableText and RichText so calling it directly is rarely
necessary.
Trait Implementations§
Source§impl Clone for WidgetSpan
impl Clone for WidgetSpan
Source§impl Debug for WidgetSpan
impl Debug for WidgetSpan
Source§impl InlineSpan for WidgetSpan
impl InlineSpan for WidgetSpan
Source§fn build(
&self,
builder: &mut ParagraphBuilder,
text_scaler: &TextScaler,
dimensions: Option<&[PlaceholderDimensions]>,
)
fn build( &self, builder: &mut ParagraphBuilder, text_scaler: &TextScaler, dimensions: Option<&[PlaceholderDimensions]>, )
Adds a placeholder box to the paragraph builder if a size has been calculated for the widget.
Sizes are provided through dimensions, which should contain a 1:1 in-order mapping
of widget to laid-out dimensions. If no such dimension is provided, the widget will be
skipped.
The text_scaler will be applied to the laid-out size of the widget.
Source§fn visit_children(
self: Rc<Self>,
visitor: &mut dyn FnMut(&InlineSpanRef) -> bool,
) -> bool
fn visit_children( self: Rc<Self>, visitor: &mut dyn FnMut(&InlineSpanRef) -> bool, ) -> bool
Calls visitor on this WidgetSpan. There are no children spans to walk.
Source§fn get_span_for_position(
self: Rc<Self>,
_position: TextPosition,
) -> Option<InlineSpanRef>
fn get_span_for_position( self: Rc<Self>, _position: TextPosition, ) -> Option<InlineSpanRef>
WidgetSpans are not hit-test targets: this always returns None.
Source§fn debug_assert_is_valid(&self) -> bool
fn debug_assert_is_valid(&self) -> bool
WidgetSpans are always valid as asserts prevent invalid WidgetSpans from being
constructed.
Source§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
Diagnosticable.toStringShort for this span: the type name, as Dart prints
runtimeType.Source§fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
InlineSpan.debugFillProperties, inherited from Diagnosticable: the tree
style and the span’s style. Read moreSource§fn visit_direct_children(
&self,
_visitor: &mut dyn FnMut(&InlineSpanRef) -> bool,
) -> bool
fn visit_direct_children( &self, _visitor: &mut dyn FnMut(&InlineSpanRef) -> bool, ) -> bool
Source§fn get_span_for_position_visitor(
self: Rc<Self>,
position: TextPosition,
offset: &mut Accumulator,
) -> Option<InlineSpanRef>
fn get_span_for_position_visitor( self: Rc<Self>, position: TextPosition, offset: &mut Accumulator, ) -> Option<InlineSpanRef>
Source§fn compute_to_plain_text(
&self,
buffer: &mut String,
include_semantics_labels: bool,
include_placeholders: bool,
)
fn compute_to_plain_text( &self, buffer: &mut String, include_semantics_labels: bool, include_placeholders: bool, )
Source§fn code_unit_at_visitor(
&self,
index: i32,
offset: &mut Accumulator,
) -> Option<u16>
fn code_unit_at_visitor( &self, index: i32, offset: &mut Accumulator, ) -> Option<u16>
InlineSpan for if the index falls within the range
of the span and returns the corresponding code unit. Returns None otherwise. Read moreSource§fn compare_to(&self, other: &dyn InlineSpan) -> RenderComparison
fn compare_to(&self, other: &dyn InlineSpan) -> RenderComparison
Source§fn as_placeholder_span(&self) -> Option<&dyn PlaceholderSpan>
fn as_placeholder_span(&self) -> Option<&dyn PlaceholderSpan>
span is PlaceholderSpan: this span as a PlaceholderSpan, when it is one.Source§fn eq_span(&self, other: &dyn InlineSpan) -> bool
fn eq_span(&self, other: &dyn InlineSpan) -> bool
==: deep equality on the same span class.Source§fn to_plain_text(
&self,
include_semantics_labels: bool,
include_placeholders: bool,
) -> String
fn to_plain_text( &self, include_semantics_labels: bool, include_placeholders: bool, ) -> String
InlineSpan tree into a single string. Read moreSource§fn code_unit_at(self: Rc<Self>, index: i32) -> Option<u16>
fn code_unit_at(self: Rc<Self>, index: i32) -> Option<u16>
index in the flattened string. Read moreSource§fn to_hit_test_target(self: Rc<Self>) -> Option<Rc<dyn HitTestTarget>>
fn to_hit_test_target(self: Rc<Self>) -> Option<Rc<dyn HitTestTarget>>
span is HitTestTarget: this span as the target a hit on it adds to a hit test,
when it is one. None, the default, for a span that is not.Source§fn debug_describe_children(&self) -> Vec<Rc<dyn DiagnosticsNode>>
fn debug_describe_children(&self) -> Vec<Rc<dyn DiagnosticsNode>>
InlineSpan.debugDescribeChildren, inherited from DiagnosticableTree.Source§fn diagnostics_node(
&self,
name: Option<String>,
style: Option<DiagnosticsTreeStyle>,
) -> DiagnosticableTreeNode
fn diagnostics_node( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableTreeNode
InlineSpan.toDiagnosticsNode(name:, style:), inherited from
Diagnosticable; a dyn InlineSpan answers through this method.Source§impl PlaceholderSpan for WidgetSpan
impl PlaceholderSpan for WidgetSpan
Source§fn alignment(&self) -> PlaceholderAlignment
fn alignment(&self) -> PlaceholderAlignment
Source§fn baseline(&self) -> Option<TextBaseline>
fn baseline(&self) -> Option<TextBaseline>
TextBaseline to align against when using PlaceholderAlignment::Baseline,
PlaceholderAlignment::AboveBaseline, and PlaceholderAlignment::BelowBaseline. Read moreSource§fn compute_to_plain_text(
&self,
buffer: &mut String,
include_semantics_labels: bool,
include_placeholders: bool,
)
fn compute_to_plain_text( &self, buffer: &mut String, include_semantics_labels: bool, include_placeholders: bool, )
PlaceholderSpans are flattened to a 0xFFFC object replacement character in the
plain text representation when include_placeholders is true.Source§fn debug_assert_is_valid(&self) -> bool
fn debug_assert_is_valid(&self) -> bool
WidgetSpan is not
supported.