pub struct TextSpan {
pub text: Option<String>,
pub children: Option<Vec<Rc<dyn InlineSpan>>>,
pub style: Option<TextStyle>,
pub recognizer: Option<Retained<AnyGestureRecognizer>>,
pub mouse_cursor: Option<Rc<dyn MouseCursor>>,
pub on_enter: Option<Rc<dyn Fn(&mut App, PointerEnterEvent)>>,
pub on_exit: Option<Rc<dyn Fn(&mut App, PointerExitEvent)>>,
}Expand description
An immutable span of text.
A TextSpan object can be styled using its style property. The style
will be applied to the text and the children.
A TextSpan object can just have plain text, or it can have children TextSpan
objects with their own styles that (in turn) can have their own children, and so on. The
text of a span is rendered before its children.
Dart’s named constructor arguments are the fluent setters (TextSpan::new().text("x")).
Dart’s TextSpan implements HitTestTarget, MouseTrackerAnnotation: the span is a
HitTestTarget, and mouse_tracker_annotation is the
annotation it implements.
Fields§
§text: Option<String>The text contained in this span.
If both text and children are set, the text will
precede the children.
children: Option<Vec<Rc<dyn InlineSpan>>>Additional spans to include as children.
If both text and children are set, the text will
precede the children.
style: Option<TextStyle>The TextStyle to apply to this span and its children.
recognizer: Option<Retained<AnyGestureRecognizer>>A gesture recognizer that will receive events that hit this span.
InlineSpan itself does not implement hit testing or event dispatch. The object that
manages the InlineSpan painting is also responsible for dispatching events. In the
rendering library, that is the RenderParagraph object, which corresponds to the
RichText widget in the widgets layer; these objects do not bubble events in
InlineSpans, so a recognizer is only effective for events that
directly hit the text of that InlineSpan, not any of its
children.
InlineSpan also does not manage the lifetime of the gesture recognizer. The code
that owns the gesture recognizer must call its dispose when the InlineSpan object
is no longer used.
mouse_cursor: Option<Rc<dyn MouseCursor>>Mouse cursor when the mouse hovers over this span, as the caller gave it; read it with
effective_mouse_cursor.
The default value is SystemMouseCursors::CLICK if recognizer
is not None, or MouseCursor.defer otherwise.
TextSpan itself does not implement hit testing or cursor changing. The object that
manages the TextSpan painting is responsible to return the TextSpan in its hit
test, as well as providing the correct mouse cursor when the TextSpan’s mouse cursor
is MouseCursor.defer.
on_enter: Option<Rc<dyn Fn(&mut App, PointerEnterEvent)>>Triggered when a mouse pointer has entered this span.
on_exit: Option<Rc<dyn Fn(&mut App, PointerExitEvent)>>Triggered when a mouse pointer has exited this span.
Implementations§
Source§impl TextSpan
impl TextSpan
Sourcepub fn recognizer(self, recognizer: Retained<AnyGestureRecognizer>) -> TextSpan
pub fn recognizer(self, recognizer: Retained<AnyGestureRecognizer>) -> TextSpan
Dart TextSpan(recognizer:).
Sourcepub fn mouse_cursor(
self,
mouse_cursor: impl Into<Rc<dyn MouseCursor>>,
) -> TextSpan
pub fn mouse_cursor( self, mouse_cursor: impl Into<Rc<dyn MouseCursor>>, ) -> TextSpan
Dart TextSpan(mouseCursor:).
Sourcepub fn on_enter(
self,
on_enter: Rc<dyn Fn(&mut App, PointerEnterEvent)>,
) -> TextSpan
pub fn on_enter( self, on_enter: Rc<dyn Fn(&mut App, PointerEnterEvent)>, ) -> TextSpan
Dart TextSpan(onEnter:).
Sourcepub fn on_exit(
self,
on_exit: Rc<dyn Fn(&mut App, PointerExitEvent)>,
) -> TextSpan
pub fn on_exit( self, on_exit: Rc<dyn Fn(&mut App, PointerExitEvent)>, ) -> TextSpan
Dart TextSpan(onExit:).
Sourcepub fn effective_mouse_cursor(&self) -> Rc<dyn MouseCursor>
pub fn effective_mouse_cursor(&self) -> Rc<dyn MouseCursor>
Dart’s mouseCursor field, as its constructor fills it: the cursor given, else
SystemMouseCursors::CLICK when there is a recognizer, else
MouseCursor.defer.
Sourcepub fn mouse_tracker_annotation(&self) -> MouseTrackerAnnotation
pub fn mouse_tracker_annotation(&self) -> MouseTrackerAnnotation
Dart’s TextSpan implements MouseTrackerAnnotation: the annotation this span is to the
mouse tracker, with its on_enter, on_exit and
effective_mouse_cursor. A span is always valid for the
mouse tracker.
Sourcepub fn into_span(self) -> Rc<dyn InlineSpan>
pub fn into_span(self) -> Rc<dyn InlineSpan>
The span as a shared InlineSpanRef.
Trait Implementations§
Source§impl Diagnosticable for TextSpan
impl Diagnosticable for TextSpan
Source§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
Source§fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Object.runtimeType as diagnostics print it: the last segment of
the Rust type path, without generic arguments.Source§fn identity_hash(&self) -> u64
fn identity_hash(&self) -> u64
Object.hashCode as diagnostics print it: the object’s address.Source§fn to_diagnostics_node(&self) -> DiagnosticableNode
fn to_diagnostics_node(&self) -> DiagnosticableNode
DiagnosticsNode::to_string_deep.Source§fn to_diagnostics_node_with(
&self,
name: Option<String>,
style: Option<DiagnosticsTreeStyle>,
) -> DiagnosticableNode
fn to_diagnostics_node_with( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableNode
toDiagnosticsNode(name:, style:).Source§fn to_string(&self) -> String
fn to_string(&self) -> String
toString: a single-line description with properties and no
children. Read moreSource§fn to_string_at(&self, min_level: DiagnosticLevel) -> String
fn to_string_at(&self, min_level: DiagnosticLevel) -> String
toString(minLevel:).Source§impl DiagnosticableTree for TextSpan
impl DiagnosticableTree for TextSpan
Source§fn debug_describe_children(&self) -> Vec<Rc<dyn DiagnosticsNode>>
fn debug_describe_children(&self) -> Vec<Rc<dyn DiagnosticsNode>>
Source§fn to_diagnostics_tree_node(
&self,
name: Option<String>,
style: Option<DiagnosticsTreeStyle>,
) -> DiagnosticableTreeNode
fn to_diagnostics_tree_node( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableTreeNode
self.Source§fn to_string_shallow(&self, joiner: &str, min_level: DiagnosticLevel) -> String
fn to_string_shallow(&self, joiner: &str, min_level: DiagnosticLevel) -> String
to_string_deep but without
recursing to children.Source§fn to_string_deep(&self) -> String
fn to_string_deep(&self) -> String
Source§fn to_string_deep_with(
&self,
prefix_line_one: &str,
prefix_other_lines: Option<&str>,
min_level: DiagnosticLevel,
wrap_width: usize,
) -> String
fn to_string_deep_with( &self, prefix_line_one: &str, prefix_other_lines: Option<&str>, min_level: DiagnosticLevel, wrap_width: usize, ) -> String
Source§impl HitTestTarget for TextSpan
impl HitTestTarget for TextSpan
Source§fn handle_event(
&self,
app: &mut App,
event: &PointerEvent,
_entry: &HitTestEntry,
)
fn handle_event( &self, app: &mut App, event: &PointerEvent, _entry: &HitTestEntry, )
Source§impl InlineSpan for TextSpan
impl InlineSpan for TextSpan
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]>, )
Apply the style, text, and
children of this object to the given ParagraphBuilder, from
which a Paragraph can be obtained.
Rather than using this directly, it’s simpler to use the TextPainter class to paint
TextSpan objects onto Canvas objects.
Source§fn visit_children(
self: Rc<TextSpan>,
visitor: &mut dyn FnMut(&Rc<dyn InlineSpan>) -> bool,
) -> bool
fn visit_children( self: Rc<TextSpan>, visitor: &mut dyn FnMut(&Rc<dyn InlineSpan>) -> bool, ) -> bool
Walks this TextSpan and its descendants in pre-order and calls visitor for
each span that has text.
When visitor returns true, the walk will continue. When visitor returns false,
then the walk will end.
Source§fn get_span_for_position_visitor(
self: Rc<TextSpan>,
position: TextPosition,
offset: &mut Accumulator,
) -> Option<Rc<dyn InlineSpan>>
fn get_span_for_position_visitor( self: Rc<TextSpan>, position: TextPosition, offset: &mut Accumulator, ) -> Option<Rc<dyn InlineSpan>>
Returns the text span that contains the given position in the text.
Source§fn debug_assert_is_valid(&self) -> bool
fn debug_assert_is_valid(&self) -> bool
In debug mode, throws an exception if the object is not in a valid configuration. Otherwise, returns true.
This is intended to be used as follows: debug_assert!(span.debug_assert_is_valid()).
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 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§fn visit_direct_children(
&self,
visitor: &mut dyn FnMut(&Rc<dyn InlineSpan>) -> bool,
) -> bool
fn visit_direct_children( &self, visitor: &mut dyn FnMut(&Rc<dyn InlineSpan>) -> bool, ) -> bool
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_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
runtimeType and is checks.Source§fn to_hit_test_target(self: Rc<TextSpan>) -> Option<Rc<dyn HitTestTarget>>
fn to_hit_test_target(self: Rc<TextSpan>) -> 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 eq_span(&self, other: &dyn InlineSpan) -> bool
fn eq_span(&self, other: &dyn InlineSpan) -> bool
==: deep equality on the same span class.Source§fn get_span_for_position(
self: Rc<Self>,
position: TextPosition,
) -> Option<Rc<dyn InlineSpan>>
fn get_span_for_position( self: Rc<Self>, position: TextPosition, ) -> Option<Rc<dyn InlineSpan>>
InlineSpan that contains the given position in the text.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 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 to_string_short(&self) -> String
fn to_string_short(&self) -> String
Diagnosticable.toStringShort for this span: the type name, as Dart prints
runtimeType.