use std::{any::TypeId, sync::mpsc::Sender}; use crate::{ layout::{EVENT_TYPES, EventManager, WIDGETS, WidgetId, WidgetUpdate}, util::{HashSet, RefGuardMut}, }; pub struct WidgetData { pub id: WidgetId, pub send: Option>, pub label: String, pub event_managers: HashSet, pub widget: W, } impl WidgetData { pub(crate) fn event_managers(&self) -> impl Iterator> { self.event_managers.iter().map(|id| { EVENT_TYPES .lock() .unwrap() .get_mut(id) .unwrap() .clone() .get_take_mut() }) } } impl Drop for WidgetData { 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); } } }