fix builtin font handle thingy

This commit is contained in:
griffi-gh 2024-02-21 11:19:14 +01:00
parent f9ea777954
commit f7366b9bbb
4 changed files with 14 additions and 9 deletions

View file

@ -15,8 +15,7 @@ include = [
] ]
[dependencies] [dependencies]
#hack: hui doesn't compile without the builtin_font feature due to a bug hui = { version = "=0.1.0-alpha.4", path = "../hui", default-features = false }
hui = { version = "=0.1.0-alpha.4", path = "../hui", default-features = false, features = ["builtin_font"] }
glium = { version = "0.34", default-features = false } glium = { version = "0.34", default-features = false }
glam = "0.25" glam = "0.25"
log = "0.4" log = "0.4"

View file

@ -1,13 +1,10 @@
use std::borrow::Cow; use std::borrow::Cow;
use glam::{vec2, Vec4}; use glam::{vec2, Vec4};
use crate::{ use crate::{
draw::UiDrawCommand, draw::UiDrawCommand, element::{MeasureContext, ProcessContext, UiElement}, layout::UiSize, measure::Response, text::{FontHandle, DEFAULT_FONT}
element::{MeasureContext, ProcessContext, UiElement},
measure::Response,
text::{FontHandle, BUILTIN_FONT},
layout::UiSize
}; };
//TODO: text fit //TODO: text fit
// pub enum TextSize { // pub enum TextSize {
// FitToWidthRatio(f32), // FitToWidthRatio(f32),
@ -29,7 +26,7 @@ impl Default for Text {
text: "".into(), text: "".into(),
size: (UiSize::Auto, UiSize::Auto), size: (UiSize::Auto, UiSize::Auto),
color: Vec4::new(1., 1., 1., 1.), color: Vec4::new(1., 1., 1., 1.),
font: BUILTIN_FONT, font: DEFAULT_FONT,
text_size: 16, text_size: 16,
} }
} }

View file

@ -4,7 +4,10 @@ mod font;
mod ftm; mod ftm;
use font::FontManager; use font::FontManager;
pub use font::{FontHandle, BUILTIN_FONT}; pub use font::FontHandle;
#[cfg(feature="builtin_font")]
pub use font::BUILTIN_FONT;
pub(crate) use font::DEFAULT_FONT;
use fontdue::{Font, FontSettings}; use fontdue::{Font, FontSettings};
use ftm::FontTextureManager; use ftm::FontTextureManager;
pub use ftm::{FontTextureInfo, GlyphCacheEntry}; pub use ftm::{FontTextureInfo, GlyphCacheEntry};

View file

@ -6,6 +6,12 @@ pub struct FontHandle(pub(crate) usize);
#[cfg(feature = "builtin_font")] #[cfg(feature = "builtin_font")]
pub const BUILTIN_FONT: FontHandle = FontHandle(0); pub const BUILTIN_FONT: FontHandle = FontHandle(0);
pub(crate) const DEFAULT_FONT: FontHandle = {
#[cfg(feature = "builtin_font")] { BUILTIN_FONT }
#[cfg(not(feature = "builtin_font"))] { FontHandle(0) }
};
#[cfg(feature = "builtin_font")] #[cfg(feature = "builtin_font")]
const BUILTIN_FONT_DATA: &[u8] = include_bytes!("../../assets/font/ProggyTiny.ttf"); const BUILTIN_FONT_DATA: &[u8] = include_bytes!("../../assets/font/ProggyTiny.ttf");