diff --git a/Cargo.toml b/Cargo.toml index 64c2a77e7..3078d2880 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,9 +55,6 @@ env_logger = "0.9.0" tokio = { version = "1.12.0", features = ["full"] } rand = { version = "0.8.4", features = ["small_rng"] } gloo-timers = "0.2.1" -# surf = { version = "2.3.1", default-features = false, features = [ -# "wasm-client", -# ] } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] gloo-timers = "0.2.1" @@ -66,6 +63,9 @@ console_error_panic_hook = "0.1.6" rand = { version = "0.8.4", features = ["small_rng"] } wasm-bindgen = { version = "0.2.71", features = ["enable-interning"] } +# surf = { version = "2.3.1", default-features = false, features = [ +# "wasm-client", +# ] } # surf = { version = "2.2.0", default-features = false, features = [ # "wasm-client", # ], git = "https://github.com/jkelleyrtp/surf/", branch = "jk/fix-the-wasm" } @@ -86,7 +86,7 @@ members = [ "packages/ssr", "packages/desktop", "packages/mobile", - "packages/webview-client" + "packages/webview-client", ] diff --git a/README.md b/README.md index cb0264f00..5520ec940 100644 --- a/README.md +++ b/README.md @@ -89,9 +89,9 @@ If you know React, then you already know Dioxus. ## Examples: -| File Navigator (Desktop) | Bluetooth scanner (Desktop) | TodoMVC (All platforms) | Widget Gallery | -| -------------------------------------------------------------------------------- | ---------------------------------------------------------------- | --------------------------------------------------------------------- | ---------------------------------------------------------------- | -| ![asd](https://github.com/DioxusLabs/file-explorer-example/raw/master/image.png) | ![asd](https://sixtyfps.io/resources/printerdemo_screenshot.png) | ![asd](https://github.com/DioxusLabs/todomvc/blob/master/example.png) | ![asd](https://sixtyfps.io/resources/printerdemo_screenshot.png) | +| File Navigator (Desktop) | Bluetooth scanner (Desktop) | TodoMVC (All platforms) | Widget Gallery | +| -------------------------------------------------------------------------------- | ---------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | +| ![asd](https://github.com/DioxusLabs/file-explorer-example/raw/master/image.png) | ![asd](https://sixtyfps.io/resources/printerdemo_screenshot.png) | [![asd](https://github.com/DioxusLabs/todomvc/blob/master/example.png)](https://github.com/dioxusLabs/todomvc/) | ![asd](https://sixtyfps.io/resources/printerdemo_screenshot.png) | @@ -101,12 +101,6 @@ If you know React, then you already know Dioxus. -| Printer Demo | Slide Puzzle | Todo | Widget Gallery | -| ---------------------------------------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------- | -| ![asd](https://sixtyfps.io/resources/printerdemo_screenshot.png) | ![asd](https://sixtyfps.io/resources/printerdemo_screenshot.png) | ![asd](https://sixtyfps.io/resources/printerdemo_screenshot.png) | ![asd](https://sixtyfps.io/resources/printerdemo_screenshot.png) | - - - See the awesome-dioxus page for a curated list of content in the Dioxus Ecosystem. diff --git a/packages/core/examples/jsframework.rs b/packages/core/examples/jsframework.rs index 8ea858407..2e6e4218e 100644 --- a/packages/core/examples/jsframework.rs +++ b/packages/core/examples/jsframework.rs @@ -1,5 +1,4 @@ use dioxus::events::on::MouseEvent; -use dioxus::events::DioxusEvent; use dioxus_core as dioxus; use dioxus_core::prelude::*; use dioxus_core_macro::*; diff --git a/packages/core/src/events.rs b/packages/core/src/events.rs index 556ba6d18..21cd6b50c 100644 --- a/packages/core/src/events.rs +++ b/packages/core/src/events.rs @@ -31,27 +31,33 @@ pub struct UserEvent { pub name: &'static str, /// The type of event - pub event: SyntheticEvent, + pub event: Box, } -#[derive(Debug)] -pub enum SyntheticEvent { - AnimationEvent(on::AnimationEvent), - ClipboardEvent(on::ClipboardEvent), - CompositionEvent(on::CompositionEvent), - FocusEvent(on::FocusEvent), - FormEvent(on::FormEvent), - KeyboardEvent(on::KeyboardEvent), - GenericEvent(DioxusEvent<()>), - TouchEvent(on::TouchEvent), - ToggleEvent(on::ToggleEvent), - MediaEvent(on::MediaEvent), - MouseEvent(on::MouseEvent), - WheelEvent(on::WheelEvent), - SelectionEvent(on::SelectionEvent), - TransitionEvent(on::TransitionEvent), - PointerEvent(on::PointerEvent), -} +struct EventInner {} + +// trait SyntheticEvent: Send + Debug { +// fn downcast(self: Box) -> Option>; +// } + +// #[derive(Debug)] +// pub enum SyntheticEvent { +// AnimationEvent(on::AnimationEvent), +// ClipboardEvent(on::ClipboardEvent), +// CompositionEvent(on::CompositionEvent), +// FocusEvent(on::FocusEvent), +// FormEvent(on::FormEvent), +// KeyboardEvent(on::KeyboardEvent), +// GenericEvent(DioxusEvent<()>), +// TouchEvent(on::TouchEvent), +// ToggleEvent(on::ToggleEvent), +// MediaEvent(on::MediaEvent), +// MouseEvent(on::MouseEvent), +// WheelEvent(on::WheelEvent), +// SelectionEvent(on::SelectionEvent), +// TransitionEvent(on::TransitionEvent), +// PointerEvent(on::PointerEvent), +// } /// Priority of Event Triggers. /// @@ -105,23 +111,7 @@ pub enum EventPriority { Low = 0, } -#[derive(Debug)] -pub struct DioxusEvent { - inner: T, - raw: Box, -} - -impl DioxusEvent { - pub fn new(inner: T, raw: F) -> Self { - let raw = Box::new(raw); - Self { inner, raw } - } - - /// Return a reference to the raw event. User will need to downcast the event to the right platform-specific type. - pub fn native(&self) -> Option<&E> { - self.raw.downcast_ref() - } - +impl EventInner { /* Not implemented! @@ -200,20 +190,13 @@ impl DioxusEvent { } } -impl std::ops::Deref for DioxusEvent { - type Target = T; - - fn deref(&self) -> &Self::Target { - &self.inner - } -} - pub mod on { use super::*; macro_rules! event_directory { ( $( $( #[$attr:meta] )* - $eventdata:ident($wrapper:ident): [ + $wrapper:ident: [ + // $eventdata:ident($wrapper:ident): [ $( $( #[$method_attr:meta] )* $name:ident @@ -221,20 +204,6 @@ pub mod on { ]; )* ) => { $( - $(#[$attr])* - #[derive(Debug)] - pub struct $wrapper(pub DioxusEvent<$eventdata>); - - // todo: derefing to the event is fine (and easy) but breaks some IDE stuff like (go to source) - // going to source in fact takes you to the source of Rc which is... less than useful - // Either we ask for this to be changed in Rust-analyzer or manually implement the trait - impl Deref for $wrapper { - type Target = DioxusEvent<$eventdata>; - fn deref(&self) -> &Self::Target { - &self.0 - } - } - $( $(#[$method_attr])* pub fn $name<'a, F>( @@ -248,12 +217,12 @@ pub mod on { // we can't allocate unsized in bumpalo's box, so we need to craft the box manually // safety: this is essentially the same as calling Box::new() but manually // The box is attached to the lifetime of the bumpalo allocator - let cb: &mut dyn FnMut(SyntheticEvent) = bump.alloc(move |evt: SyntheticEvent| match evt { - SyntheticEvent::$wrapper(event) => callback(event), - _ => unreachable!("Downcasted SyntheticEvent to wrong spcific event type - this is an internal bug!") + let cb: &mut dyn FnMut(Box) = bump.alloc(move |evt: Box| { + let event = evt.downcast::<$wrapper>().unwrap(); + callback(*event) }); - let callback: BumpBox = unsafe { BumpBox::from_raw(cb) }; + let callback: BumpBox) + 'a> = unsafe { BumpBox::from_raw(cb) }; // ie oncopy let event_name = stringify!($name); @@ -274,7 +243,7 @@ pub mod on { // The Dioxus Synthetic event system event_directory! { - ClipboardEventInner(ClipboardEvent): [ + ClipboardEvent: [ /// Called when "copy" oncopy @@ -285,7 +254,7 @@ pub mod on { onpaste ]; - CompositionEventInner(CompositionEvent): [ + CompositionEvent: [ /// oncompositionend oncompositionend @@ -296,7 +265,7 @@ pub mod on { oncompositionupdate ]; - KeyboardEventInner(KeyboardEvent): [ + KeyboardEvent: [ /// onkeydown onkeydown @@ -307,7 +276,7 @@ pub mod on { onkeyup ]; - FocusEventInner(FocusEvent): [ + FocusEvent: [ /// onfocus onfocus @@ -315,7 +284,7 @@ pub mod on { onblur ]; - FormEventInner(FormEvent): [ + FormEvent: [ /// onchange onchange @@ -373,7 +342,7 @@ pub mod on { /// - [`onmouseout`] /// - [`onmouseover`] /// - [`onmouseup`] - MouseEventInner(MouseEvent): [ + MouseEvent: [ /// Execute a callback when a button is clicked. /// /// ## Description @@ -456,7 +425,7 @@ pub mod on { onmouseup ]; - PointerEventInner(PointerEvent): [ + PointerEvent: [ /// pointerdown onpointerdown @@ -488,12 +457,12 @@ pub mod on { onpointerout ]; - SelectionEventInner(SelectionEvent): [ + SelectionEvent: [ /// onselect onselect ]; - TouchEventInner(TouchEvent): [ + TouchEvent: [ /// ontouchcancel ontouchcancel @@ -507,12 +476,12 @@ pub mod on { ontouchstart ]; - WheelEventInner(WheelEvent): [ + WheelEvent: [ /// onwheel ]; - MediaEventInner(MediaEvent): [ + MediaEvent: [ ///abort onabort @@ -583,7 +552,7 @@ pub mod on { onwaiting ]; - AnimationEventInner(AnimationEvent): [ + AnimationEvent: [ /// onanimationstart onanimationstart @@ -594,12 +563,12 @@ pub mod on { onanimationiteration ]; - TransitionEventInner(TransitionEvent): [ + TransitionEvent: [ /// ontransitionend ]; - ToggleEventInner(ToggleEvent): [ + ToggleEvent: [ /// ontoggle ]; @@ -607,19 +576,19 @@ pub mod on { #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct ClipboardEventInner( + pub struct ClipboardEvent( // DOMDataTransfer clipboardData ); #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct CompositionEventInner { + pub struct CompositionEvent { pub data: String, } #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct KeyboardEventInner { + pub struct KeyboardEvent { pub char_code: u32, /// Identify which "key" was entered. @@ -687,18 +656,18 @@ pub mod on { #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct FocusEventInner {/* DOMEventInner: Send + SyncTarget relatedTarget */} + pub struct FocusEvent {/* DOMEventInner: Send + SyncTarget relatedTarget */} #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct FormEventInner { + pub struct FormEvent { pub value: String, - /* DOMEventInner: Send + SyncTarget relatedTarget */ + /* DOMEvent: Send + SyncTarget relatedTarget */ } #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct MouseEventInner { + pub struct MouseEvent { pub alt_key: bool, pub button: i16, pub buttons: u16, @@ -716,7 +685,7 @@ pub mod on { #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct PointerEventInner { + pub struct PointerEvent { // Mouse only pub alt_key: bool, pub button: i16, @@ -745,11 +714,11 @@ pub mod on { #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct SelectionEventInner {} + pub struct SelectionEvent {} #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct TouchEventInner { + pub struct TouchEvent { pub alt_key: bool, pub ctrl_key: bool, pub meta_key: bool, @@ -762,7 +731,7 @@ pub mod on { #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct WheelEventInner { + pub struct WheelEvent { pub delta_mode: u32, pub delta_x: f64, pub delta_y: f64, @@ -771,17 +740,17 @@ pub mod on { #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct MediaEventInner {} + pub struct MediaEvent {} #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct ImageEventInner { + pub struct ImageEvent { pub load_error: bool, } #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct AnimationEventInner { + pub struct AnimationEvent { pub animation_name: String, pub pseudo_element: String, pub elapsed_time: f32, @@ -789,7 +758,7 @@ pub mod on { #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct TransitionEventInner { + pub struct TransitionEvent { pub property_name: String, pub pseudo_element: String, pub elapsed_time: f32, @@ -797,7 +766,7 @@ pub mod on { #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug)] - pub struct ToggleEventInner {} + pub struct ToggleEvent {} } #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] diff --git a/packages/core/src/lib.rs b/packages/core/src/lib.rs index 8c07f0037..091f0f774 100644 --- a/packages/core/src/lib.rs +++ b/packages/core/src/lib.rs @@ -62,8 +62,8 @@ pub(crate) mod innerlude { pub use crate::innerlude::{ Context, DioxusElement, DomEdit, DomTree, ElementId, EventPriority, LazyNodes, MountType, - Mutations, NodeFactory, Properties, SchedulerMsg, ScopeId, SuspendedContext, SyntheticEvent, - TaskHandle, TestDom, ThreadsafeVirtualDom, UserEvent, VNode, VirtualDom, FC, + Mutations, NodeFactory, Properties, SchedulerMsg, ScopeId, SuspendedContext, TaskHandle, + TestDom, ThreadsafeVirtualDom, UserEvent, VNode, VirtualDom, FC, }; pub mod prelude { diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index 5346042a1..eae2709fa 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -4,8 +4,7 @@ //! cheap and *very* fast to construct - building a full tree should be quick. use crate::innerlude::{ - empty_cell, Context, DomTree, ElementId, Properties, Scope, ScopeId, SuspendedContext, - SyntheticEvent, FC, + empty_cell, Context, DomTree, ElementId, Properties, Scope, ScopeId, SuspendedContext, FC, }; use bumpalo::{boxed::Box as BumpBox, Bump}; use std::{ @@ -271,7 +270,8 @@ pub struct Listener<'bump> { pub event: &'static str, /// The actual callback that the user specified - pub(crate) callback: RefCell>>, + pub(crate) callback: + RefCell) + 'bump>>>, } /// Virtual Components for custom user-defined components diff --git a/packages/desktop/src/events.rs b/packages/desktop/src/events.rs index a7b69187a..4b1b1ae43 100644 --- a/packages/desktop/src/events.rs +++ b/packages/desktop/src/events.rs @@ -1,16 +1,10 @@ //! Convert a serialized event to an event Trigger //! -use std::rc::Rc; use std::sync::Arc; +use std::{any::Any, rc::Rc}; -use dioxus_core::{ - events::{ - on::{MouseEvent, MouseEventInner}, - SyntheticEvent, - }, - ElementId, EventPriority, ScopeId, UserEvent, -}; +use dioxus_core::{events::on::MouseEvent, ElementId, EventPriority, ScopeId, UserEvent}; #[derive(serde::Serialize, serde::Deserialize)] struct ImEvent { @@ -43,85 +37,70 @@ pub fn trigger_from_serialized(val: serde_json::Value) -> UserEvent { } } -fn make_synthetic_event(name: &str, val: serde_json::Value) -> SyntheticEvent { +fn make_synthetic_event(name: &str, val: serde_json::Value) -> Box { use dioxus_core::events::on::*; - use dioxus_core::events::DioxusEvent; match name { - "copy" | "cut" | "paste" => SyntheticEvent::ClipboardEvent(ClipboardEvent( - DioxusEvent::new(ClipboardEventInner(), ()), - )), + "copy" | "cut" | "paste" => { + // + Box::new(ClipboardEvent {}) + } "compositionend" | "compositionstart" | "compositionupdate" => { - SyntheticEvent::CompositionEvent(CompositionEvent(DioxusEvent::new( - serde_json::from_value(val).unwrap(), - (), - ))) + Box::new(serde_json::from_value::(val).unwrap()) + } + "keydown" | "keypress" | "keyup" => { + Box::new(serde_json::from_value::(val).unwrap()) } - "keydown" | "keypress" | "keyup" => SyntheticEvent::KeyboardEvent(KeyboardEvent( - DioxusEvent::new(serde_json::from_value(val).unwrap(), ()), - )), "focus" | "blur" => { - SyntheticEvent::FocusEvent(FocusEvent(DioxusEvent::new(FocusEventInner {}, ()))) + // + Box::new(FocusEvent {}) } - "change" => SyntheticEvent::GenericEvent(DioxusEvent::new((), ())), // todo: these handlers might get really slow if the input box gets large and allocation pressure is heavy // don't have a good solution with the serialized event problem - "input" | "invalid" | "reset" | "submit" => SyntheticEvent::FormEvent(FormEvent( - DioxusEvent::new(serde_json::from_value(val).unwrap(), ()), - )), + "change" | "input" | "invalid" | "reset" | "submit" => { + Box::new(serde_json::from_value::(val).unwrap()) + } + "click" | "contextmenu" | "doubleclick" | "drag" | "dragend" | "dragenter" | "dragexit" | "dragleave" | "dragover" | "dragstart" | "drop" | "mousedown" | "mouseenter" | "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup" => { - SyntheticEvent::MouseEvent(MouseEvent(DioxusEvent::new( - serde_json::from_value(val).unwrap(), - (), - ))) + Box::new(serde_json::from_value::(val).unwrap()) } "pointerdown" | "pointermove" | "pointerup" | "pointercancel" | "gotpointercapture" | "lostpointercapture" | "pointerenter" | "pointerleave" | "pointerover" | "pointerout" => { - SyntheticEvent::PointerEvent(PointerEvent(DioxusEvent::new( - serde_json::from_value(val).unwrap(), - (), - ))) + Box::new(serde_json::from_value::(val).unwrap()) + } + "select" => { + // + Box::new(serde_json::from_value::(val).unwrap()) } - "select" => SyntheticEvent::SelectionEvent(SelectionEvent(DioxusEvent::new( - SelectionEventInner {}, - (), - ))), - "touchcancel" | "touchend" | "touchmove" | "touchstart" => SyntheticEvent::TouchEvent( - TouchEvent(DioxusEvent::new(serde_json::from_value(val).unwrap(), ())), - ), + "touchcancel" | "touchend" | "touchmove" | "touchstart" => { + Box::new(serde_json::from_value::(val).unwrap()) + } - "scroll" => SyntheticEvent::GenericEvent(DioxusEvent::new((), ())), + "scroll" => Box::new(()), - "wheel" => SyntheticEvent::WheelEvent(WheelEvent(DioxusEvent::new( - serde_json::from_value(val).unwrap(), - (), - ))), + "wheel" => Box::new(serde_json::from_value::(val).unwrap()), - "animationstart" | "animationend" | "animationiteration" => SyntheticEvent::AnimationEvent( - AnimationEvent(DioxusEvent::new(serde_json::from_value(val).unwrap(), ())), - ), + "animationstart" | "animationend" | "animationiteration" => { + Box::new(serde_json::from_value::(val).unwrap()) + } - "transitionend" => SyntheticEvent::TransitionEvent(TransitionEvent(DioxusEvent::new( - serde_json::from_value(val).unwrap(), - (), - ))), + "transitionend" => Box::new(serde_json::from_value::(val).unwrap()), "abort" | "canplay" | "canplaythrough" | "durationchange" | "emptied" | "encrypted" | "ended" | "error" | "loadeddata" | "loadedmetadata" | "loadstart" | "pause" | "play" | "playing" | "progress" | "ratechange" | "seeked" | "seeking" | "stalled" | "suspend" | "timeupdate" | "volumechange" | "waiting" => { - SyntheticEvent::MediaEvent(MediaEvent(DioxusEvent::new(MediaEventInner {}, ()))) + // + Box::new(MediaEvent {}) } - "toggle" => { - SyntheticEvent::ToggleEvent(ToggleEvent(DioxusEvent::new(ToggleEventInner {}, ()))) - } + "toggle" => Box::new(ToggleEvent {}), - _ => SyntheticEvent::GenericEvent(DioxusEvent::new((), ())), + _ => Box::new(()), } } diff --git a/packages/web/src/dom.rs b/packages/web/src/dom.rs index 7cfae2bae..e30f7693b 100644 --- a/packages/web/src/dom.rs +++ b/packages/web/src/dom.rs @@ -8,13 +8,13 @@ //! - Partial delegation?> use dioxus_core::{ - events::{DioxusEvent, KeyCode, SyntheticEvent, UserEvent}, + events::{KeyCode, UserEvent}, mutations::NodeRefMutation, scheduler::SchedulerMsg, DomEdit, ElementId, ScopeId, }; use fxhash::FxHashMap; -use std::{fmt::Debug, rc::Rc, sync::Arc}; +use std::{any::Any, fmt::Debug, rc::Rc, sync::Arc}; use wasm_bindgen::{closure::Closure, JsCast}; use web_sys::{ Attr, CssStyleDeclaration, Document, Element, Event, HtmlElement, HtmlInputElement, @@ -483,45 +483,37 @@ unsafe impl Sync for DioxusWebsysEvent {} // todo: some of these events are being casted to the wrong event type. // We need tests that simulate clicks/etc and make sure every event type works. -fn virtual_event_from_websys_event(event: web_sys::Event) -> SyntheticEvent { +fn virtual_event_from_websys_event(event: web_sys::Event) -> Box { use crate::events::*; use dioxus_core::events::on::*; match event.type_().as_str() { - "copy" | "cut" | "paste" => SyntheticEvent::ClipboardEvent(ClipboardEvent( - DioxusEvent::new(ClipboardEventInner(), DioxusWebsysEvent(event)), - )), + "copy" | "cut" | "paste" => Box::new(ClipboardEvent {}), "compositionend" | "compositionstart" | "compositionupdate" => { let evt: &web_sys::CompositionEvent = event.dyn_ref().unwrap(); - SyntheticEvent::CompositionEvent(CompositionEvent(DioxusEvent::new( - CompositionEventInner { - data: evt.data().unwrap_or_default(), - }, - DioxusWebsysEvent(event), - ))) + Box::new(CompositionEvent { + data: evt.data().unwrap_or_default(), + }) } "keydown" | "keypress" | "keyup" => { let evt: &web_sys::KeyboardEvent = event.dyn_ref().unwrap(); - SyntheticEvent::KeyboardEvent(KeyboardEvent(DioxusEvent::new( - KeyboardEventInner { - alt_key: evt.alt_key(), - char_code: evt.char_code(), - key: evt.key(), - key_code: KeyCode::from_raw_code(evt.key_code() as u8), - ctrl_key: evt.ctrl_key(), - locale: "not implemented".to_string(), - location: evt.location() as usize, - meta_key: evt.meta_key(), - repeat: evt.repeat(), - shift_key: evt.shift_key(), - which: evt.which() as usize, - }, - DioxusWebsysEvent(event), - ))) + Box::new(KeyboardEvent { + alt_key: evt.alt_key(), + char_code: evt.char_code(), + key: evt.key(), + key_code: KeyCode::from_raw_code(evt.key_code() as u8), + ctrl_key: evt.ctrl_key(), + locale: "not implemented".to_string(), + location: evt.location() as usize, + meta_key: evt.meta_key(), + repeat: evt.repeat(), + shift_key: evt.shift_key(), + which: evt.which() as usize, + }) + } + "focus" | "blur" => { + // + Box::new(FocusEvent {}) } - "focus" | "blur" => SyntheticEvent::FocusEvent(FocusEvent(DioxusEvent::new( - FocusEventInner {}, - DioxusWebsysEvent(event), - ))), // "change" => SyntheticEvent::GenericEvent(DioxusEvent::new((), DioxusWebsysEvent(event))), // todo: these handlers might get really slow if the input box gets large and allocation pressure is heavy @@ -565,135 +557,112 @@ fn virtual_event_from_websys_event(event: web_sys::Event) -> SyntheticEvent { }) .expect("only an InputElement or TextAreaElement or an element with contenteditable=true can have an oninput event listener"); - SyntheticEvent::FormEvent(FormEvent(DioxusEvent::new( - FormEventInner { value }, - DioxusWebsysEvent(event), - ))) + Box::new(FormEvent { value }) } "click" | "contextmenu" | "doubleclick" | "drag" | "dragend" | "dragenter" | "dragexit" | "dragleave" | "dragover" | "dragstart" | "drop" | "mousedown" | "mouseenter" | "mouseleave" | "mousemove" | "mouseout" | "mouseover" | "mouseup" => { let evt: &web_sys::MouseEvent = event.dyn_ref().unwrap(); - SyntheticEvent::MouseEvent(MouseEvent(DioxusEvent::new( - MouseEventInner { - alt_key: evt.alt_key(), - button: evt.button(), - buttons: evt.buttons(), - client_x: evt.client_x(), - client_y: evt.client_y(), - ctrl_key: evt.ctrl_key(), - meta_key: evt.meta_key(), - screen_x: evt.screen_x(), - screen_y: evt.screen_y(), - shift_key: evt.shift_key(), - page_x: evt.page_x(), - page_y: evt.page_y(), - }, - DioxusWebsysEvent(event), - ))) + Box::new(MouseEvent { + alt_key: evt.alt_key(), + button: evt.button(), + buttons: evt.buttons(), + client_x: evt.client_x(), + client_y: evt.client_y(), + ctrl_key: evt.ctrl_key(), + meta_key: evt.meta_key(), + screen_x: evt.screen_x(), + screen_y: evt.screen_y(), + shift_key: evt.shift_key(), + page_x: evt.page_x(), + page_y: evt.page_y(), + }) } "pointerdown" | "pointermove" | "pointerup" | "pointercancel" | "gotpointercapture" | "lostpointercapture" | "pointerenter" | "pointerleave" | "pointerover" | "pointerout" => { let evt: &web_sys::PointerEvent = event.dyn_ref().unwrap(); - SyntheticEvent::PointerEvent(PointerEvent(DioxusEvent::new( - PointerEventInner { - alt_key: evt.alt_key(), - button: evt.button(), - buttons: evt.buttons(), - client_x: evt.client_x(), - client_y: evt.client_y(), - ctrl_key: evt.ctrl_key(), - meta_key: evt.meta_key(), - page_x: evt.page_x(), - page_y: evt.page_y(), - screen_x: evt.screen_x(), - screen_y: evt.screen_y(), - shift_key: evt.shift_key(), - pointer_id: evt.pointer_id(), - width: evt.width(), - height: evt.height(), - pressure: evt.pressure(), - tangential_pressure: evt.tangential_pressure(), - tilt_x: evt.tilt_x(), - tilt_y: evt.tilt_y(), - twist: evt.twist(), - pointer_type: evt.pointer_type(), - is_primary: evt.is_primary(), - // get_modifier_state: evt.get_modifier_state(), - }, - DioxusWebsysEvent(event), - ))) + Box::new(PointerEvent { + alt_key: evt.alt_key(), + button: evt.button(), + buttons: evt.buttons(), + client_x: evt.client_x(), + client_y: evt.client_y(), + ctrl_key: evt.ctrl_key(), + meta_key: evt.meta_key(), + page_x: evt.page_x(), + page_y: evt.page_y(), + screen_x: evt.screen_x(), + screen_y: evt.screen_y(), + shift_key: evt.shift_key(), + pointer_id: evt.pointer_id(), + width: evt.width(), + height: evt.height(), + pressure: evt.pressure(), + tangential_pressure: evt.tangential_pressure(), + tilt_x: evt.tilt_x(), + tilt_y: evt.tilt_y(), + twist: evt.twist(), + pointer_type: evt.pointer_type(), + is_primary: evt.is_primary(), + // get_modifier_state: evt.get_modifier_state(), + }) } - "select" => SyntheticEvent::SelectionEvent(SelectionEvent(DioxusEvent::new( - SelectionEventInner {}, - DioxusWebsysEvent(event), - ))), + "select" => Box::new(SelectionEvent {}), "touchcancel" | "touchend" | "touchmove" | "touchstart" => { let evt: &web_sys::TouchEvent = event.dyn_ref().unwrap(); - SyntheticEvent::TouchEvent(TouchEvent(DioxusEvent::new( - TouchEventInner { - alt_key: evt.alt_key(), - ctrl_key: evt.ctrl_key(), - meta_key: evt.meta_key(), - shift_key: evt.shift_key(), - }, - DioxusWebsysEvent(event), - ))) + Box::new(TouchEvent { + alt_key: evt.alt_key(), + ctrl_key: evt.ctrl_key(), + meta_key: evt.meta_key(), + shift_key: evt.shift_key(), + }) } - "scroll" => SyntheticEvent::GenericEvent(DioxusEvent::new((), DioxusWebsysEvent(event))), + "scroll" => Box::new(()), "wheel" => { let evt: &web_sys::WheelEvent = event.dyn_ref().unwrap(); - SyntheticEvent::WheelEvent(WheelEvent(DioxusEvent::new( - WheelEventInner { - delta_x: evt.delta_x(), - delta_y: evt.delta_y(), - delta_z: evt.delta_z(), - delta_mode: evt.delta_mode(), - }, - DioxusWebsysEvent(event), - ))) + Box::new(WheelEvent { + delta_x: evt.delta_x(), + delta_y: evt.delta_y(), + delta_z: evt.delta_z(), + delta_mode: evt.delta_mode(), + }) } "animationstart" | "animationend" | "animationiteration" => { let evt: &web_sys::AnimationEvent = event.dyn_ref().unwrap(); - SyntheticEvent::AnimationEvent(AnimationEvent(DioxusEvent::new( - AnimationEventInner { - elapsed_time: evt.elapsed_time(), - animation_name: evt.animation_name(), - pseudo_element: evt.pseudo_element(), - }, - DioxusWebsysEvent(event), - ))) + Box::new(AnimationEvent { + elapsed_time: evt.elapsed_time(), + animation_name: evt.animation_name(), + pseudo_element: evt.pseudo_element(), + }) } "transitionend" => { let evt: &web_sys::TransitionEvent = event.dyn_ref().unwrap(); - SyntheticEvent::TransitionEvent(TransitionEvent(DioxusEvent::new( - TransitionEventInner { - elapsed_time: evt.elapsed_time(), - property_name: evt.property_name(), - pseudo_element: evt.pseudo_element(), - }, - DioxusWebsysEvent(event), - ))) + Box::new(TransitionEvent { + elapsed_time: evt.elapsed_time(), + property_name: evt.property_name(), + pseudo_element: evt.pseudo_element(), + }) } "abort" | "canplay" | "canplaythrough" | "durationchange" | "emptied" | "encrypted" | "ended" | "error" | "loadeddata" | "loadedmetadata" | "loadstart" | "pause" | "play" | "playing" | "progress" | "ratechange" | "seeked" | "seeking" | "stalled" | "suspend" - | "timeupdate" | "volumechange" | "waiting" => SyntheticEvent::MediaEvent(MediaEvent( - DioxusEvent::new(MediaEventInner {}, DioxusWebsysEvent(event)), - )), + | "timeupdate" | "volumechange" | "waiting" => { + // + Box::new(MediaEvent {}) + } - "toggle" => SyntheticEvent::ToggleEvent(ToggleEvent(DioxusEvent::new( - ToggleEventInner {}, - DioxusWebsysEvent(event), - ))), + "toggle" => { + // + Box::new(ToggleEvent {}) + } - _ => SyntheticEvent::GenericEvent(DioxusEvent::new((), DioxusWebsysEvent(event))), + _ => Box::new(()), } }