FINALLY transition events to global; slow text sending bug tho
This commit is contained in:
40
core/src/layout/widget/data.rs
Normal file
40
core/src/layout/widget/data.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use std::{any::TypeId, sync::mpsc::Sender};
|
||||
|
||||
use crate::{
|
||||
layout::{EVENT_TYPES, EventManager, WIDGETS, WidgetId, WidgetUpdate},
|
||||
util::{HashSet, RefGuardMut},
|
||||
};
|
||||
|
||||
pub struct WidgetData<W: ?Sized> {
|
||||
pub id: WidgetId,
|
||||
pub send: Option<Sender<WidgetUpdate>>,
|
||||
pub label: String,
|
||||
pub event_managers: HashSet<TypeId>,
|
||||
pub widget: W,
|
||||
}
|
||||
|
||||
impl<W: ?Sized> WidgetData<W> {
|
||||
pub(crate) fn event_managers(&self) -> impl Iterator<Item = RefGuardMut<'_, dyn EventManager>> {
|
||||
self.event_managers.iter().map(|id| {
|
||||
EVENT_TYPES
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get_mut(id)
|
||||
.unwrap()
|
||||
.clone()
|
||||
.get_take_mut()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: ?Sized> Drop for WidgetData<W> {
|
||||
fn drop(&mut self) {
|
||||
WIDGETS.remove(self.id);
|
||||
for mut m in self.event_managers() {
|
||||
// refer to src/layout/event.rs for why this is like this
|
||||
let stuff = m.remove(self.id);
|
||||
drop(m);
|
||||
drop(stuff);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user