Skip to main content

TextStyle

Struct TextStyle 

Source
pub struct TextStyle {
Show 23 fields pub inherit: bool, pub color: Option<AnyColor>, pub background_color: Option<AnyColor>, pub font_family: Option<String>, pub font_size: Option<f64>, pub font_weight: Option<FontWeight>, pub font_style: Option<FontStyle>, pub letter_spacing: Option<f64>, pub word_spacing: Option<f64>, pub text_baseline: Option<TextBaseline>, pub height: Option<f64>, pub leading_distribution: Option<TextLeadingDistribution>, pub foreground: Option<Rc<Paint>>, pub background: Option<Rc<Paint>>, pub decoration: Option<TextDecoration>, pub decoration_color: Option<AnyColor>, pub decoration_style: Option<TextDecorationStyle>, pub decoration_thickness: Option<f64>, pub debug_label: Option<String>, pub shadows: Option<Vec<Shadow>>, pub font_features: Option<Vec<FontFeature>>, pub font_variations: Option<Vec<FontVariation>>, pub overflow: Option<TextOverflow>, /* private fields */
}
Expand description

An immutable style describing how to format and paint text.

Fields§

§inherit: bool

Whether null values in this TextStyle can be replaced with their value in another TextStyle using merge.

§color: Option<AnyColor>

The color to use when painting the text.

If foreground is specified, this value must be None. The color property is shorthand for Paint()..color = color.

§background_color: Option<AnyColor>

The color to use as the background for the text.

§font_family: Option<String>

The name of the font to use when painting the text (e.g., Roboto).

If the font is defined in a package, this is prefixed with packages/package_name/.

§font_size: Option<f64>

The size of fonts (in logical pixels) to use when painting the text.

§font_weight: Option<FontWeight>

The typeface thickness to use when painting the text (e.g., bold).

§font_style: Option<FontStyle>

The typeface variant to use when drawing the letters (e.g., italics).

§letter_spacing: Option<f64>

The amount of space (in logical pixels) to add between each letter.

§word_spacing: Option<f64>

The amount of space (in logical pixels) to add at each sequence of white-space (i.e. between each word).

§text_baseline: Option<TextBaseline>

The common baseline that should be aligned between this text span and its parent text span, or, for the root text spans, with the line box.

§height: Option<f64>

The height of this text span, as a multiple of the font size.

§leading_distribution: Option<TextLeadingDistribution>

How the vertical space added by the height multiplier should be distributed over and under the text.

§foreground: Option<Rc<Paint>>

The paint drawn as a foreground for the text.

Shared, as Dart shares the one Paint object: a clone of the style holds the same paint, and == compares paints by identity, as Dart’s Paint has no ==.

§background: Option<Rc<Paint>>

The paint drawn as a background for the text.

Shared and compared by identity, as foreground is.

§decoration: Option<TextDecoration>

The decorations to paint near the text (e.g., an underline).

§decoration_color: Option<AnyColor>

The color in which to paint the text decorations.

§decoration_style: Option<TextDecorationStyle>

The style in which to paint the text decorations (e.g., dashed).

§decoration_thickness: Option<f64>

The thickness of the decoration stroke as a multiplier of the thickness defined by the font.

§debug_label: Option<String>

A human-readable description of this text style.

This property is maintained only in debug builds. It is not considered when comparing text styles using == or compare_to.

§shadows: Option<Vec<Shadow>>

A list of Shadows that will be painted underneath the text.

§font_features: Option<Vec<FontFeature>>

A list of FontFeatures that affect how the font selects glyphs.

§font_variations: Option<Vec<FontVariation>>

A list of FontVariations that affect how a variable font is rendered.

§overflow: Option<TextOverflow>

How visual text overflow should be handled.

Implementations§

Source§

impl TextStyle

Source

pub fn new() -> TextStyle

Creates a text style.

Chain setters for the fields Dart’s constructor takes as named arguments: TextStyle::new().color(c).font_size(14.0).

Source

pub fn inherit(self, inherit: bool) -> TextStyle

Whether null values in this TextStyle can be replaced with their value in another TextStyle using merge.

Source

pub fn color(self, color: impl Into<AnyColor>) -> TextStyle

The color to use when painting the text.

Source

pub fn background_color( self, background_color: impl Into<AnyColor>, ) -> TextStyle

The color to use as the background for the text.

Source

pub fn font_family(self, font_family: impl Into<String>) -> TextStyle

The name of the font to use when painting the text (e.g., Roboto).

Source

pub fn font_family_fallback( self, font_family_fallback: Vec<String>, ) -> TextStyle

The ordered list of font families to fall back on when a glyph cannot be found in a higher priority font family.

Source

pub fn package(self, package: impl Into<String>) -> TextStyle

The package argument must be provided if the font family is defined in a package. It is combined with font_family to set that property.

Source

pub fn font_size(self, font_size: f64) -> TextStyle

The size of fonts (in logical pixels) to use when painting the text.

Source

pub fn font_weight(self, font_weight: FontWeight) -> TextStyle

The typeface thickness to use when painting the text (e.g., bold).

Source

pub fn font_style(self, font_style: FontStyle) -> TextStyle

The typeface variant to use when drawing the letters (e.g., italics).

Source

pub fn letter_spacing(self, letter_spacing: f64) -> TextStyle

The amount of space (in logical pixels) to add between each letter.

Source

pub fn word_spacing(self, word_spacing: f64) -> TextStyle

The amount of space (in logical pixels) to add at each sequence of white-space (i.e. between each word).

Source

pub fn text_baseline(self, text_baseline: TextBaseline) -> TextStyle

The common baseline that should be aligned between this text span and its parent text span.

Source

pub fn height(self, height: f64) -> TextStyle

The height of this text span, as a multiple of the font size.

Source

pub fn leading_distribution( self, leading_distribution: TextLeadingDistribution, ) -> TextStyle

How the vertical space added by the height multiplier should be distributed over and under the text.

Source

pub fn foreground(self, foreground: impl Into<Rc<Paint>>) -> TextStyle

The paint drawn as a foreground for the text.

Source

pub fn background(self, background: impl Into<Rc<Paint>>) -> TextStyle

The paint drawn as a background for the text.

Source

pub fn decoration(self, decoration: TextDecoration) -> TextStyle

The decorations to paint near the text (e.g., an underline).

Source

pub fn decoration_color( self, decoration_color: impl Into<AnyColor>, ) -> TextStyle

The color in which to paint the text decorations.

Source

pub fn decoration_style( self, decoration_style: TextDecorationStyle, ) -> TextStyle

The style in which to paint the text decorations (e.g., dashed).

Source

pub fn decoration_thickness(self, decoration_thickness: f64) -> TextStyle

The thickness of the decoration stroke as a multiplier of the thickness defined by the font.

Source

pub fn debug_label(self, debug_label: impl Into<String>) -> TextStyle

A human-readable description of this text style.

Source

pub fn shadows(self, shadows: Vec<Shadow>) -> TextStyle

A list of Shadows that will be painted underneath the text.

Source

pub fn font_features(self, font_features: Vec<FontFeature>) -> TextStyle

A list of FontFeatures that affect how the font selects glyphs.

Source

pub fn font_variations(self, font_variations: Vec<FontVariation>) -> TextStyle

A list of FontVariations that affect how a variable font is rendered.

Source

pub fn overflow(self, overflow: TextOverflow) -> TextStyle

How visual text overflow should be handled.

Source

pub fn font_family_fallback_list(&self) -> Option<Vec<String>>

The ordered list of font families to fall back on when a glyph cannot be found in a higher priority font family.

If the font is defined in a package, each font family in the list is prefixed with packages/package_name/.

Source

pub fn copy_with(&self) -> TextStyle

Creates a copy of this text style but with the given fields replaced with the new values.

Chain setters: style.copy_with().color(c).

Source

pub fn apply(&self) -> TextStyleApply

Creates a copy of this text style replacing or altering the specified properties.

Chain replacements and factors, then TextStyleApply::into_style. style.apply() with no further setters is Dart apply() with defaults.

Source

pub fn merge(&self, other: Option<&TextStyle>) -> TextStyle

Returns a new text style that is a combination of this style and the given other style.

If other has inherit set to true, its null properties are replaced with the non-null properties of this text style. If other has inherit set to false, returns other unchanged.

Source

pub fn lerp( a: Option<&TextStyle>, b: Option<&TextStyle>, t: f64, ) -> Option<TextStyle>

Interpolate between two text styles for animated transitions.

Source

pub fn get_text_style(&self) -> TextStyle

The style information for text runs, encoded for use by dart:ui.

Source

pub fn get_text_style_with(&self, text_scaler: &TextScaler) -> TextStyle

The style information for text runs, encoded for use by dart:ui, with the font size scaled by text_scaler (Dart’s getTextStyle(textScaler: scaler)).

Source

pub fn get_paragraph_style(&self) -> GetParagraphStyle<'_>

The style information for paragraphs, encoded for use by dart:ui.

Chain optional Dart named arguments, then GetParagraphStyle::build.

Source

pub fn compare_to(&self, other: &TextStyle) -> RenderComparison

Describe the difference between this style and another, in terms of how much damage it will make to the rendering.

Source§

impl TextStyle

Source

pub fn debug_fill_properties_with_prefix( &self, properties: &mut DiagnosticPropertiesBuilder, prefix: &str, )

Dart debugFillProperties(properties, {String prefix = ''}).

TextSpan calls this to add the style’s properties to its own node, where Dart’s InlineSpan.debugFillProperties does.

Trait Implementations§

Source§

impl Animatable<TextStyle> for TextStyleTween

Source§

fn transform(&self, _app: &App, t: f64) -> TextStyle

Returns the value of the object at point t. Read more
Source§

fn evaluate(&self, app: &App, animation: AnyAnimation<f64>) -> T
where Self: Sized,

The current value of this object for the given animation. Read more
Source§

fn animate( self, app: &mut App, parent: Retained<AnyAnimation<f64>>, ) -> Retained<AnyAnimation<T>>
where Self: Sized + Clone + 'static, T: 'static,

Returns a new animation that is driven by the given animation but that takes on values determined by this object. The new animation keeps parent; whoever keeps the result keeps both.
Source§

fn chain<P>(self, parent: P) -> ChainedEvaluation<P, Self>
where Self: Sized + Clone, P: Animatable<f64> + Clone,

Returns a new Animatable whose value is determined by first evaluating the given parent and then evaluating this object at the result.
Source§

impl Clone for TextStyle

Source§

fn clone(&self) -> TextStyle

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 TextStyle

Source§

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

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

impl Default for TextStyle

Source§

fn default() -> TextStyle

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

impl Diagnosticable for TextStyle

Source§

fn to_string_short(&self) -> String

A brief description of this object, usually just the type and the hash.
Source§

fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)

Add additional properties associated with the node.
Source§

fn type_name(&self) -> &'static str

Dart’s Object.runtimeType as diagnostics print it: the last segment of the Rust type path, without generic arguments.
Source§

fn identity_hash(&self) -> u64

Dart’s Object.hashCode as diagnostics print it: the object’s address.
Source§

fn to_diagnostics_node(&self) -> DiagnosticableNode

Returns a debug representation of the object used by debugging tools and by DiagnosticsNode::to_string_deep.
Source§

fn to_diagnostics_node_with( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableNode

Dart toDiagnosticsNode(name:, style:).
Source§

fn to_string(&self) -> String

Dart’s toString: a single-line description with properties and no children. Read more
Source§

fn to_string_at(&self, min_level: DiagnosticLevel) -> String

Dart’s toString(minLevel:).
Source§

impl Display for TextStyle

Dart’s TextStyle.toString, through its diagnostics.

Source§

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

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

impl From<TextStyle> for AnyTextStyle

Source§

fn from(value: TextStyle) -> AnyTextStyle

Converts to this type from the input type.
Source§

impl From<TextStyleApply> for TextStyle

Source§

fn from(apply: TextStyleApply) -> TextStyle

Converts to this type from the input type.
Source§

impl MaybeWidgetStateProperty<TextStyle> for AnyTextStyle

Source§

fn as_widget_state_property( &self, ) -> Option<&dyn WidgetStateProperty<TextStyle>>

The property this value is, if it is one.
Source§

fn from_resolved(value: TextStyle) -> AnyTextStyle

A resolved value as this type (Dart’s T is both).
Source§

impl PartialEq for TextStyle

Source§

fn eq(&self, other: &TextStyle) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl TweenValue for TextStyle

Source§

fn same(&self, other: &TextStyle) -> bool

Dart’s == between a widget’s target value and a tween endpoint.
Source§

impl WidgetStateProperty<TextStyle> for WidgetStateTextStyle

Source§

fn resolve(&self, states: &WidgetStates) -> TextStyle

Returns a value of type T that depends on states. Read more
Source§

fn as_any(&self) -> &dyn Any

Downcast support for Dart’s is checks in ==.
Source§

fn as_mapper(&self) -> Option<&WidgetStateMapper<TextStyle>>

Dart’s other is WidgetStateMapper<T>: the mapper this property is, if it is one, as the private mapper subclasses of WidgetStateColor and the rest are.
Source§

fn eq_property(&self, other: &dyn WidgetStateProperty<TextStyle>) -> bool

Dart’s ==. Identity unless a class overrides it, as WidgetStatePropertyAll and WidgetStateMapper do.
Source§

fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)

Dart’s WidgetStateProperty.debugFillProperties, from Diagnosticable: a property adds its own fields.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>