diff options
author | 2023-03-30 00:56:00 +0200 | |
---|---|---|
committer | 2023-03-30 00:56:00 +0200 | |
commit | 707de9d788dc3c49d4ac57a19afac1bb938b78d9 (patch) | |
tree | a1f38efa232742f375afae751d433276a83f7e49 /core/src/font.rs | |
parent | 472fbdf1875e82bc89ac0bbd4b2ff09cae1d9620 (diff) | |
download | iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.tar.gz iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.tar.bz2 iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.zip |
Introduce support for `Font` attributes
Diffstat (limited to 'core/src/font.rs')
-rw-r--r-- | core/src/font.rs | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/core/src/font.rs b/core/src/font.rs index b67c08af..920b3dd5 100644 --- a/core/src/font.rs +++ b/core/src/font.rs @@ -2,8 +2,44 @@ use std::hash::Hash; /// A font. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum Font { +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] +pub struct Font { + /// The [`Family`] of the [`Font`]. + pub family: Family, + /// The [`Weight`] of the [`Font`]. + pub weight: Weight, + /// Whether if the [`Font`] is monospaced or not. + pub monospaced: bool, +} + +impl Font { + /// A non-monospaced sans-serif font with normal [`Weight`]. + pub const DEFAULT: Font = Font { + family: Family::SansSerif, + weight: Weight::Normal, + monospaced: false, + }; + + /// A monospaced font with normal [`Weight`]. + pub const MONOSPACE: Font = Font { + family: Family::Monospace, + monospaced: true, + ..Self::DEFAULT + }; + + /// Creates a non-monospaced [`Font`] with the given [`Family::Name`] and + /// normal [`Weight`]. + pub const fn with_name(name: &'static str) -> Self { + Font { + family: Family::Name(name), + ..Self::DEFAULT + } + } +} + +/// A font family. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] +pub enum Family { /// The name of a font family of choice. Name(&'static str), @@ -13,6 +49,7 @@ pub enum Font { /// Glyphs in sans-serif fonts, as the term is used in CSS, are generally low /// contrast and have stroke endings that are plain — without any flaring, /// cross stroke, or other ornamentation. + #[default] SansSerif, /// Glyphs in cursive fonts generally use a more informal script style, and @@ -31,11 +68,12 @@ pub enum Font { /// The weight of some text. #[allow(missing_docs)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] pub enum Weight { Thin, ExtraLight, Light, + #[default] Normal, Medium, Semibold, |