feat: helper for loading fonts
This commit is contained in:
parent
0c1396cac3
commit
eb0fcf5278
3 changed files with 19 additions and 15 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
/// Copyright 2022 System76 <info@system76.com>
|
/// Copyright 2022 System76 <info@system76.com>
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
|
font::load_fonts,
|
||||||
iced::{self, Application, Command, Length, Subscription},
|
iced::{self, Application, Command, Length, Subscription},
|
||||||
iced::{
|
iced::{
|
||||||
subscription,
|
subscription,
|
||||||
|
|
@ -196,6 +197,7 @@ pub enum Message {
|
||||||
ToggleNavBar,
|
ToggleNavBar,
|
||||||
ToggleNavBarCondensed,
|
ToggleNavBarCondensed,
|
||||||
ToggleWarning,
|
ToggleWarning,
|
||||||
|
FontsLoaded,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Page> for Message {
|
impl From<Page> for Message {
|
||||||
|
|
@ -343,7 +345,7 @@ impl Application for Window {
|
||||||
window.insert_page(Page::Accessibility);
|
window.insert_page(Page::Accessibility);
|
||||||
window.insert_page(Page::Applications);
|
window.insert_page(Page::Applications);
|
||||||
|
|
||||||
(window, Command::none())
|
(window, load_fonts().map(|_| Message::FontsLoaded))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn title(&self) -> String {
|
fn title(&self) -> String {
|
||||||
|
|
@ -422,6 +424,7 @@ impl Application for Window {
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Message::ToggleWarning => self.toggle_warning(),
|
Message::ToggleWarning => self.toggle_warning(),
|
||||||
|
Message::FontsLoaded => {}
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
iced
2
iced
|
|
@ -1 +1 @@
|
||||||
Subproject commit 75ec39407e2339d5fa10124ff371de39ee1794c8
|
Subproject commit 6c2def56acca6acc64a2ea06e2712c4337d9ee09
|
||||||
27
src/font.rs
27
src/font.rs
|
|
@ -2,23 +2,24 @@
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
pub use iced::Font;
|
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::with_name("Fira Sans Regular");
|
||||||
// pub const FONT: Font = Font::External {
|
pub const FONT_DATA: &[u8] = include_bytes!("../res/Fira/FiraSans-Regular.otf");
|
||||||
// name: "Fira Sans Regular",
|
|
||||||
// bytes: include_bytes!("../res/Fira/FiraSans-Regular.otf"),
|
|
||||||
// };
|
|
||||||
|
|
||||||
pub const FONT_LIGHT: Font = Font::with_name("Fira Sans Light");
|
pub const FONT_LIGHT: Font = Font::with_name("Fira Sans Light");
|
||||||
|
pub const FONT_LIGHT_DATA: &[u8] = include_bytes!("../res/Fira/FiraSans-Light.otf");
|
||||||
// pub const FONT_LIGHT: Font = Font::External {
|
|
||||||
// name: "Fira Sans Light",
|
|
||||||
// bytes: include_bytes!("../res/Fira/FiraSans-Light.otf"),
|
|
||||||
// };
|
|
||||||
|
|
||||||
pub const FONT_SEMIBOLD: Font = Font::with_name("Fira Sans SemiBold");
|
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 {
|
pub fn load_fonts() -> Command<Result<(), Error>> {
|
||||||
// name: "Fira Sans SemiBold",
|
Command::batch(vec![
|
||||||
// bytes: include_bytes!("../res/Fira/FiraSans-SemiBold.otf"),
|
load(FONT_DATA),
|
||||||
// };
|
load(FONT_LIGHT_DATA),
|
||||||
|
load(FONT_SEMIBOLD_DATA),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue