summaryrefslogtreecommitdiffstats
path: root/core/src/font.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-05-11 16:45:08 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-11 16:45:08 +0200
commit669f7cc74b2e7918e86a8197916f503f2d3d9b93 (patch)
treeacb365358235be6ce115b50db9404d890b6e77a6 /core/src/font.rs
parentbc62013b6cde52174bf4c4286939cf170bfa7760 (diff)
parent63d3fc6996b848e10e77e6924bfebdf6ba82852e (diff)
downloadiced-669f7cc74b2e7918e86a8197916f503f2d3d9b93.tar.gz
iced-669f7cc74b2e7918e86a8197916f503f2d3d9b93.tar.bz2
iced-669f7cc74b2e7918e86a8197916f503f2d3d9b93.zip
Merge pull request #1830 from iced-rs/advanced-text
Advanced text
Diffstat (limited to 'core/src/font.rs')
-rw-r--r--core/src/font.rs111
1 files changed, 97 insertions, 14 deletions
diff --git a/core/src/font.rs b/core/src/font.rs
index d8c34e5a..bb425fd6 100644
--- a/core/src/font.rs
+++ b/core/src/font.rs
@@ -1,19 +1,102 @@
+//! Load and use fonts.
+use std::hash::Hash;
+
/// A font.
-#[derive(Debug, Clone, Copy, Default)]
-pub enum Font {
- /// The default font.
- ///
- /// This is normally a font configured in a renderer or loaded from the
- /// system.
+#[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,
+ /// The [`Stretch`] of the [`Font`].
+ pub stretch: Stretch,
+ /// 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,
+ stretch: Stretch::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),
+
+ /// Serif fonts represent the formal text style for a script.
+ Serif,
+
+ /// 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]
- Default,
+ SansSerif,
+
+ /// Glyphs in cursive fonts generally use a more informal script style, and
+ /// the result looks more like handwritten pen or brush writing than printed
+ /// letterwork.
+ Cursive,
+
+ /// Fantasy fonts are primarily decorative or expressive fonts that contain
+ /// decorative or expressive representations of characters.
+ Fantasy,
+
+ /// The sole criterion of a monospace font is that all glyphs have the same
+ /// fixed width.
+ Monospace,
+}
- /// An external font.
- External {
- /// The name of the external font
- name: &'static str,
+/// The weight of some text.
+#[allow(missing_docs)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
+pub enum Weight {
+ Thin,
+ ExtraLight,
+ Light,
+ #[default]
+ Normal,
+ Medium,
+ Semibold,
+ Bold,
+ ExtraBold,
+ Black,
+}
- /// The bytes of the external font
- bytes: &'static [u8],
- },
+/// The width of some text.
+#[allow(missing_docs)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
+pub enum Stretch {
+ UltraCondensed,
+ ExtraCondensed,
+ Condensed,
+ SemiCondensed,
+ #[default]
+ Normal,
+ SemiExpanded,
+ Expanded,
+ ExtraExpanded,
+ UltraExpanded,
}