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
impl TextBuilder
pub fn new() -> TextBuilder
Sourcepub fn base(self, font: Font) -> TextBuilder
pub fn base(self, font: Font) -> TextBuilder
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.
Sourcepub fn text(self, s: &str) -> TextBuilder
pub fn text(self, s: &str) -> TextBuilder
Unstyled text: it draws with the label’s own font.
Sourcepub fn run(
self,
s: &str,
run: impl FnOnce(Range<usize>) -> TextRun,
) -> TextBuilder
pub fn run( self, s: &str, run: impl FnOnce(Range<usize>) -> TextRun, ) -> TextBuilder
A run with a fully specified style.
Sourcepub fn strong(self, s: &str) -> TextBuilder
pub fn strong(self, s: &str) -> TextBuilder
Bold.
Sourcepub fn emphasis(self, s: &str) -> TextBuilder
pub fn emphasis(self, s: &str) -> TextBuilder
Italic.
Sourcepub fn code(self, s: &str) -> TextBuilder
pub fn code(self, s: &str) -> TextBuilder
Inline code: the platform’s monospaced face at this style’s size.
Sourcepub fn colored(self, s: &str, color: Color) -> TextBuilder
pub fn colored(self, s: &str, color: Color) -> TextBuilder
A colored phrase.
Sourcepub fn underline(self, s: &str) -> TextBuilder
pub fn underline(self, s: &str) -> TextBuilder
Underlined.
Sourcepub fn highlight(self, s: &str, color: Color) -> TextBuilder
pub fn highlight(self, s: &str, color: Color) -> TextBuilder
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.
Sourcepub fn sized(self, s: &str, scale: f64) -> TextBuilder
pub fn sized(self, s: &str, scale: f64) -> TextBuilder
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.
Sourcepub fn strikethrough(self, s: &str) -> TextBuilder
pub fn strikethrough(self, s: &str) -> TextBuilder
Struck through.
Trait Implementations§
Source§impl Clone for TextBuilder
impl Clone for TextBuilder
Source§fn clone(&self) -> TextBuilder
fn clone(&self) -> TextBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextBuilder
impl Debug for TextBuilder
Source§impl Default for TextBuilder
impl Default for TextBuilder
Source§fn default() -> TextBuilder
fn default() -> TextBuilder
Auto Trait Implementations§
impl Freeze for TextBuilder
impl RefUnwindSafe for TextBuilder
impl Send for TextBuilder
impl Sync for TextBuilder
impl Unpin for TextBuilder
impl UnsafeUnpin for TextBuilder
impl UnwindSafe for TextBuilder
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> ErasedDestructor for Twhere
T: 'static,
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