Skip to main content

TextBuilder

Struct TextBuilder 

Source
pub struct TextBuilder { /* private fields */ }
Expand description

Build a styled paragraph run by run (docs/text-runs.md).

A builder exists because byte ranges are error-prone to write by hand and meaningless to read: TextRun { range: 12..19, .. } says nothing about which word it covers. Appending text and its style together keeps the two from drifting apart.

ⓘ
label("").runs_from(
    TextBuilder::new()
        .text("Saved to ")
        .code("~/Documents")
        .text(" just now — ")
        .strong("do not close")
        .text(" the window."),
)

Implementations§

Source§

impl TextBuilder

Source

pub fn new() -> Self

Source

pub fn base(self, font: Font) -> Self

The style the emphasis variants build on. Set it to the label’s font so a bold run inside a Footnote paragraph stays footnote-sized.

Source

pub fn text(self, s: &str) -> Self

Unstyled text: it draws with the label’s own font.

Source

pub fn run(self, s: &str, run: impl FnOnce(Range<usize>) -> TextRun) -> Self

A run with a fully specified style.

Source

pub fn strong(self, s: &str) -> Self

Bold.

Source

pub fn emphasis(self, s: &str) -> Self

Italic.

Source

pub fn code(self, s: &str) -> Self

Inline code: the platform’s monospaced face at this style’s size.

Source

pub fn colored(self, s: &str, color: Color) -> Self

A colored phrase.

Source

pub fn underline(self, s: &str) -> Self

Underlined.

Source

pub fn highlight(self, s: &str, color: Color) -> Self

Highlighted: a color painted behind the glyphs, for a search hit or a review mark.

Sets the foreground too, through the same readable-on-a-fill rule Button::tint uses: a highlight is usually a pale wash, and the label’s own text color is chosen for the window’s background rather than for the swatch now sitting under it. On a dark theme that pairing puts light text on pale amber, which is the one combination a highlight must not produce. Use TextBuilder::run where an app wants to state both itself.

Source

pub fn sized(self, s: &str, scale: f64) -> Self

A relative size: 1.5 is half again the base style’s, 0.8 smaller (FontSpec::scale). Relative rather than a point size so the phrase still tracks the reader’s accessibility text-size setting.

Source

pub fn strikethrough(self, s: &str) -> Self

Struck through.

A link run. A #route target navigates in-app, as with link. Rendering it is Cap::TextRuns; activating it is Cap::TextLinks, which fewer backends have, so check before relying on the tap (docs/text-runs.md).

Source

pub fn build(self) -> (String, Vec<TextRun>)

The assembled text and its runs.

Trait Implementations§

Source§

impl Clone for TextBuilder

Source§

fn clone(&self) -> TextBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextBuilder

Source§

fn default() -> TextBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoReactive<T, StaticMark> for T
where T: Clone + 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Day API ↩ Guides· daybrite.dev