fix builtin font handle thingy

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

View file

@ -15,8 +15,7 @@ include = [
]
[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, features = ["builtin_font"] }
hui = { version = "=0.1.0-alpha.4", path = "../hui", default-features = false }
glium = { version = "0.34", default-features = false }
glam = "0.25"
log = "0.4"

View file

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

View file

@ -4,7 +4,10 @@ mod font;
mod ftm;
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 ftm::FontTextureManager;
pub use ftm::{FontTextureInfo, GlyphCacheEntry};

View file

@ -6,6 +6,12 @@ pub struct FontHandle(pub(crate) usize);
#[cfg(feature = "builtin_font")]
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")]
const BUILTIN_FONT_DATA: &[u8] = include_bytes!("../../assets/font/ProggyTiny.ttf");