remove modules and have single event manager (atomics feature parity + preparation for local state)

This commit is contained in:
2025-12-12 01:46:24 -05:00
parent a708813ce7
commit 37b1987aa8
17 changed files with 390 additions and 432 deletions

View File

@@ -1,5 +1,5 @@
use crate::{
IdLike, Widget, WidgetId,
IdLike, Widget, WidgetData, WidgetId,
util::{DynBorrower, HashSet, SlotVec},
};
@@ -9,13 +9,6 @@ pub struct Widgets {
vec: SlotVec<WidgetData>,
}
pub struct WidgetData {
pub widget: Box<dyn Widget>,
pub label: String,
/// dynamic borrow checking
pub borrowed: bool,
}
impl Widgets {
pub fn has_updates(&self) -> bool {
!self.updates.is_empty()
@@ -60,35 +53,23 @@ impl Widgets {
}
pub fn add<W: Widget>(&mut self, widget: W) -> WidgetId {
let mut label = std::any::type_name::<W>().to_string();
if let (Some(first), Some(last)) = (label.find(":"), label.rfind(":")) {
label = label.split_at(first).0.to_string() + "::" + label.split_at(last + 1).1;
}
self.insert_any(Box::new(widget), label)
self.vec.add(WidgetData::new(widget))
}
pub fn data(&self, id: WidgetId) -> Option<&WidgetData> {
self.vec.get(id)
pub fn data(&self, id: impl IdLike) -> Option<&WidgetData> {
self.vec.get(id.id())
}
pub fn label(&self, id: WidgetId) -> &String {
&self.data(id).unwrap().label
pub fn label(&self, id: impl IdLike) -> &String {
&self.data(id.id()).unwrap().label
}
pub fn data_mut(&mut self, id: WidgetId) -> Option<&mut WidgetData> {
self.vec.get_mut(id)
pub fn data_mut(&mut self, id: impl IdLike) -> Option<&mut WidgetData> {
self.vec.get_mut(id.id())
}
pub fn insert_any(&mut self, widget: Box<dyn Widget>, label: String) -> WidgetId {
self.vec.add(WidgetData {
widget,
label,
borrowed: false,
})
}
pub fn delete(&mut self, id: WidgetId) {
self.vec.free(id);
pub fn delete(&mut self, id: impl IdLike) {
self.vec.free(id.id());
// not sure if there's any point in this
// self.updates.remove(&id);
}