Skip to main content

WearTextStyle

Struct WearTextStyle 

Source
pub struct WearTextStyle {
    pub size_sp: f32,
    pub line_height_sp: f32,
    pub weight: u16,
    pub tracking_sp: f32,
    pub align: TextAlign,
}
Expand description

One of Wear Material 3’s type-scale entries.

size and line_height are in sp; tracking is letter spacing in sp. weight is both the FontWeight and the wght variation axis — the tokens set them to the same number.

align is not part of Wear’s type scale — every token leaves it unset and a call site states it. It lives here anyway because the alternative is for every caller to reach into the resolved TextStyle’s paragraph style and overwrite one field, which is how a type scale stops being the thing that describes the text.

Fields§

§size_sp: f32§line_height_sp: f32§weight: u16§tracking_sp: f32§align: TextAlign

TextAlign::Unspecified on every scale entry, as in the tokens.

Implementations§

Source§

impl WearTextStyle

Source

pub const BRAND_FAMILY: FontFamily = FontFamily::SansSerif

The family Wear’s type scale resolves to on a real device.

Wear’s TypefaceTokens.Brand is DeviceFontFamilyName("roboto-flex"), and naming that here would be the faithful-looking answer and the wrong one. On the Wear OS 5 system image these widgets are measured against, /system/etc/fonts.xml declares a roboto-flex family whose every entry points at RobotoFlex-Regular.ttfa file the image does not ship. A family whose files cannot be opened is dropped, so the token does not resolve and the platform falls back to sans-serif, which is Roboto. That is what the pixels show, and it is what this names.

Naming a family at all is not optional. A TextStyle that leaves font_family as None only draws if some face happens to answer for the default, and an app that registers the system fonts under their own families — which is what a port matching Android’s text has to do — has no such face. The text then measures, lays out and rasterises to nothing: a screen with correct geometry and no glyphs on it.

Source

pub const TITLE_MEDIUM: Self

titleMedium — what a ListHeader draws with.

Source

pub const LABEL_MEDIUM: Self

labelMedium — a Button label and a SwitchButton label.

Source

pub const LABEL_SMALL: Self

labelSmall — a secondary label.

Source

pub const BODY_LARGE: Self

bodyLarge — the theme default, which a bare Text inherits. Note that a bare Text that overrides only its fontSize keeps this line height: a 12sp glyph in an 18sp line box is a real Wear screen, not a mistake to unify away.

Source

pub const fn at_size(self, size_sp: f32) -> Self

The same style at another glyph size, keeping the line height.

This is the shape of Wear’s Text(text, fontSize = 12.sp) — an override of the size alone.

Source

pub const fn with_line_height(self, line_height_sp: f32) -> Self

The same style with its line height stated outright.

Source

pub const fn aligned(self, align: TextAlign) -> Self

The same style aligned in its own width.

Wear’s own Text(text, textAlign = TextAlign.Center) — the shape every credit line and every centred blurb on a watch screen takes.

Source

pub fn resolve(self, color: Color) -> TextStyle

The Cranpose TextStyle this entry resolves to.

The sizes stay in Sp, so the framework applies the user’s text-size setting once, at measure time. Pre-scaling them here and handing the result to a Text would apply it twice.

Source

pub fn resolve_in(self, color: Color, family: FontFamily) -> TextStyle

The same, drawn in a family the caller names.

For a device whose roboto-flex really does resolve, or an app that registered Wear’s brand face under a name of its own.

Trait Implementations§

Source§

impl Clone for WearTextStyle

Source§

fn clone(&self) -> WearTextStyle

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 Copy for WearTextStyle

Source§

impl Debug for WearTextStyle

Source§

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

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

impl PartialEq for WearTextStyle

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for WearTextStyle

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<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> 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> 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, 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.