1
1
Fork 0
mirror of https://github.com/griffi-gh/hUI.git synced 2025-04-07 16:36:27 -05:00

It compiles

This commit is contained in:
griffi-gh 2025-03-11 10:31:42 +01:00
parent e8851ee356
commit 6fd0402a28
9 changed files with 42 additions and 15 deletions
hui-glium
hui-painter
hui

View file

@ -16,7 +16,6 @@ include = [
]
[dependencies]
# hui = { version = "=0.1.0-alpha.6", path = "../hui", default-features = false }
hui-painter = { version = "=0.1.0-alpha.6", path = "../hui-painter", default-features = false }
glium = { version = "0.36", default-features = false }
glam = "0.30"

View file

@ -10,6 +10,7 @@ edition = "2024"
license = "GPL-3.0-or-later"
publish = true
include = [
"assets/**/*",
"src/**/*.rs",
"Cargo.toml",
]
@ -23,3 +24,7 @@ hashbrown = "0.15"
nohash-hasher = "0.2"
fontdue = "0.9"
rustc-hash = "2.0"
[features]
default = ["default-font"]
default-font = []

View file

@ -69,6 +69,9 @@ impl PaintCommand for PaintText {
let layout = self.build_layout(&font_array);
for glyph in layout.glyphs() {
if !glyph.char_data.rasterize() {
continue;
}
ctx.fonts.render_glyph(&mut ctx.textures, self.text.font, glyph.key);
}
}

View file

@ -4,7 +4,7 @@ use crate::texture::{TextureAtlas, TextureHandle};
pub(crate) mod ftm;
pub(crate) mod font;
pub use font::FontHandle;
pub use font::{FontHandle, DEFAULT_FONT};
pub struct FontManager {
fonts: font::FontHandleManager,
@ -13,10 +13,15 @@ pub struct FontManager {
impl FontManager {
pub fn new() -> Self {
Self {
let mut this = Self {
fonts: font::FontHandleManager::new(),
ftm: ftm::FontTextureManager::new(),
};
#[cfg(feature="default-font")] {
this.fonts.idc = 0;
this.add(include_bytes!("../assets/font/ProggyTiny.ttf"));
}
this
}
/// Add a font to the manager from raw font file data.

View file

@ -2,23 +2,32 @@ use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher;
pub(crate) type FontId = u16;
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub struct FontHandle(pub(crate) FontId);
#[cfg(feature = "default-font")]
pub const DEFAULT_FONT: FontHandle = FontHandle(0);
#[cfg(feature = "default-font")]
impl Default for FontHandle {
fn default() -> Self {
DEFAULT_FONT
}
}
pub(crate) struct FontRepr {
pub(crate) font: fontdue::Font,
}
pub struct FontHandleManager {
idc: FontId,
fonts: HashMap<FontId, FontRepr,BuildNoHashHasher<FontId>>,
pub(crate) idc: FontId,
fonts: HashMap<FontId, FontRepr, BuildNoHashHasher<FontId>>,
}
impl FontHandleManager {
pub fn new() -> Self {
Self {
idc: 0,
idc: 1,
fonts: HashMap::default(),
}
}

View file

@ -10,7 +10,6 @@ edition = "2024"
license = "GPL-3.0-or-later"
publish = true
include = [
"assets/**/*",
"src/**/*.rs",
"Cargo.toml",
]
@ -33,7 +32,10 @@ image = { version = "0.25", default-features = false, optional = true }
rustc-hash = "2.0"
[features]
default = ["el_all", "derive"]
default = ["el_all", "derive", "default-font"]
## Enable the default font (Proggy tiny, \~35kb)
default-font = ["hui-painter/default-font"]
## Enable derive macros
derive = ["dep:hui-derive"]

View file

@ -1,5 +1,5 @@
use hui_painter::text::FontHandle;
use hui_painter::text::{FontHandle, DEFAULT_FONT};
pub struct FontStack {
fonts: Vec<FontHandle>,
@ -8,12 +8,10 @@ pub struct FontStack {
impl FontStack {
pub fn new() -> Self {
Self {
#[cfg(not(feature = "default-font"))]
fonts: Vec::new(),
// TODO builtin_font
// #[cfg(not(feature = "builtin_font"))]
// fonts: Vec::new(),
// #[cfg(feature = "builtin_font")]
// fonts: vec![super::BUILTIN_FONT],
#[cfg(feature = "default-font")]
fonts: vec![DEFAULT_FONT],
}
}
@ -33,3 +31,9 @@ impl FontStack {
// self.current().unwrap_or_default()
// }
}
impl Default for FontStack {
fn default() -> Self {
Self::new()
}
}