mirror of
https://github.com/danbulant/despot
synced 2026-06-16 13:01:13 +00:00
attempt at fixing font loading (doesn't work yet)
This commit is contained in:
parent
9e47c89a7d
commit
394fcf01e8
2 changed files with 30 additions and 11 deletions
31
src/icons.rs
31
src/icons.rs
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::{LazyLock, OnceLock};
|
||||
|
||||
use cushy::{
|
||||
fonts::LoadedFont,
|
||||
fonts::{FontCollection, LoadedFont},
|
||||
styles::{
|
||||
components::{FontFamily, FontWeight, LineHeight},
|
||||
DynamicComponent, FamilyOwned, FontFamilyList, Weight,
|
||||
|
|
@ -12,13 +12,18 @@ use cushy::{
|
|||
|
||||
static FONT: OnceLock<LoadedFont> = OnceLock::new();
|
||||
|
||||
pub fn load_fonts(cushy: &Cushy) {
|
||||
let font = cushy.fonts().push_unloadable(
|
||||
pub fn load_fonts(/*cushy: &Cushy*/) -> FontCollection {
|
||||
let fonts = FontCollection::default();
|
||||
let font_data = include_bytes!("../fonts/MaterialIcons-Regular.ttf").to_vec();
|
||||
dbg!(font_data.len());
|
||||
let font = fonts.push_unloadable(
|
||||
// include_bytes!("../fonts/MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf").into(),
|
||||
include_bytes!("../fonts/MaterialIcons-Regular.ttf").into(),
|
||||
font_data,
|
||||
);
|
||||
// /home/dan/projects/despot/fonts/MaterialIcons-Regular.ttf
|
||||
println!("loaded");
|
||||
FONT.set(font).map_err(|_| ()).unwrap();
|
||||
fonts
|
||||
}
|
||||
|
||||
fn font_component() -> DynamicComponent {
|
||||
|
|
@ -26,7 +31,9 @@ fn font_component() -> DynamicComponent {
|
|||
move |context| {
|
||||
let font = &FONT.get().unwrap();
|
||||
// dbg!(font);
|
||||
let face = context.loaded_font_faces(font).first()?;
|
||||
let faces = context.loaded_font_faces(font);
|
||||
dbg!(&faces);
|
||||
let face = faces.first()?;
|
||||
dbg!(&face);
|
||||
Some(cushy::styles::Component::custom(FontFamilyList::from(
|
||||
vec![FamilyOwned::Name(face.families[0].0.clone())],
|
||||
|
|
@ -35,11 +42,23 @@ fn font_component() -> DynamicComponent {
|
|||
})
|
||||
}
|
||||
|
||||
fn font_weight_component() -> DynamicComponent {
|
||||
DynamicComponent::new({
|
||||
move |context| {
|
||||
let font = &FONT.get().unwrap();
|
||||
let faces = context.loaded_font_faces(font);
|
||||
let face = faces.first()?;
|
||||
Some(cushy::styles::Component::FontWeight(face.weight))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static FONT_FAMILY_COMPONENT: LazyLock<DynamicComponent> = LazyLock::new(font_component);
|
||||
static FONT_WEIGHT_COMPONENT: LazyLock<DynamicComponent> = LazyLock::new(font_weight_component);
|
||||
|
||||
pub fn icon(str: &str) -> impl MakeWidget {
|
||||
str.with_dynamic(&FontFamily, FONT_FAMILY_COMPONENT.clone())
|
||||
.with(&FontWeight, Weight::NORMAL)
|
||||
.with_dynamic(&FontWeight, FONT_WEIGHT_COMPONENT.clone())
|
||||
}
|
||||
|
||||
pub const SHUFFLE: &str = "\u{e043}";
|
||||
|
|
|
|||
10
src/main.rs
10
src/main.rs
|
|
@ -40,7 +40,6 @@ mod widgets;
|
|||
fn main() -> cushy::Result {
|
||||
let args = Args::parse();
|
||||
let app = PendingApp::new(TokioRuntime::default());
|
||||
load_fonts(app.cushy());
|
||||
|
||||
let token = get_token().unwrap();
|
||||
|
||||
|
|
@ -95,16 +94,17 @@ fn main() -> cushy::Result {
|
|||
|
||||
let selected_page = Dynamic::new(ActivePage::default());
|
||||
|
||||
playlists_widget(playlists.items, selected_page)
|
||||
let mut win = playlists_widget(playlists.items, selected_page)
|
||||
.and(LikedSongsPage::new(context.clone()).into_widget())
|
||||
.into_columns()
|
||||
.expand()
|
||||
.and(bar(dynplayer))
|
||||
.into_rows()
|
||||
.expand()
|
||||
.make_window()
|
||||
.open(&mut app)
|
||||
.unwrap();
|
||||
.into_window();
|
||||
let fonts = load_fonts(/*app.cushy()*/);
|
||||
win.fonts = fonts;
|
||||
win.open(&mut app).unwrap();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue