Skip to main content

WidgetSpan

Struct WidgetSpan 

Source
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 an InlineSpan tree.
  • Text, a widget for showing uniformly-styled text.
  • RichText, a widget for finer control of text rendering.
  • TextPainter, a class for painting InlineSpan objects on a Canvas.

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

The widget to embed inline within text.

§alignment: PlaceholderAlignment

How the placeholder aligns vertically with the text.

§baseline: Option<TextBaseline>§style: Option<TextStyle>

The TextStyle to apply to this span; only the decoration, foreground, background, and spacing options are used.

Implementations§

Source§

impl WidgetSpan

Source

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.

Source

pub fn alignment(self, alignment: PlaceholderAlignment) -> WidgetSpan

Dart WidgetSpan(alignment:).

Source

pub fn baseline(self, baseline: TextBaseline) -> WidgetSpan

Dart WidgetSpan(baseline:).

Source

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

Dart WidgetSpan(style:).

Source

pub fn into_span(self) -> InlineSpanRef

The span as a shared InlineSpanRef.

A baseline alignment needs a baseline.

Source

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

Source§

fn clone(&self) -> Self

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 WidgetSpan

Source§

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

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

impl InlineSpan for WidgetSpan

Source§

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

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>

WidgetSpans are not hit-test targets: this always returns None.

Source§

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

Dart’s Diagnosticable.toStringShort for this span: the type name, as Dart prints runtimeType.
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 style(&self) -> Option<&TextStyle>

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

fn visit_direct_children( &self, _visitor: &mut dyn FnMut(&InlineSpanRef) -> bool, ) -> bool

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

fn get_span_for_position_visitor( self: Rc<Self>, position: TextPosition, offset: &mut Accumulator, ) -> Option<InlineSpanRef>

Performs the check at each InlineSpan for if the position falls within the range. 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

Downcast support for Dart’s runtimeType and is checks.
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 eq_span(&self, other: &dyn InlineSpan) -> bool

Dart’s ==: deep equality on the same span class.
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 to_hit_test_target(self: Rc<Self>) -> 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 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§

impl PlaceholderSpan for WidgetSpan

Source§

fn alignment(&self) -> PlaceholderAlignment

How the placeholder aligns vertically with the text. Read more
Source§

fn baseline(&self) -> Option<TextBaseline>

Source§

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

In debug mode, throws an exception: a placeholder that is not a WidgetSpan is not supported.

Auto Trait Implementations§

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>