Trait FormattableText

Source
pub trait FormattableText: PartialEq + Debug {
    type FontTokenIter<'a>: Iterator<Item = FontToken>
       where Self: 'a;

    // Required methods
    fn as_str(&self) -> &str;
    fn font_tokens<'a>(&'a self, dpem: f32) -> Self::FontTokenIter<'a>;
    fn effect_tokens(&self) -> &[Effect<()>];

    // Provided method
    fn str_len(&self) -> usize { ... }
}
Expand description

Text, optionally with formatting data

Any F: FormattableText automatically support FormattableTextDyn. Implement either this or FormattableTextDyn, not both.

Required Associated Types§

Source

type FontTokenIter<'a>: Iterator<Item = FontToken> where Self: 'a

Required Methods§

Source

fn as_str(&self) -> &str

Access whole text as contiguous str

Source

fn font_tokens<'a>(&'a self, dpem: f32) -> Self::FontTokenIter<'a>

Construct an iterator over formatting items

It is expected that FontToken::start of yielded items is strictly increasing; if not, formatting may not be applied correctly.

The default font size (dpem) is passed as a reference.

For plain text this iterator will be empty.

Source

fn effect_tokens(&self) -> &[Effect<()>]

Get the sequence of effect tokens

This method has some limitations: (1) it may only return a reference to an existing sequence, (2) effect tokens cannot be generated dependent on input state, and (3) it does not incorporate color information. For most uses it should still be sufficient, but for other cases it may be preferable not to use this method (use a dummy implementation returning &[] and use inherent methods on the text object via Text::text).

Provided Methods§

Source

fn str_len(&self) -> usize

Length of text

Default implementation uses FormattableText::as_str.

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.

Implementations on Foreign Types§

Source§

impl FormattableText for String

Source§

impl<'t> FormattableText for &'t str

Source§

type FontTokenIter<'a> = Empty<FontToken> where &'t str: 'a

Source§

fn as_str(&self) -> &str

Source§

fn font_tokens<'a>( &'a self, _: f32, ) -> <&'t str as FormattableText>::FontTokenIter<'a>

Source§

fn effect_tokens(&self) -> &[Effect<()>]

Implementors§