TextView

Trait TextView 

Source
pub trait TextView: View {
    // Required method
    fn text_node(&mut self) -> &mut TextStyle;

    // Provided methods
    fn text_alignment(self, justify_text: JustifyText) -> Self { ... }
    fn text_linebreak(self, line_break: LineBreak) -> Self { ... }
    fn text(self, text: impl Into<String>) -> Self { ... }
    fn text_color(self, color: impl Into<Color>) -> Self { ... }
    fn font(self, font: Handle<Font>) -> Self { ... }
    fn font_size(self, font_size: f32) -> Self { ... }
    fn line_height(self, line_height: LineHeight) -> Self { ... }
    fn font_smoothing(self, font_smoothing: FontSmoothing) -> Self { ... }
}
Expand description

A trait for views that support styled text content using a TextStyle bundle.

Required Methods§

Source

fn text_node(&mut self) -> &mut TextStyle

Returns a mutable reference to the inner TextStyle node used for text styling.

Provided Methods§

Source

fn text_alignment(self, justify_text: JustifyText) -> Self

Sets the text alignment mode within the layout container.

Controls horizontal alignment of multiline text, such as left-aligned, right-aligned, centered, or justified.

§Arguments
  • justify_text - A JustifyText variant indicating the desired alignment mode.
§Example
view.text_alignment(JustifyText::Center);
Source

fn text_linebreak(self, line_break: LineBreak) -> Self

Sets the line-breaking behavior of the text content.

Determines how and when lines wrap, such as breaking on word boundaries, characters, or disabling wrapping altogether.

§Arguments
  • line_break - A LineBreak variant specifying the wrapping strategy.
§Example
view.text_linebreak(LineBreak::WordWrap);
Source

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

Sets the string content of the text node.

§Arguments
  • text - A string or string-like value representing the text to display.
§Example
view.text("Hello, world!");
Source

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

Sets the text color of the node.

§Arguments
  • color - A color value (e.g., Color::WHITE, Color::rgb(...)).
Source

fn font(self, font: Handle<Font>) -> Self

Sets the font asset used for rendering the text.

§Arguments
  • font - A handle to a Font asset.
Source

fn font_size(self, font_size: f32) -> Self

Sets the size of the font in logical pixels.

§Arguments
  • font_size - The font size, typically in points or pixels.
Source

fn line_height(self, line_height: LineHeight) -> Self

Sets the line height for the text, controlling vertical spacing between lines.

§Arguments
  • line_height - A LineHeight value representing relative or absolute spacing.
Source

fn font_smoothing(self, font_smoothing: FontSmoothing) -> Self

Sets the font smoothing mode for the text.

§Arguments
  • font_smoothing - A FontSmoothing strategy (e.g., FontSmoothing::None, Subpixel).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§