use crate::fonts::atlas::id::FontId;
use crate::fonts::atlas::legacy::claim_legacy_renderer;
use crate::fonts::atlas::state::{
assert_no_font_atlas_texture_borrows, assert_no_open_font_atlas_frames, font_atlas_state,
};
use crate::fonts::atlas::{FontAtlasModeError, LegacyFontAtlas};
use crate::sys;
use super::FontAtlas;
impl FontAtlas {
pub fn try_claim_legacy_renderer(&self) -> Result<LegacyFontAtlas<'_>, FontAtlasModeError> {
claim_legacy_renderer(self)
}
pub(crate) unsafe fn from_raw<'a>(raw: *const sys::ImFontAtlas) -> &'a Self {
assert!(
!raw.is_null(),
"FontAtlas::from_raw() requires non-null pointer"
);
font_atlas_state(raw.cast_mut());
unsafe { &*raw.cast::<Self>() }
}
pub fn raw(&self) -> *mut sys::ImFontAtlas {
self.0.get()
}
pub(crate) fn font_id_for_raw(&self, font: *mut sys::ImFont) -> FontId {
FontId::from_raw_parts(font, self.raw())
}
pub(crate) fn assert_mutation_allowed(&self, caller: &str) {
let raw = self.raw();
assert_no_font_atlas_texture_borrows(raw, caller);
assert_no_open_font_atlas_frames(raw, caller);
assert!(
!unsafe { (*raw).Locked },
"{caller} cannot modify a locked font atlas"
);
}
}