Text

Struct Text 

Source
pub struct Text(/* private fields */);
Expand description

A view that displays one or more lines of read-only text.

Text

Text sizes itself to fit its content and never stretches to fill extra space. When the available width is limited, it wraps to multiple lines automatically. If both width and height are constrained, it truncates with “…” at the end.

§Layout Behavior

  • Sizing: Fits its content naturally, like a label
  • In stacks: Takes only the space it needs, leaving room for siblings
  • Wrapping: Automatically wraps when width is constrained via .frame()

§Examples

// Simple text
text("Hello, World!")

// Styled text
text("Important").bold().title()

// Enable wrapping with fixed width
text("Long paragraph...").frame().width(200.0)

// Push text apart in a row
hstack((text("Name"), spacer(), text("Value")))

Implementations§

Source§

impl Text

Source

pub fn new(content: impl IntoComputed<StyledStr>) -> Self

Creates a new text component.

Source

pub fn display<T: Display>(source: impl Signal<Output = T>) -> Self

Creates a text component from any type implementing Display.

This is a convenience method for creating text from values like numbers, booleans, or other displayable types.

Source

pub fn format<T>( value: impl IntoComputed<T>, formatter: impl Formatter<T> + 'static, ) -> Self

Creates a text component using a custom formatter.

This allows for specialized formatting of values, such as locale-specific number or date formatting.

Source

pub fn content(&self) -> Computed<StyledStr>

Returns the computed content of this text component.

This provides access to the reactive text content that will automatically update when the underlying data changes.

Source

pub fn font(self, font: impl IntoSignal<Font>) -> Self

Sets the font for this text component.

This allows customizing the typography, including size, weight, style, and other font properties.

Source

pub fn size(self, size: impl IntoSignal<f64>) -> Self

Sets the font size.

Source

pub fn weight(self, weight: impl IntoSignal<FontWeight>) -> Self

Sets the font weight.

Source

pub fn underline(self, underline: impl IntoSignal<bool>) -> Self

Applies an underline to the text.

Source

pub fn foreground(self, color: impl Into<Color>) -> Self

Sets the foreground (text) color.

Source

pub fn background_color(self, color: impl Into<Color>) -> Self

Sets the background color for the text.

Source

pub fn bold(self) -> Self

Sets the font to bold.

Source

pub fn italic(self, is_italic: impl Signal<Output = bool>) -> Self

Sets the italic style.

Source§

impl Text

Source

pub fn body(self) -> Self

Sets the font to body style.

Source§

impl Text

Source

pub fn title(self) -> Self

Sets the font to title style.

Source§

impl Text

Source

pub fn headline(self) -> Self

Sets the font to headline style.

Source§

impl Text

Source

pub fn subheadline(self) -> Self

Sets the font to subheadline style.

Source§

impl Text

Source

pub fn caption(self) -> Self

Sets the font to caption style.

Source§

impl Text

Source

pub fn footnote(self) -> Self

Sets the font to footnote style.

Trait Implementations§

Source§

impl Clone for Text

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl ConfigurableView for Text

Source§

type Config = TextConfig

The configuration type associated with this view. Read more
Source§

fn config(self) -> Self::Config

Returns the configuration for this view. Read more
Source§

impl Debug for Text

Source§

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

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

impl Default for Text

Source§

fn default() -> Self

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

impl<T> From<T> for Text

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl From<TextConfig> for Text

Source§

fn from(value: TextConfig) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Text

Source§

fn eq(&self, _other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Text

Source§

fn partial_cmp(&self, _other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Signal for Text

Source§

type Output = Text

The type of value produced by this computation.
Source§

type Guard = ()

The guard type returned by the watch method that manages watcher lifecycle.
Source§

fn get(&self) -> Self::Output

Execute the computation and return the current value.
Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Register a watcher to be notified when the computed value changes. Read more
Source§

impl View for Text

Source§

fn body(self, env: &Environment) -> impl View

Build this view and return the content. Read more

Auto Trait Implementations§

§

impl Freeze for Text

§

impl !RefUnwindSafe for Text

§

impl !Send for Text

§

impl !Sync for Text

§

impl Unpin for Text

§

impl !UnwindSafe for Text

Blanket Implementations§

Source§

impl<S> AnimationExt for S
where S: SignalExt,

Source§

fn animated(self) -> WithMetadata<Self, Animation>
where Self: Sized,

Apply default animation to this reactive value Read more
Source§

fn with_animation(self, animation: Animation) -> WithMetadata<Self, Animation>
where Self: Sized,

Apply a specific animation to this reactive value Read more
§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> IdentifiableExt for T

Source§

fn use_id<F, Id>(self, f: F) -> UseId<Self, F>
where F: Fn(&Self) -> Id, Id: Ord + Hash,

Wraps the value in a UseId with the provided identification function.
Source§

fn self_id(self) -> SelfId<Self>

Wraps the value in a SelfId, making the value serve as its own identifier.
§

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

§

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<C, Output> IntoSignal<Output> for C
where C: Signal, <C as Signal>::Output: 'static + Clone, Output: From<<C as Signal>::Output> + 'static,

Source§

fn into_signal(self) -> <C as IntoSignal<Output>>::Signal

Convert this computation into one that produces the desired output type.

Source§

type Signal = Map<C, fn(<C as Signal>::Output) -> Output, Output>

The specific computation type that will be produced.
Source§

impl<V> IntoView for V
where V: View,

Source§

type Output = V

The resulting View type after conversion.
Source§

fn into_view(self, _env: &Environment) -> <V as IntoView>::Output

Converts the implementing type into a View. Read more
Source§

impl<C> SignalExt for C
where C: Signal,

Source§

fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
where F: 'static + Clone + Fn(Self::Output) -> Output, Output: 'static, Self: 'static,

Transforms the output of this signal using the provided function.
Source§

fn zip<B>(self, b: B) -> Zip<Self, B>
where B: Signal, Self::Output: Clone, <B as Signal>::Output: Clone,

Combines this signal with another signal into a tuple.
Source§

fn cached(self) -> Cached<Self>
where Self::Output: Clone,

Wraps this signal with caching to avoid redundant computations.
Source§

fn computed(self) -> Computed<Self::Output>
where Self: 'static,

Converts this signal into a type-erased Computed container.
Source§

fn with<T>(self, metadata: T) -> WithMetadata<Self, T>

Attaches metadata to this signal’s watcher notifications.
Source§

fn debounce(self, duration: Duration) -> Debounce<Self, DefaultExecutor>
where Self::Output: Clone,

Creates a debounced version of this signal. Read more
Source§

fn throttle(self, duration: Duration) -> Throttle<Self, DefaultExecutor>
where Self::Output: Clone,

Creates a throttled version of this signal. Read more
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.