use super::font::Font;
use crate::capi_state::CApiState;
pub struct ActiveFont<'a> {
generation: usize,
font: &'a Font,
}
impl<'a> ActiveFont<'a> {
pub(crate) fn new(font: &'a Font) -> Self {
let generation = CApiState::get().font_generation.get() + 1;
CApiState::get().font_generation.set(generation);
ActiveFont { generation, font }
}
pub fn font(&self) -> &'a Font {
self.font
}
pub(crate) fn fns() -> &'static craydate_sys::playdate_graphics {
CApiState::get().cgraphics
}
}
impl Drop for ActiveFont<'_> {
fn drop(&mut self) {
if self.generation == CApiState::get().font_generation.get() {
unsafe { Self::fns().setFont.unwrap()(core::ptr::null_mut()) }
}
}
}