Struct embedded_text::TextBox[][src]

pub struct TextBox<'a, S, M = NoPlugin<<S as TextRenderer>::Color>> where
    S: TextRenderer
{ pub text: &'a str, pub bounds: Rectangle, pub character_style: S, pub style: TextBoxStyle, pub vertical_offset: i32, // some fields omitted }
Expand description

A text box object.

The TextBox object can be used to draw text on a draw target. It is meant to be a more feature-rich alternative to Text in embedded-graphics.

To construct a TextBox object at least a text string, a bounding box and character style are required. For advanced formatting options an additional TextBoxStyle object might be used. For more information about text box styling, see the documentation of the style module.

Text rendering in embedded-graphics is designed to be extendable by text renderers for different font formats. embedded-text follows this philosophy by using the same text renderer infrastructure. To use a text renderer in an embedded-text project each renderer provides a character style object. See the embedded-graphics documentation for more information on text renderers and character styling.

Plugins

The feature set of TextBox can be extended by plugins. Plugins can be used to implement optional features which are not essential to the core functionality of embedded-text.

Use the add_plugin method to add a plugin to the TextBox object. Multiple plugins can be used at the same time. Plugins are applied in the reverse order they are added. Note that some plugins may interfere with others if used together or not in the expected order.

If you need to extract data from plugins after the text box has been rendered, you can use the take_plugins method.

See the list of built-in plugins in the plugin module.

Note: Implementing custom plugins is experimental and require enabling the plugin feature.

Example: advanced text styling using the ANSI plugin

use embedded_text::{TextBox, plugin::ansi::Ansi};
TextBox::new(
    "Some \x1b[4munderlined\x1b[24m text",
    bounding_box,
    character_style,
)
.add_plugin(Ansi::new())
.draw(&mut display)?;

Vertical offsetting

You can use the set_vertical_offset method to move the text inside the text box. Vertical offset is applied after all vertical measurements and alignments. This can be useful to scroll text in a fixed text box. Setting a positive value moves the text down.

Residual text

If the text does not fit the given bounding box, the draw method returns the part which was not processed. The return value can be used to flow text into multiple text boxes.

Fields

text: &'a str

The text to be displayed in this TextBox

bounds: Rectangle

The bounding box of this TextBox

character_style: S

The character style of the TextBox.

style: TextBoxStyle

The style of the TextBox.

vertical_offset: i32

Vertical offset applied to the text just before rendering.

Implementations

Creates a new TextBox instance with a given bounding Rectangle.

Creates a new TextBox instance with a given bounding Rectangle and a given TextBoxStyle.

Creates a new TextBox instance with a given bounding Rectangle and a default TextBoxStyle with the given horizontal alignment.

Creates a new TextBox instance with a given bounding Rectangle and a default TextBoxStyle and the given vertical alignment.

Creates a new TextBox instance with a given bounding Rectangle and a default TextBoxStyle and the given height mode.

Creates a new TextBox instance with a given bounding Rectangle and a default TextBoxStyle and the given line height.

Creates a new TextBox instance with a given bounding Rectangle and a default TextBoxStyle and the given paragraph spacing.

Creates a new TextBox instance with a given bounding Rectangle and a default TextBoxStyle and the given tab size.

Sets the vertical text offset.

Vertical offset changes the vertical position of the displayed text within the bounding box. Setting a positive value moves the text down.

Adds a new plugin to the TextBox.

Adds a new plugin to the TextBox.

Deconstruct the text box and return the plugins.

Sets the height of the TextBox to the height of the text.

Sets the height of the TextBox to the height of the text, limited to max_height.

This method allows you to set a maximum height. The TextBox will take up at most max_height pixel vertical space.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the bounding box.

The pixel color type.

The return type of the draw method. Read more

Draw the graphics object using the supplied DrawTarget.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Move the origin of an object by a given number of (x, y) pixels, returning a new object

Move the origin of an object by a given number of (x, y) pixels, mutating the object in place Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Performs the conversion.

Performs the conversion.

Casts the value.

Should always be Self

Casts the value.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

Casts the value.