Skip to main content

TextSpan

Struct TextSpan 

Source
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

Source

pub fn new() -> TextSpan

Creates an empty TextSpan; set the fields with the fluent setters.

Source

pub fn text(self, text: impl Into<String>) -> TextSpan

Dart TextSpan(text:).

Source

pub fn children(self, children: Vec<Rc<dyn InlineSpan>>) -> TextSpan

Dart TextSpan(children:).

Source

pub fn style(self, style: TextStyle) -> TextSpan

Dart TextSpan(style:).

Source

pub fn recognizer(self, recognizer: Retained<AnyGestureRecognizer>) -> TextSpan

Dart TextSpan(recognizer:).

Source

pub fn mouse_cursor( self, mouse_cursor: impl Into<Rc<dyn MouseCursor>>, ) -> TextSpan

Dart TextSpan(mouseCursor:).

Source

pub fn on_enter( self, on_enter: Rc<dyn Fn(&mut App, PointerEnterEvent)>, ) -> TextSpan

Dart TextSpan(onEnter:).

Source

pub fn on_exit( self, on_exit: Rc<dyn Fn(&mut App, PointerExitEvent)>, ) -> TextSpan

Dart TextSpan(onExit:).

Source

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.

Source

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.

Source

pub fn into_span(self) -> Rc<dyn InlineSpan>

The span as a shared InlineSpanRef.

Trait Implementations§

Source§

impl Clone for TextSpan

Source§

fn clone(&self) -> TextSpan

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextSpan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for TextSpan

Source§

fn default() -> TextSpan

Returns the “default value” for a type. Read more
Source§

impl Diagnosticable for TextSpan

Source§

fn to_string_short(&self) -> String

A brief description of this object, usually just the type and the hash.
Source§

fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)

Add additional properties associated with the node.
Source§

fn type_name(&self) -> &'static str

Dart’s Object.runtimeType as diagnostics print it: the last segment of the Rust type path, without generic arguments.
Source§

fn identity_hash(&self) -> u64

Dart’s Object.hashCode as diagnostics print it: the object’s address.
Source§

fn to_diagnostics_node(&self) -> DiagnosticableNode

Returns a debug representation of the object used by debugging tools and by DiagnosticsNode::to_string_deep.
Source§

fn to_diagnostics_node_with( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableNode

Dart toDiagnosticsNode(name:, style:).
Source§

fn to_string(&self) -> String

Dart’s toString: a single-line description with properties and no children. Read more
Source§

fn to_string_at(&self, min_level: DiagnosticLevel) -> String

Dart’s toString(minLevel:).
Source§

impl DiagnosticableTree for TextSpan

Source§

fn debug_describe_children(&self) -> Vec<Rc<dyn DiagnosticsNode>>

Returns a list of nodes describing this node’s children.
Source§

fn to_diagnostics_tree_node( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableTreeNode

Returns a node whose properties and children are collected from self.
Source§

fn to_string_shallow(&self, joiner: &str, min_level: DiagnosticLevel) -> String

Returns a one-line detailed description of the object, including the same information as to_string_deep but without recursing to children.
Source§

fn to_string_deep(&self) -> String

Returns a string representation of this node and its descendants with Dart’s default arguments.
Source§

fn to_string_deep_with( &self, prefix_line_one: &str, prefix_other_lines: Option<&str>, min_level: DiagnosticLevel, wrap_width: usize, ) -> String

Returns a string representation of this node and its descendants.
Source§

impl HitTestTarget for TextSpan

Source§

fn handle_event( &self, app: &mut App, event: &PointerEvent, _entry: &HitTestEntry, )

Override this method to receive events.
Source§

fn arena_id(&self) -> Option<HandleId>

The arena object this target delivers to, if it is one, so a result kept across turns keeps it (HitTestResult::keep_targets): Dart keeps the object alive by holding it in the path.
Source§

impl InlineSpan for TextSpan

Source§

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

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>>

Returns the text span that contains the given position in the text.

Source§

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)

Dart’s InlineSpan.debugFillProperties, inherited from Diagnosticable: the tree style and the span’s style. Read more
Source§

fn debug_describe_children(&self) -> Vec<Rc<dyn DiagnosticsNode>>

Dart’s InlineSpan.debugDescribeChildren, inherited from DiagnosticableTree.
Source§

fn diagnostics_node( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableTreeNode

Dart’s InlineSpan.toDiagnosticsNode(name:, style:), inherited from Diagnosticable; a dyn InlineSpan answers through this method.
Source§

fn style(&self) -> Option<&TextStyle>

The TextStyle to apply to this span. Read more
Source§

fn visit_direct_children( &self, visitor: &mut dyn FnMut(&Rc<dyn InlineSpan>) -> bool, ) -> bool

Calls visitor for each immediate child of this InlineSpan. Read more
Source§

fn compute_to_plain_text( &self, buffer: &mut String, include_semantics_labels: bool, include_placeholders: bool, )

Walks the InlineSpan tree and writes the plain text representation to the buffer. Read more
Source§

fn code_unit_at_visitor( &self, index: i32, offset: &mut Accumulator, ) -> Option<u16>

Performs the check at each InlineSpan for if the index falls within the range of the span and returns the corresponding code unit. Returns None otherwise. Read more
Source§

fn compare_to(&self, other: &dyn InlineSpan) -> RenderComparison

Describe the difference between this span and another, in terms of how much damage it will make to the rendering. The comparison is deep. Read more
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Downcast support for Dart’s runtimeType and is checks.
Source§

fn to_hit_test_target(self: Rc<TextSpan>) -> Option<Rc<dyn HitTestTarget>>

Dart’s 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

Dart’s ==: deep equality on the same span class.
Source§

fn get_span_for_position( self: Rc<Self>, position: TextPosition, ) -> Option<Rc<dyn InlineSpan>>

Returns the InlineSpan that contains the given position in the text.
Source§

fn to_plain_text( &self, include_semantics_labels: bool, include_placeholders: bool, ) -> String

Flattens the InlineSpan tree into a single string. Read more
Source§

fn code_unit_at(self: Rc<Self>, index: i32) -> Option<u16>

Returns the UTF-16 code unit at the given index in the flattened string. Read more
Source§

fn as_placeholder_span(&self) -> Option<&dyn PlaceholderSpan>

Dart’s span is PlaceholderSpan: this span as a PlaceholderSpan, when it is one.
Source§

fn to_string_short(&self) -> String

Dart’s Diagnosticable.toStringShort for this span: the type name, as Dart prints runtimeType.

Auto Trait Implementations§

§

impl !RefUnwindSafe for TextSpan

§

impl !Send for TextSpan

§

impl !Sync for TextSpan

§

impl !UnwindSafe for TextSpan

§

impl Forget for TextSpan

§

impl Freeze for TextSpan
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<Rc<dyn InlineSpan>>: Freeze, &'static dyn ColorExtension: Freeze, *const RcInner<dyn ColorExtension> is !null: Freeze, PhantomData<RcInner<dyn ColorExtension>>: Freeze, PhantomData<String>: Freeze, *const RcInner<Paint> is !null: Freeze, PhantomData<RcInner<Paint>>: Freeze, PhantomData<Shadow>: Freeze, PhantomData<FontFeature>: Freeze, PhantomData<FontVariation>: Freeze, NonZero<u32>: Freeze, &'static GestureRecognizerVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const RcInner<dyn MouseCursor> is !null: Freeze, PhantomData<RcInner<dyn MouseCursor>>: Freeze, *const RcInner<dyn Fn(&mut App, PointerEnterEvent)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, PointerEnterEvent)>>: Freeze, *const RcInner<dyn Fn(&mut App, PointerExitEvent)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, PointerExitEvent)>>: Freeze,

§

impl Move for TextSpan

§

impl Unpin for TextSpan
where *const u8 is !null: Unpin, Rc<dyn InlineSpan>: Unpin, &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin, Rc<Paint>: Unpin, NonZero<u32>: Unpin, &'static GestureRecognizerVTable: Unpin, Rc<Keep>: Unpin, Rc<dyn MouseCursor>: Unpin, Rc<dyn Fn(&mut App, PointerEnterEvent)>: Unpin, Rc<dyn Fn(&mut App, PointerExitEvent)>: Unpin,

§

impl UnsafeUnpin for TextSpan
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<Rc<dyn InlineSpan>>: UnsafeUnpin, &'static dyn ColorExtension: UnsafeUnpin, *const RcInner<dyn ColorExtension> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ColorExtension>>: UnsafeUnpin, PhantomData<String>: UnsafeUnpin, *const RcInner<Paint> is !null: UnsafeUnpin, PhantomData<RcInner<Paint>>: UnsafeUnpin, PhantomData<Shadow>: UnsafeUnpin, PhantomData<FontFeature>: UnsafeUnpin, PhantomData<FontVariation>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static GestureRecognizerVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const RcInner<dyn MouseCursor> is !null: UnsafeUnpin, PhantomData<RcInner<dyn MouseCursor>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, PointerEnterEvent)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, PointerEnterEvent)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, PointerExitEvent)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, PointerExitEvent)>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>