mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-21 14:48:42 -06:00
wip font stuff :p
This commit is contained in:
parent
9dcdd26fdb
commit
70f7641214
|
@ -1,5 +1,6 @@
|
||||||
pub mod paint;
|
pub mod paint;
|
||||||
pub mod texture;
|
pub mod texture;
|
||||||
|
pub mod text;
|
||||||
|
|
||||||
use texture::TextureAtlas;
|
use texture::TextureAtlas;
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
use std::{borrow::Cow, sync::Arc};
|
use std::{borrow::Cow, sync::Arc};
|
||||||
use fontdue::layout::{CoordinateSystem, Layout};
|
use fontdue::layout::{CoordinateSystem, Layout};
|
||||||
use crate::{paint::{
|
use crate::{
|
||||||
buffer::PaintBuffer,
|
Painter,
|
||||||
command::PaintCommand,
|
paint::{
|
||||||
}, Painter};
|
buffer::PaintBuffer,
|
||||||
|
command::PaintCommand,
|
||||||
pub struct FontHandle(Arc<fontdue::Font>);
|
},
|
||||||
|
};
|
||||||
|
|
||||||
pub struct TextChunk {
|
pub struct TextChunk {
|
||||||
pub text: Cow<'static, str>,
|
pub text: Cow<'static, str>,
|
||||||
pub font: FontHandle,
|
pub font: (),
|
||||||
pub size: f32,
|
pub size: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::{paint::{
|
use crate::{
|
||||||
buffer::PaintBuffer,
|
Painter,
|
||||||
command::PaintCommand,
|
paint::{
|
||||||
}, Painter};
|
buffer::PaintBuffer,
|
||||||
|
command::PaintCommand,
|
||||||
//TODO: use generics instead
|
},
|
||||||
|
};
|
||||||
|
|
||||||
pub struct PaintTransform {
|
pub struct PaintTransform {
|
||||||
pub transform: glam::Affine2,
|
pub transform: glam::Affine2,
|
||||||
|
|
2
hui-painter/src/text.rs
Normal file
2
hui-painter/src/text.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod ftm;
|
||||||
|
pub mod font;
|
0
hui-painter/src/text/font.rs
Normal file
0
hui-painter/src/text/font.rs
Normal file
40
hui-painter/src/text/ftm.rs
Normal file
40
hui-painter/src/text/ftm.rs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
use fontdue::layout::GlyphRasterConfig;
|
||||||
|
use hashbrown::HashMap;
|
||||||
|
use nohash_hasher::BuildNoHashHasher;
|
||||||
|
use crate::texture::{TextureAtlas, TextureHandle};
|
||||||
|
|
||||||
|
type FontId = u16;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct FontHandle(FontId);
|
||||||
|
|
||||||
|
/// Maps to the actual texture handle.
|
||||||
|
struct GlyphCacheItem {
|
||||||
|
handle: TextureHandle,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Map from raster config to glyph cache item.
|
||||||
|
///
|
||||||
|
/// Partitioned by font id in FtM :3
|
||||||
|
type PartitionKey = HashMap<GlyphRasterConfig, GlyphCacheItem>;
|
||||||
|
|
||||||
|
/// Manages glyph cache items in a texture atlas.
|
||||||
|
pub struct FontTextureManager {
|
||||||
|
partition: HashMap<FontId, PartitionKey, BuildNoHashHasher<FontId>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FontTextureManager {
|
||||||
|
/// Drop cached data for the specified font.
|
||||||
|
///
|
||||||
|
/// Panics:
|
||||||
|
/// - If the font handle is invalid.
|
||||||
|
/// - If any of the cached items are not found in the texture atlas or became invalid.\
|
||||||
|
/// This may happen if, for example, a different atlas is passed than the one used to allocate the items.
|
||||||
|
fn drop_font(&mut self, font: FontHandle, atlas: &mut TextureAtlas) {
|
||||||
|
let dump = self.partition.remove(&font.0).expect("Font handle is invalid");
|
||||||
|
for (_, item) in dump {
|
||||||
|
atlas.deallocate(item.handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue