pub struct Text(/* private fields */);Expand description
A view that displays one or more lines of read-only 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
impl Text
Sourcepub fn new(content: impl IntoComputed<StyledStr>) -> Self
pub fn new(content: impl IntoComputed<StyledStr>) -> Self
Creates a new text component.
Sourcepub fn display<T: Display>(source: impl Signal<Output = T>) -> Self
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.
Sourcepub fn format<T>(
value: impl IntoComputed<T>,
formatter: impl Formatter<T> + 'static,
) -> Self
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.
Sourcepub fn content(&self) -> Computed<StyledStr>
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.
Sourcepub fn font(self, font: impl IntoSignal<Font>) -> Self
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.
Sourcepub fn size(self, size: impl IntoSignal<f64>) -> Self
pub fn size(self, size: impl IntoSignal<f64>) -> Self
Sets the font size.
Sourcepub fn weight(self, weight: impl IntoSignal<FontWeight>) -> Self
pub fn weight(self, weight: impl IntoSignal<FontWeight>) -> Self
Sets the font weight.
Sourcepub fn underline(self, underline: impl IntoSignal<bool>) -> Self
pub fn underline(self, underline: impl IntoSignal<bool>) -> Self
Applies an underline to the text.
Sourcepub fn foreground(self, color: impl Into<Color>) -> Self
pub fn foreground(self, color: impl Into<Color>) -> Self
Sets the foreground (text) color.
Sourcepub fn background_color(self, color: impl Into<Color>) -> Self
pub fn background_color(self, color: impl Into<Color>) -> Self
Sets the background color for the text.
Source§impl Text
impl Text
Sourcepub fn subheadline(self) -> Self
pub fn subheadline(self) -> Self
Sets the font to subheadline style.
Trait Implementations§
Source§impl ConfigurableView for Text
impl ConfigurableView for Text
Source§impl From<TextConfig> for Text
impl From<TextConfig> for Text
Source§fn from(value: TextConfig) -> Self
fn from(value: TextConfig) -> Self
Source§impl PartialOrd for Text
impl PartialOrd for Text
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 Swhere
S: SignalExt,
impl<S> AnimationExt for Swhere
S: SignalExt,
Source§fn animated(self) -> WithMetadata<Self, Animation>where
Self: Sized,
fn animated(self) -> WithMetadata<Self, Animation>where
Self: Sized,
Source§fn with_animation(self, animation: Animation) -> WithMetadata<Self, Animation>where
Self: Sized,
fn with_animation(self, animation: Animation) -> WithMetadata<Self, Animation>where
Self: Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> IdentifiableExt for T
impl<T> IdentifiableExt for T
Source§impl<C, Output> IntoSignal<Output> for C
impl<C, Output> IntoSignal<Output> for C
Source§impl<C> SignalExt for Cwhere
C: Signal,
impl<C> SignalExt for Cwhere
C: Signal,
Source§fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
fn map<F, Output>(self, f: F) -> Map<Self, F, Output>
Source§fn cached(self) -> Cached<Self>
fn cached(self) -> Cached<Self>
Source§fn computed(self) -> Computed<Self::Output>where
Self: 'static,
fn computed(self) -> Computed<Self::Output>where
Self: 'static,
Computed container.