diff options
author | 2023-03-30 00:56:00 +0200 | |
---|---|---|
committer | 2023-03-30 00:56:00 +0200 | |
commit | 707de9d788dc3c49d4ac57a19afac1bb938b78d9 (patch) | |
tree | a1f38efa232742f375afae751d433276a83f7e49 /wgpu | |
parent | 472fbdf1875e82bc89ac0bbd4b2ff09cae1d9620 (diff) | |
download | iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.tar.gz iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.tar.bz2 iced-707de9d788dc3c49d4ac57a19afac1bb938b78d9.zip |
Introduce support for `Font` attributes
Diffstat (limited to 'wgpu')
-rw-r--r-- | wgpu/src/backend.rs | 2 | ||||
-rw-r--r-- | wgpu/src/layer.rs | 2 | ||||
-rw-r--r-- | wgpu/src/settings.rs | 2 | ||||
-rw-r--r-- | wgpu/src/text.rs | 44 |
4 files changed, 36 insertions, 14 deletions
diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 88c58554..9772781a 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -336,7 +336,7 @@ impl iced_graphics::Backend for Backend { } impl backend::Text for Backend { - const ICON_FONT: Font = Font::Name("Iced-Icons"); + const ICON_FONT: Font = Font::with_name("Iced-Icons"); const CHECKMARK_ICON: char = '\u{f00c}'; const ARROW_DOWN_ICON: char = '\u{e800}'; diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index cb9d5e2f..c4723397 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -61,7 +61,7 @@ impl<'a> Layer<'a> { ), color: Color::new(0.9, 0.9, 0.9, 1.0), size: 20.0, - font: Font::Monospace, + font: Font::MONOSPACE, horizontal_alignment: alignment::Horizontal::Left, vertical_alignment: alignment::Vertical::Top, }; diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 7c0750ef..ff041bdf 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -58,7 +58,7 @@ impl Default for Settings { Settings { present_mode: wgpu::PresentMode::AutoVsync, internal_backend: wgpu::Backends::all(), - default_font: Font::SansSerif, + default_font: Font::default(), default_text_size: 16.0, antialiasing: None, } diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index ac116f69..b0b7a198 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -1,6 +1,7 @@ use crate::core::alignment; +use crate::core::font::{self, Font}; use crate::core::text::Hit; -use crate::core::{Font, Point, Rectangle, Size}; +use crate::core::{Point, Rectangle, Size}; use crate::layer::Text; use rustc_hash::{FxHashMap, FxHashSet}; @@ -262,14 +263,28 @@ impl Pipeline { } } -fn to_family(font: Font) -> glyphon::Family<'static> { - match font { - Font::Name(name) => glyphon::Family::Name(name), - Font::SansSerif => glyphon::Family::SansSerif, - Font::Serif => glyphon::Family::Serif, - Font::Cursive => glyphon::Family::Cursive, - Font::Fantasy => glyphon::Family::Fantasy, - Font::Monospace => glyphon::Family::Monospace, +fn to_family(family: font::Family) -> glyphon::Family<'static> { + match family { + font::Family::Name(name) => glyphon::Family::Name(name), + font::Family::SansSerif => glyphon::Family::SansSerif, + font::Family::Serif => glyphon::Family::Serif, + font::Family::Cursive => glyphon::Family::Cursive, + font::Family::Fantasy => glyphon::Family::Fantasy, + font::Family::Monospace => glyphon::Family::Monospace, + } +} + +fn to_weight(weight: font::Weight) -> glyphon::Weight { + match weight { + font::Weight::Thin => glyphon::Weight::THIN, + font::Weight::ExtraLight => glyphon::Weight::EXTRA_LIGHT, + font::Weight::Light => glyphon::Weight::LIGHT, + font::Weight::Normal => glyphon::Weight::NORMAL, + font::Weight::Medium => glyphon::Weight::MEDIUM, + font::Weight::Semibold => glyphon::Weight::SEMIBOLD, + font::Weight::Bold => glyphon::Weight::BOLD, + font::Weight::ExtraBold => glyphon::Weight::EXTRA_BOLD, + font::Weight::Black => glyphon::Weight::BLACK, } } @@ -328,8 +343,15 @@ impl Cache { font_system, key.content, glyphon::Attrs::new() - .family(to_family(key.font)) - .monospaced(matches!(key.font, Font::Monospace)), + .family(to_family(key.font.family)) + .weight(to_weight(key.font.weight)) + .monospaced( + key.font.monospaced + || matches!( + key.font.family, + font::Family::Monospace + ), + ), ); let _ = entry.insert(buffer); |