pub struct TextArgs {
pub text: String,
pub color: Color,
pub size: Dp,
pub line_height: Option<Dp>,
}
Expand description
Configuration arguments for the text
component.
TextArgs
defines the visual properties and content for rendering text in the Tessera UI framework.
It uses the builder pattern for convenient construction and provides sensible defaults for all styling properties.
§Fields
text
: The string content to be displayedcolor
: Text color (defaults to black)size
: Font size in density-independent pixels (defaults to 25.0 dp)line_height
: Optional line height override (defaults to 1.2 × font size)
§Builder Pattern
This struct uses the derive_builder
crate to provide a fluent builder API. All fields except text
have sensible defaults, making it easy to create text with minimal configuration.
§Examples
§Basic text with defaults
use tessera_ui_basic_components::text::{TextArgs, TextArgsBuilder};
let args = TextArgsBuilder::default()
.text("Hello, World!".to_string())
.build()
.unwrap();
// Uses: black color, 25.0 dp size, 30.0 dp line height (1.2 × size)
§Customized text styling
use tessera_ui_basic_components::text::{TextArgs, TextArgsBuilder};
use tessera_ui::{Color, Dp};
let args = TextArgsBuilder::default()
.text("Styled Text".to_string())
.color(Color::from_rgb(0.2, 0.4, 0.8)) // Blue color
.size(Dp(32.0)) // Larger font
.line_height(Dp(40.0)) // Custom line height
.build()
.unwrap();
§Using automatic line height calculation
use tessera_ui_basic_components::text::{TextArgs, TextArgsBuilder};
use tessera_ui::Dp;
let args = TextArgsBuilder::default()
.text("Auto Line Height".to_string())
.size(Dp(50.0))
// line_height will automatically be Dp(60.0) (1.2 × 50.0)
.build()
.unwrap();
§Converting from string types
use tessera_ui_basic_components::text::TextArgs;
// From String
let args1: TextArgs = "Hello".to_string().into();
// From &str
let args2: TextArgs = "World".into();
Fields§
§text: String
The text content to be rendered.
This is the actual string that will be displayed on screen. It can contain Unicode characters and will be rendered using the specified font properties.
color: Color
The color of the text.
Defaults to Color::BLACK
if not specified. The color is applied uniformly
to all characters in the text string.
size: Dp
The font size in density-independent pixels (dp).
Defaults to Dp(25.0)
if not specified. This size is automatically scaled
based on the device’s pixel density to ensure consistent visual appearance
across different screen densities.
line_height: Option<Dp>
Optional override for line height in density-independent pixels (dp).
If not specified (None), the line height will automatically be calculated as 1.2 times the font size, which provides good readability for most text.
Set this to a specific value if you need precise control over line spacing, such as for dense layouts or specific design requirements.
§Example
use tessera_ui_basic_components::text::TextArgsBuilder;
use tessera_ui::Dp;
// Automatic line height (1.2 × size)
let auto = TextArgsBuilder::default()
.text("Auto spacing".to_string())
.size(Dp(20.0)) // line_height will be Dp(24.0)
.build()
.unwrap();
// Custom line height
let custom = TextArgsBuilder::default()
.text("Custom spacing".to_string())
.size(Dp(20.0))
.line_height(Dp(30.0)) // Explicit line height
.build()
.unwrap();
Trait Implementations§
Source§impl From<&str> for TextArgs
Converts a string slice (&str
) into TextArgs
using the builder pattern.
impl From<&str> for TextArgs
Converts a string slice (&str
) into TextArgs
using the builder pattern.
Auto Trait Implementations§
impl Freeze for TextArgs
impl RefUnwindSafe for TextArgs
impl Send for TextArgs
impl Sync for TextArgs
impl Unpin for TextArgs
impl UnwindSafe for TextArgs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.