add extension to downcast web events
This commit is contained in:
1 parent
8ba1c05a93
commit
097eb2099c
4 files changed
+442
-288
No files matched your search
@@ -10,6 +10,18 @@ pub struct PointerData {
|
||||
inner: Box<dyn HasPointerData>,
|
||||
}
|
||||
|
||||
impl PointerData {
|
||||
/// Create a new PointerData
|
||||
pub fn new(data: impl HasPointerData + 'static) -> Self {
|
||||
Self::from(data)
|
||||
}
|
||||
|
||||
/// Downcast this event to a concrete event type
|
||||
pub fn downcast<T: 'static>(&self) -> Option<&T> {
|
||||
self.inner.as_any().downcast_ref::<T>()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: HasPointerData> From<E> for PointerData {
|
||||
fn from(e: E) -> Self {
|
||||
Self { inner: Box::new(e) }
|
||||
|
||||
Reference in new issue
Block a user