mod application;
mod display;
mod events;
mod platform;
mod text_input;
mod window;
use std::cell::{Cell, RefCell};
pub(super) struct CallbackSlot<T> {
value: RefCell<Option<T>>,
generation: Cell<u64>,
}
impl<T> Default for CallbackSlot<T> {
fn default() -> Self {
Self {
value: RefCell::new(None),
generation: Cell::new(0),
}
}
}
impl<T> CallbackSlot<T> {
pub(super) fn set(&self, value: T) {
self.generation.set(self.generation.get().wrapping_add(1));
drop(self.value.replace(Some(value)));
}
pub(super) fn take(&self) -> Option<T> {
self.generation.set(self.generation.get().wrapping_add(1));
self.value.borrow_mut().take()
}
pub(super) fn with<R>(&self, callback: impl FnOnce(&mut T) -> R) -> Option<R> {
let mut value = self.value.borrow_mut().take()?;
let generation = self.generation.get();
let result = callback(&mut value);
if self.generation.get() == generation {
drop(self.value.replace(Some(value)));
}
Some(result)
}
}
pub(crate) use display::*;
pub use platform::*;
pub use window::set_status_bar_style;
pub(crate) use window::*;
pub fn current_platform(_headless: bool) -> std::rc::Rc<dyn gpui::Platform> {
std::rc::Rc::new(IosPlatform::new())
}