Struct zng_wgt_text::Text

source ·
pub struct Text(/* private fields */);
Expand description

W A configured text run.

§Examples

let hello_txt = Text! {
    font_family = "Arial";
    font_size = 18;
    txt = "Hello!";
};

§Shorthand

The Text! macro provides shorthand syntax that matches the formatx! input, but outputs a text widget:

let txt = Text!("Hello!");

let name = "World";
let fmt = Text!("Hello {}!", name);

let expr = Text!({
    let mut s = String::new();
    s.push('a');
    s
});

The code abode is equivalent to:

let txt = Text! {
    txt = formatx!("Hello!");
};

let name = "World";
let fmt = Text! {
    txt = formatx!("Hello {}!", name);
};

let expr = Text! {
    txt = {
        let mut s = String::new();
        s.push('a');
        s
    };
};

Implementations§

source§

impl Text

source

pub fn widget_new() -> Self

Start building a new instance.

source

pub fn widget_type() -> WidgetType

Gets the widget type info.

source§

impl Text

source

pub fn context_vars_set(set: &mut ContextValueSet)

Context variables used by properties in text.

source§

impl Text

source

pub fn txt(&self, txt: impl IntoVar<Txt>)

c The text string.

Set to an empty string ("") by default.

source§

impl Text

source

pub fn txt_parse<T>(&self, value: impl IntoVar<T>)
where T: TxtParseValue,

P Value that is parsed from the text and displayed as the text.

This is an alternative to txt that converts to and from T if it can be formatted to display text and can parse, with parse error that can display.

If the parse operation fails the value variable is not updated and the error display text is set in DATA.invalidate, you can use has_data_error and get_data_error_txt to display the error.

See also txt_parse_live for ways to control when the parse attempt happens.

Methods from Deref<Target = FontMix<TextFillMix<TextAlignMix<TextWrapMix<TextDecorationMix<TextSpacingMix<TextTransformMix<LangMix<FontFeaturesMix<TextEditMix<SelectionToolbarMix<TextInspectMix<WidgetBase>>>>>>>>>>>>>§

source

pub fn font_family(&self, names: impl IntoVar<FontNames>)

P Font family name or list of names for texts in this widget or descendants.

All fonts in the list are resolved according to the font_style, font_weight and font_stretch config. During text shaping the first font on the list is preferred, but if the font does not cover a character or word, that character or word to the second font in the list and so on.

Sets the FONT_FAMILY_VAR.

source

pub fn font_size(&self, size: impl IntoVar<FontSize>)

P Sets the font size for the widget and descendants.

This property affects all texts inside the widget and the Length::Em unit.

Sets the FONT_SIZE_VAR context var and the LayoutMetrics::font_size.

source

pub fn font_weight(&self, weight: impl IntoVar<FontWeight>)

P Defines the thickness or boldness the preferred font should have.

This value influences font resolution, the variant within the font family that is closest to this config will be selected.

Sets the FONT_WEIGHT_VAR.

source

pub fn font_style(&self, style: impl IntoVar<FontStyle>)

P Defines the skew style of the font glyphs.

This value influences font resolution, the variant within the font family that is closest to this config will be selected.

Sets the FONT_STYLE_VAR.

source

pub fn font_stretch(&self, stretch: impl IntoVar<FontStretch>)

P Defines how condensed or expanded the preferred font should be.

This value influences font resolution, the variant within the font family that is closest to this config will be selected.

Sets the FONT_STRETCH_VAR.

source

pub fn font_synthesis(&self, enabled: impl IntoVar<FontSynthesis>)

P Configure if a synthetic font is generated for fonts that do not implement bold or oblique variants.

Not all fonts implement the requested font_weight and font_style, this config allows the renderer to try and generate the style and weight anyway, using transforms and the glyph outlines.

Sets the FONT_SYNTHESIS_VAR.

source

pub fn font_aa(&self, aa: impl IntoVar<FontAntiAliasing>)

P Configure the anti-aliasing used to render text glyphs inside the widget.

Uses the operating system configuration by default.

Sets the FONT_AA_VAR.

Trait Implementations§

source§

impl Deref for Text

source§

impl DerefMut for Text

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl !Freeze for Text

§

impl !RefUnwindSafe for Text

§

impl Send for Text

§

impl !Sync for Text

§

impl Unpin for Text

§

impl !UnwindSafe for Text

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

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

§

impl<T> MaybeSendSync for T