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: TextAlignTextAlign::Unspecified on every scale entry, as in the tokens.
Implementations§
Source§impl WearTextStyle
impl WearTextStyle
Sourcepub const BRAND_FAMILY: FontFamily = FontFamily::SansSerif
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.ttf — a 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.
Sourcepub const TITLE_MEDIUM: Self
pub const TITLE_MEDIUM: Self
titleMedium — what a ListHeader draws with.
Sourcepub const LABEL_MEDIUM: Self
pub const LABEL_MEDIUM: Self
labelMedium — a Button label and a SwitchButton label.
Sourcepub const LABEL_SMALL: Self
pub const LABEL_SMALL: Self
labelSmall — a secondary label.
Sourcepub const BODY_LARGE: Self
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.
Sourcepub const fn at_size(self, size_sp: f32) -> Self
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.
Sourcepub const fn with_line_height(self, line_height_sp: f32) -> Self
pub const fn with_line_height(self, line_height_sp: f32) -> Self
The same style with its line height stated outright.
Sourcepub const fn aligned(self, align: TextAlign) -> Self
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.
Sourcepub fn resolve(self, color: Color) -> TextStyle
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.
Sourcepub fn resolve_in(self, color: Color, family: FontFamily) -> TextStyle
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
impl Clone for WearTextStyle
impl Copy for WearTextStyle
Source§impl Debug for WearTextStyle
impl Debug for WearTextStyle
Source§impl PartialEq for WearTextStyle
impl PartialEq for WearTextStyle
impl StructuralPartialEq for WearTextStyle
Auto Trait Implementations§
impl Freeze for WearTextStyle
impl RefUnwindSafe for WearTextStyle
impl Send for WearTextStyle
impl Sync for WearTextStyle
impl Unpin for WearTextStyle
impl UnsafeUnpin for WearTextStyle
impl UnwindSafe for WearTextStyle
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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