Skip to main content

Text

Enum Text 

Source
pub enum Text {
    Fine,
    Note,
    Body,
    Lead,
    Subhead,
    Head,
    Title,
    Display,
    Hero,
}
Expand description

What a piece of text is, from which its size follows.

The type axis, and the same move Gap makes on the spacing axis: name the role and let the size follow, so the choice is reviewable. Whether a caption should be 13px or 14px is unanswerable in isolation; whether a piece of text is a caption is not.

§Why the ratios are their own ramp

Type does not reuse Step. The spacing scale is built in eighths of the base because that is what the HIG’s distances land on, and a type ramp needs different rungs — 7/8 and 9/8 sit either side of body copy and have no spacing meaning at all, while Hair and Tight are far below any legible size. Sharing the enum would have meant widening it for rungs spacing never asks for.

What is shared is the thing that matters: every rung here is a Ratio of --geometry-base, so text tracks the user’s chosen root size exactly as spacing does, and one knob still moves the whole design.

§Why the floor is 3/4

Twelve pixels at the default base, and nothing below it. Sizes under that are a legibility problem rather than a tier, and a scale that offers one is a scale that invites it. Text that needs to recede should recede by colour or weight, which cost no legibility.

§Why type does not shift on touch

Density is a claim about the contact patch and nothing else, and text is not a tap target. The reader’s own root font size is already the knob for how large text should be, and it already moves this whole ramp. So the type axis is density-invariant, and a phone gets the same tiers a desktop does.

Variants§

§

Fine

Three quarters of the base. Timestamps, badges, legal lines.

§

Note

Seven eighths of the base. Secondary text: metadata, table cells, captions, form help.

§

Body

The base itself. Running copy, and the size everything else is read against.

§

Lead

Nine eighths of the base. Emphasised copy: intros, card titles.

§

Subhead

Five quarters of the base. The third heading level.

§

Head

One and a half times the base. Section headings, the second level.

§

Title

Twice the base. The page’s own title, the first level.

§

Display

Two and a half times the base. Display copy, above the document hierarchy rather than at the top of it.

§

Hero

Three times the base. One per page at most: a landing hero.

Implementations§

Source§

impl Text

Source

pub const fn ratio(self) -> Ratio

This role’s size as a fraction of the base unit.

Source

pub const fn px(self) -> u16

Size in CSS pixels at the default base.

Source

pub const fn token(self) -> &'static str

The CSS custom-property name, without the leading --.

Source

pub const fn all() -> [Self; 9]

Every role, smallest first.

Trait Implementations§

Source§

impl Clone for Text

Source§

fn clone(&self) -> Text

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 Text

Source§

impl Debug for Text

Source§

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

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

impl Eq for Text

Source§

impl Hash for Text

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Text

Source§

fn eq(&self, other: &Text) -> 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 Text

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnsafeUnpin 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> 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.