xgpui-ios 2.0.0

Upstream-derived UIKit and Metal backend for xgpui on iOS
Documentation
//! UIKit-backed implementation details for the iOS GPUI platform.

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> {
        // Even an empty take can mean the focused handler was withdrawn during a callback.
        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);
        // Do not resurrect a handler that application code replaced or removed.
        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::*;

/// Returns the native platform implementation for iOS.
pub fn current_platform(_headless: bool) -> std::rc::Rc<dyn gpui::Platform> {
    std::rc::Rc::new(IosPlatform::new())
}