use crate::sys;
#[repr(transparent)]
pub struct FontLoader(sys::ImFontLoader);
impl FontLoader {
#[doc(alias = "ImFontAtlasGetFontLoaderForStbTruetype")]
pub fn stb_truetype() -> &'static Self {
let raw = unsafe { sys::igImFontAtlasGetFontLoaderForStbTruetype() };
assert!(
!raw.is_null(),
"Dear ImGui returned a null stb_truetype font loader"
);
unsafe { &*raw.cast::<Self>() }
}
pub unsafe fn from_raw<'a>(raw: *const sys::ImFontLoader) -> &'a Self {
assert!(
!raw.is_null(),
"FontLoader::from_raw() received a null pointer"
);
unsafe { &*raw.cast::<Self>() }
}
pub(crate) fn as_ptr(&self) -> *const sys::ImFontLoader {
&self.0
}
}
#[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;
}
}
#[cfg(test)]
mod tests {
#[test]
fn builtin_font_loader_has_required_callbacks() {
let loader = super::FontLoader::stb_truetype();
let raw = loader.as_ptr();
assert!(!raw.is_null());
assert!(!unsafe { (*raw).Name }.is_null());
assert!(unsafe { (*raw).FontBakedLoadGlyph }.is_some());
}
}