From eb0fcf5278337fbf919f48198b0ebb9eafcfc4a6 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 10 May 2023 13:15:56 -0400 Subject: [PATCH] feat: helper for loading fonts --- examples/cosmic/src/window.rs | 5 ++++- iced | 2 +- src/font.rs | 27 ++++++++++++++------------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/cosmic/src/window.rs b/examples/cosmic/src/window.rs index 5e32c6d6..de94840c 100644 --- a/examples/cosmic/src/window.rs +++ b/examples/cosmic/src/window.rs @@ -1,6 +1,7 @@ /// Copyright 2022 System76 // SPDX-License-Identifier: MPL-2.0 use cosmic::{ + font::load_fonts, iced::{self, Application, Command, Length, Subscription}, iced::{ subscription, @@ -196,6 +197,7 @@ pub enum Message { ToggleNavBar, ToggleNavBarCondensed, ToggleWarning, + FontsLoaded, } impl From for Message { @@ -343,7 +345,7 @@ impl Application for Window { window.insert_page(Page::Accessibility); window.insert_page(Page::Applications); - (window, Command::none()) + (window, load_fonts().map(|_| Message::FontsLoaded)) } fn title(&self) -> String { @@ -422,6 +424,7 @@ impl Application for Window { _ => (), }, Message::ToggleWarning => self.toggle_warning(), + Message::FontsLoaded => {} } ret } diff --git a/iced b/iced index 75ec3940..6c2def56 160000 --- a/iced +++ b/iced @@ -1 +1 @@ -Subproject commit 75ec39407e2339d5fa10124ff371de39ee1794c8 +Subproject commit 6c2def56acca6acc64a2ea06e2712c4337d9ee09 diff --git a/src/font.rs b/src/font.rs index aed48d59..8a2a4cc6 100644 --- a/src/font.rs +++ b/src/font.rs @@ -2,23 +2,24 @@ // SPDX-License-Identifier: MPL-2.0 pub use iced::Font; +use iced::{ + font::{load, Error}, + Command, +}; pub const FONT: Font = Font::with_name("Fira Sans Regular"); -// pub const FONT: Font = Font::External { -// name: "Fira Sans Regular", -// bytes: include_bytes!("../res/Fira/FiraSans-Regular.otf"), -// }; +pub const FONT_DATA: &[u8] = include_bytes!("../res/Fira/FiraSans-Regular.otf"); pub const FONT_LIGHT: Font = Font::with_name("Fira Sans Light"); - -// pub const FONT_LIGHT: Font = Font::External { -// name: "Fira Sans Light", -// bytes: include_bytes!("../res/Fira/FiraSans-Light.otf"), -// }; +pub const FONT_LIGHT_DATA: &[u8] = include_bytes!("../res/Fira/FiraSans-Light.otf"); pub const FONT_SEMIBOLD: Font = Font::with_name("Fira Sans SemiBold"); +pub const FONT_SEMIBOLD_DATA: &[u8] = include_bytes!("../res/Fira/FiraSans-SemiBold.otf"); -// pub const FONT_SEMIBOLD: Font = Font::External { -// name: "Fira Sans SemiBold", -// bytes: include_bytes!("../res/Fira/FiraSans-SemiBold.otf"), -// }; +pub fn load_fonts() -> Command> { + Command::batch(vec![ + load(FONT_DATA), + load(FONT_LIGHT_DATA), + load(FONT_SEMIBOLD_DATA), + ]) +}