mgui-core 0.5.0

mgui 框架核心:Element/RenderObject/Widget 三树、布局与绘制协议、帧管线与响应式原语
Documentation
use slotmap::SlotMap;

/// 阶段 1 直接复用 slotmap,后续如需自定义 generational index 再替换。
pub struct Arena<K: slotmap::Key, V> {
    inner: SlotMap<K, V>,
}

impl<K: slotmap::Key, V> Default for Arena<K, V> {
    fn default() -> Self {
        Self { inner: SlotMap::with_key() }
    }
}

impl<K: slotmap::Key, V> Arena<K, V> {
    pub fn new() -> Self {
        Self::default()
    }
    pub fn insert(&mut self, value: V) -> K {
        self.inner.insert(value)
    }
    pub fn get(&self, id: K) -> Option<&V> {
        self.inner.get(id)
    }
    pub fn get_mut(&mut self, id: K) -> Option<&mut V> {
        self.inner.get_mut(id)
    }
    pub fn remove(&mut self, id: K) -> Option<V> {
        self.inner.remove(id)
    }
    pub fn contains(&self, id: K) -> bool {
        self.inner.contains_key(id)
    }
    pub fn len(&self) -> usize {
        self.inner.len()
    }
    pub fn is_empty(&self) -> bool {
        self.inner.is_empty()
    }
    /// 迭代所有 (key, value) 对(测试 / 调试用)
    pub fn iter(&self) -> impl Iterator<Item = (K, &V)> {
        self.inner.iter()
    }
}

// #[cfg(test)] 已迁到 crates/mgui-test/tests/arena.rs