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
impl Text
sourcepub fn widget_new() -> Text
pub fn widget_new() -> Text
Start building a new instance.
sourcepub fn widget_type() -> WidgetType
pub fn widget_type() -> WidgetType
Gets the widget type info.
source§impl Text
impl Text
sourcepub fn context_vars_set(set: &mut ContextValueSet)
pub fn context_vars_set(set: &mut ContextValueSet)
Context variables used by properties in text.
source§impl Text
impl Text
sourcepub fn txt_parse<T>(&self, value: impl IntoVar<T>)where
T: TxtParseValue,
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>>>>>>>>>>>>>§
sourcepub fn font_family(&self, names: impl IntoVar<FontNames>)
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
.
sourcepub fn font_size(&self, size: impl IntoVar<Length>)
pub fn font_size(&self, size: impl IntoVar<Length>)
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
.
sourcepub fn font_weight(&self, weight: impl IntoVar<FontWeight>)
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
.
sourcepub fn font_style(&self, style: impl IntoVar<FontStyle>)
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
.
sourcepub fn font_stretch(&self, stretch: impl IntoVar<FontStretch>)
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
.
sourcepub fn font_synthesis(&self, enabled: impl IntoVar<FontSynthesis>)
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
.
sourcepub fn font_aa(&self, aa: impl IntoVar<FontAntiAliasing>)
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
impl Deref for Text
source§type Target = FontMix<TextFillMix<TextAlignMix<TextWrapMix<TextDecorationMix<TextSpacingMix<TextTransformMix<LangMix<FontFeaturesMix<TextEditMix<SelectionToolbarMix<TextInspectMix<WidgetBase>>>>>>>>>>>>
type Target = FontMix<TextFillMix<TextAlignMix<TextWrapMix<TextDecorationMix<TextSpacingMix<TextTransformMix<LangMix<FontFeaturesMix<TextEditMix<SelectionToolbarMix<TextInspectMix<WidgetBase>>>>>>>>>>>>
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> 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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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