use std::ffi::CString;
use crate::sys;
use super::core::FontAtlas;
pub struct FontLoader {
raw: sys::ImFontLoader,
_name: CString,
}
impl FontLoader {
pub fn new(name: &str) -> Result<Self, std::ffi::NulError> {
let name_cstring = CString::new(name)?;
let mut raw = unsafe {
let p = sys::ImFontLoader_ImFontLoader();
if p.is_null() {
panic!("ImFontLoader_ImFontLoader() returned null");
}
let v = *p;
sys::ImFontLoader_destroy(p);
v
};
raw.Name = name_cstring.as_ptr();
Ok(Self {
raw,
_name: name_cstring,
})
}
pub(crate) fn as_ptr(&self) -> *const sys::ImFontLoader {
&self.raw
}
pub fn with_loader_init<F>(self, _callback: F) -> Self
where
F: Fn(&mut FontAtlas) -> bool + 'static,
{
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FontLoaderFlags(pub u32);
impl FontLoaderFlags {
pub const NONE: Self = Self(0);
pub const NO_HINTING: Self = Self(1 << 0);
pub const NO_AUTOHINT: Self = Self(1 << 1);
pub const FORCE_AUTOHINT: Self = Self(1 << 2);
pub const LIGHT_HINTING: Self = Self(1 << 3);
pub const MONO_HINTING: Self = Self(1 << 4);
pub const BOLD: Self = Self(1 << 5);
pub const OBLIQUE: Self = Self(1 << 6);
pub const MONOCHROME: Self = Self(1 << 7);
pub const LOAD_COLOR: Self = Self(1 << 8);
pub const BITMAP: Self = Self(1 << 9);
}
impl std::ops::BitOr for FontLoaderFlags {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
}
impl std::ops::BitOrAssign for FontLoaderFlags {
fn bitor_assign(&mut self, rhs: Self) {
self.0 |= rhs.0;
}
}