Skip to main content

Typography

Struct Typography 

Source
pub struct Typography {
    pub black: Rc<TextTheme>,
    pub white: Rc<TextTheme>,
    pub english_like: Rc<TextTheme>,
    pub dense: Rc<TextTheme>,
    pub tall: Rc<TextTheme>,
}
Expand description

The color and geometry TextThemes for Material apps.

The text theme provided by the overall Theme, ThemeData.text_theme, is based on the current locale’s MaterialLocalizations.script_category and is created by merging a color text theme - black for Brightness::Light themes and white for Brightness::Dark themes - and a geometry text theme, one of english_like, dense, or tall, depending on the locale.

To lookup the localized text theme use Theme::of(app, context).text_theme.

The color text themes are black_mountain_view, white_mountain_view, black_cupertino, and white_cupertino. The Mountain View theme TextStyles are based on the Roboto fonts as used on Android. The Cupertino themes are based on the San Francisco font fonts as used by Apple on iOS.

Three sets of geometry themes are provided: 2014, 2018, and 2021. The 2014 themes correspond to the original version of the Material Design spec. The 2018 themes correspond to the second iteration of the specification and feature different font sizes, font weights, and letter spacing values. The 2021 themes correspond to the Material Design 3 specification.

By default, ThemeData.typography is Typography.material2021(platform: platform, colorScheme: colorScheme) (or Typography.material2014(platform: platform) when ThemeData.use_material3 is false). To use the 2018 text theme geometries, specify a value using the Typography::material2018 constructor:

typography: Typography::material2018().platform(Some(platform)).build()

See also:

Each text theme is shared, as Dart shares the one TextTheme object: a clone holds the same five, and ThemeData::localize keys its cache on the geometry theme’s identity.

Fields§

§black: Rc<TextTheme>

A Material Design text theme with dark glyphs.

This TextTheme should provide color but not geometry (font size, weight, etc). A text theme’s geometry depends on the locale. To look up a localized TextTheme, use the overall Theme, for example: Theme::of(app, context).text_theme.

The english_like, dense, and tall text theme’s provide locale-specific geometry.

§white: Rc<TextTheme>

A Material Design text theme with light glyphs.

This TextTheme provides color but not geometry (font size, weight, etc). A text theme’s geometry depends on the locale. To look up a localized TextTheme, use the overall Theme, for example: Theme::of(app, context).text_theme.

The english_like, dense, and tall text theme’s provide locale-specific geometry.

§english_like: Rc<TextTheme>

Defines text geometry for ScriptCategory::EnglishLike scripts, such as English, French, Russian, etc.

This text theme is merged with either black or white, depending on the overall ThemeData.brightness, when the current locale’s MaterialLocalizations.script_category is ScriptCategory::EnglishLike.

To look up a localized TextTheme, use the overall Theme, for example: Theme::of(app, context).text_theme.

§dense: Rc<TextTheme>

Defines text geometry for dense scripts, such as Chinese, Japanese and Korean.

This text theme is merged with either black or white, depending on the overall ThemeData.brightness, when the current locale’s MaterialLocalizations.script_category is ScriptCategory::Dense.

To look up a localized TextTheme, use the overall Theme, for example: Theme::of(app, context).text_theme.

§tall: Rc<TextTheme>

Defines text geometry for tall scripts, such as Farsi, Hindi, and Thai.

This text theme is merged with either black or white, depending on the overall ThemeData.brightness, when the current locale’s MaterialLocalizations.script_category is ScriptCategory::Tall.

To look up a localized TextTheme, use the overall Theme, for example: Theme::of(app, context).text_theme.

Implementations§

Source§

impl Typography

Source

pub fn new() -> TypographyBuilder

Creates a typography instance.

This constructor is identical to Typography::material2018.

Source

pub fn material2014() -> TypographyBuilder

Creates a typography instance using Material Design’s 2014 defaults.

If platform is TargetPlatform::IOS or TargetPlatform::MacOS, the default values for black and white are black_cupertino and white_cupertino respectively. Otherwise they are black_mountain_view and white_mountain_view. If platform is null then both black and white must be specified.

The default values for english_like, dense, and tall are english_like2014, dense2014, and tall2014.

Source

pub fn material2018() -> TypographyBuilder

Creates a typography instance using Material Design’s 2018 defaults.

If platform is TargetPlatform::IOS or TargetPlatform::MacOS, the default values for black and white are black_cupertino and white_cupertino respectively. Otherwise they are black_mountain_view and white_mountain_view. If platform is null then both black and white must be specified.

The default values for english_like, dense, and tall are english_like2018, dense2018, and tall2018.

Source

pub fn material2021() -> TypographyMaterial2021Builder

Creates a typography instance using Material Design 3 2021 defaults.

Text colors are derived from color_scheme. For a light color_scheme, every style in the resulting black uses ColorScheme.on_surface and every style in white uses ColorScheme.surface. For a dark color_scheme, these are reversed. The same colors are used for TextStyle::decoration_color.

The default values for black and white depend on platform: black_cupertino and white_cupertino on iOS, black_redwood_city and white_redwood_city on macOS, black_redmond and white_redmond on Windows, black_helsinki and white_helsinki on Linux, and black_mountain_view and white_mountain_view otherwise. If platform is null then both black and white must be specified.

The default values for english_like, dense, and tall are english_like2021, dense2021, and tall2021.

The black and white parameters are deprecated. Only their non-color properties (such as font family) are used. Any TextStyle::color or TextStyle::decoration_color they specify is replaced with a color from color_scheme as described above. To customize the text theme’s colors, call copy_with on the result:

let base = Typography::material2021().color_scheme(color_scheme).build();
let typography = base
    .copy_with()
    .black(base.black.merge(Some(&my_black)))
    .white(base.white.merge(Some(&my_white)));

See also:

Source

pub fn geometry_theme_for(&self, category: ScriptCategory) -> &Rc<TextTheme>

Returns one of english_like, dense, or tall.

Source

pub fn copy_with(&self) -> Typography

Creates a copy of this Typography with the given fields replaced by the non-null parameter values.

Dart’s named arguments are the setters on the copy: typography.copy_with().black(text_theme).

Source

pub fn black(self, black: impl Into<Rc<TextTheme>>) -> Typography

Dart copyWith(black:).

Source

pub fn white(self, white: impl Into<Rc<TextTheme>>) -> Typography

Dart copyWith(white:).

Source

pub fn english_like(self, english_like: impl Into<Rc<TextTheme>>) -> Typography

Dart copyWith(englishLike:).

Source

pub fn dense(self, dense: impl Into<Rc<TextTheme>>) -> Typography

Dart copyWith(dense:).

Source

pub fn tall(self, tall: impl Into<Rc<TextTheme>>) -> Typography

Dart copyWith(tall:).

Source

pub fn lerp(a: &Typography, b: &Typography, t: f64) -> Typography

Linearly interpolate between two Typography objects.

{@macro dart.ui.shadow.lerp}

Source

pub fn black_mountain_view() -> TextTheme

A Material Design text theme with dark glyphs based on Roboto.

This TextTheme provides color but not geometry (font size, weight, etc).

Source

pub fn white_mountain_view() -> TextTheme

A Material Design text theme with light glyphs based on Roboto.

This TextTheme provides color but not geometry (font size, weight, etc).

Source

pub fn black_redmond() -> TextTheme

A Material Design text theme with dark glyphs based on Segoe UI.

This TextTheme provides color but not geometry (font size, weight, etc).

Source

pub fn white_redmond() -> TextTheme

A Material Design text theme with light glyphs based on Segoe UI.

This TextTheme provides color but not geometry (font size, weight, etc).

Source

pub fn black_helsinki() -> TextTheme

A Material Design text theme with dark glyphs based on Roboto, with fallback fonts that are likely (but not guaranteed) to be installed on Linux.

This TextTheme provides color but not geometry (font size, weight, etc).

Source

pub fn white_helsinki() -> TextTheme

A Material Design text theme with light glyphs based on Roboto, with fallbacks of DejaVu Sans, Liberation Sans and Arial.

This TextTheme provides color but not geometry (font size, weight, etc).

Source

pub fn black_cupertino() -> TextTheme

A Material Design text theme with dark glyphs based on San Francisco.

This TextTheme provides color but not geometry (font size, weight, etc).

This theme uses the iOS version of the font names.

Source

pub fn white_cupertino() -> TextTheme

A Material Design text theme with light glyphs based on San Francisco.

This TextTheme provides color but not geometry (font size, weight, etc).

This theme uses the iOS version of the font names.

Source

pub fn black_redwood_city() -> TextTheme

A Material Design text theme with dark glyphs based on San Francisco.

This TextTheme provides color but not geometry (font size, weight, etc).

This theme uses the macOS version of the font names.

Source

pub fn white_redwood_city() -> TextTheme

A Material Design text theme with light glyphs based on San Francisco.

This TextTheme provides color but not geometry (font size, weight, etc).

This theme uses the macOS version of the font names.

Source

pub fn english_like2014() -> TextTheme

Defines text geometry for ScriptCategory::EnglishLike scripts, such as English, French, Russian, etc.

Source

pub fn english_like2018() -> TextTheme

Defines text geometry for ScriptCategory::EnglishLike scripts, such as English, French, Russian, etc.

The font sizes, weights, and letter spacings in this version match the 2018 Material Design specification.

Source

pub fn dense2014() -> TextTheme

Defines text geometry for dense scripts, such as Chinese, Japanese and Korean.

Source

pub fn dense2018() -> TextTheme

Defines text geometry for dense scripts, such as Chinese, Japanese and Korean.

The font sizes, weights, and letter spacings in this version match the 2018 Material Design specification.

Source

pub fn tall2014() -> TextTheme

Defines text geometry for tall scripts, such as Farsi, Hindi, and Thai.

Source

pub fn tall2018() -> TextTheme

Defines text geometry for tall scripts, such as Farsi, Hindi, and Thai.

The font sizes, weights, and letter spacings in this version match the 2018 Material Design specification.

Source

pub fn english_like2021() -> TextTheme

Defines text geometry for ScriptCategory::EnglishLike scripts, such as English, French, Russian, etc.

The font sizes, weights, and letter spacings in this version match the 2021 Material Design 3 specification.

Source

pub fn dense2021() -> TextTheme

Defines text geometry for dense scripts, such as Chinese, Japanese and Korean.

The Material Design 3 specification does not include ‘dense’ text themes, so this is just here to be consistent with the API.

Source

pub fn tall2021() -> TextTheme

Defines text geometry for tall scripts, such as Farsi, Hindi, and Thai.

The Material Design 3 specification does not include ‘tall’ text themes, so this is just here to be consistent with the API.

Trait Implementations§

Source§

impl Clone for Typography

Source§

fn clone(&self) -> Self

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 Typography

Source§

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

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

impl Diagnosticable for Typography

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_string_short(&self) -> String

A brief description of this object, usually just the type and the hash.
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 Typography

Source§

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

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

impl PartialEq for Typography

Source§

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

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>