Skip to main content

LabelExt

Trait LabelExt 

Source
pub trait LabelExt: Sized {
    // Required methods
    fn text_size(self, size: impl Into<Value<f32>>) -> Self;
    fn weight(self, weight: FontWeight) -> Self;
    fn family(self, family: FontFamily<'static>) -> Self;
    fn max_lines(self, max_lines: impl Into<Value<Option<u32>>>) -> Self;
}
Expand description

Builder methods that set the text style of a label element.

Import the trait to use them. The style types the methods name come from this crate, so nothing else is needed:

use smudge_text::FontWeight;
use smudge_text::LabelExt;
use smudge_text::label;

let element = label("Hello").text_size(18.0).weight(FontWeight::SEMI_BOLD);

Every method sets one field of the label’s text style; the remaining fields come from the ambient style at mount. The color the glyphs paint with is a paint property of the node, set with text_color, which needs no import.

Required Methods§

Source

fn text_size(self, size: impl Into<Value<f32>>) -> Self

Sets the font size in logical pixels.

The size changes what the label measures, so the node is laid out again.

Source

fn weight(self, weight: FontWeight) -> Self

Sets the weight the family is matched with.

The weight can change what the label measures, so the node is laid out again.

Source

fn family(self, family: FontFamily<'static>) -> Self

Sets the font family the text resolves to.

The family can change what the label measures, so the node is laid out again.

Source

fn max_lines(self, max_lines: impl Into<Value<Option<u32>>>) -> Self

Caps the lines the label shows at max_lines.

A layout that breaks into more lines, or whose last kept line is wider than the label, keeps its first max_lines and ends the last one with an ellipsis, cut back on a cluster boundary so the whole fits the width the label wraps at. A width below the ellipsis’s own advance leaves it standing alone and past the width. Right-to-left text keeps its first lines without an ellipsis, and so does text in fonts that map neither an ellipsis nor a full stop. None, the default, shows every line. The accessible value keeps the full text either way. The cap can change what the label measures, so the node is laid out again, without shaping the text again.

use smudge_text::LabelExt;
use smudge_text::label;

let capped = label("Hello").max_lines(Some(2));
let uncapped = label("Hello").max_lines(None);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl LabelExt for Element<Label>

Source§

fn text_size(self, size: impl Into<Value<f32>>) -> Self

Source§

fn weight(self, weight: FontWeight) -> Self

Source§

fn family(self, family: FontFamily<'static>) -> Self

Source§

fn max_lines(self, max_lines: impl Into<Value<Option<u32>>>) -> Self

Implementors§