@@ -89,6 +89,7 @@ builder_constructors! {
89
89
} ;
90
90
}
91
91
92
+ // I am still bad at Macros so I created this element directly
92
93
#[ allow( non_camel_case_types) ]
93
94
pub struct image ;
94
95
@@ -111,68 +112,56 @@ impl image {
111
112
}
112
113
}
113
114
114
- pub trait GlobalAttributes {
115
- fn prevent_default < ' a > ( & self , cx : NodeFactory < ' a > , val : Arguments ) -> Attribute < ' a > {
116
- cx. attr ( "dioxus-prevent-default" , val, None , false )
117
- }
118
- }
119
-
120
- pub trait SvgAttributes {
121
- fn prevent_default < ' a > ( & self , cx : NodeFactory < ' a > , val : Arguments ) -> Attribute < ' a > {
122
- cx. attr ( "dioxus-prevent-default" , val, None , false )
123
- }
124
- }
125
-
126
115
pub mod on {
127
116
use dioxus_core:: * ;
128
117
use dioxus_html:: on:: { MouseData , MouseEvent , WheelData , WheelEvent } ;
129
118
130
119
use bumpalo:: boxed:: Box as BumpBox ;
131
120
132
121
macro_rules! event_directory {
133
- ( $(
134
- $( #[ $attr: meta] ) *
135
- $wrapper: ident( $data: ident) : [
136
- $(
137
- $( #[ $method_attr: meta] ) *
138
- $name: ident
139
- ) *
140
- ] ;
141
- ) * ) => {
142
- $(
122
+ ( $(
123
+ $( #[ $attr: meta] ) *
124
+ $wrapper: ident( $data: ident) : [
125
+ $(
126
+ $( #[ $method_attr: meta] ) *
127
+ $name: ident
128
+ ) *
129
+ ] ;
130
+ ) * ) => {
143
131
$(
144
- $( #[ $method_attr] ) *
145
- pub fn $name<' a>(
146
- factory: NodeFactory <' a>,
147
- mut callback: impl FnMut ( $wrapper) + ' a,
148
- // mut callback: impl FnMut(UiEvent<$data>) + 'a,
149
- ) -> Listener <' a>
150
- {
151
- let bump = & factory. bump( ) ;
152
-
153
- // we can't allocate unsized in bumpalo's box, so we need to craft the box manually
154
- // safety: this is essentially the same as calling Box::new() but manually
155
- // The box is attached to the lifetime of the bumpalo allocator
156
- let cb: & mut dyn FnMut ( AnyEvent ) = bump. alloc( move |evt: AnyEvent | {
157
- let event = evt. downcast:: <$data>( ) . unwrap( ) ;
158
- callback( event)
159
- } ) ;
160
-
161
- let callback: BumpBox <dyn FnMut ( AnyEvent ) + ' a> = unsafe { BumpBox :: from_raw( cb) } ;
162
-
163
- // ie oncopy
164
- let event_name = stringify!( $name) ;
165
-
166
- // ie copy
167
- let shortname: & ' static str = & event_name[ 2 ..] ;
168
-
169
- let handler = bump. alloc( std:: cell:: RefCell :: new( Some ( callback) ) ) ;
170
- factory. listener( shortname, handler)
171
- }
132
+ $(
133
+ $( #[ $method_attr] ) *
134
+ pub fn $name<' a>(
135
+ factory: NodeFactory <' a>,
136
+ mut callback: impl FnMut ( $wrapper) + ' a,
137
+ // mut callback: impl FnMut(UiEvent<$data>) + 'a,
138
+ ) -> Listener <' a>
139
+ {
140
+ let bump = & factory. bump( ) ;
141
+
142
+ // we can't allocate unsized in bumpalo's box, so we need to craft the box manually
143
+ // safety: this is essentially the same as calling Box::new() but manually
144
+ // The box is attached to the lifetime of the bumpalo allocator
145
+ let cb: & mut dyn FnMut ( AnyEvent ) = bump. alloc( move |evt: AnyEvent | {
146
+ let event = evt. downcast:: <$data>( ) . unwrap( ) ;
147
+ callback( event)
148
+ } ) ;
149
+
150
+ let callback: BumpBox <dyn FnMut ( AnyEvent ) + ' a> = unsafe { BumpBox :: from_raw( cb) } ;
151
+
152
+ // ie oncopy
153
+ let event_name = stringify!( $name) ;
154
+
155
+ // ie copy
156
+ let shortname: & ' static str = & event_name[ 2 ..] ;
157
+
158
+ let handler = bump. alloc( std:: cell:: RefCell :: new( Some ( callback) ) ) ;
159
+ factory. listener( shortname, handler)
160
+ }
161
+ ) *
172
162
) *
173
- ) *
174
- } ;
175
- }
163
+ } ;
164
+ }
176
165
177
166
event_directory ! {
178
167
MouseEvent ( MouseData ) : [
@@ -186,3 +175,7 @@ pub mod on {
186
175
] ;
187
176
}
188
177
}
178
+
179
+ pub trait GlobalAttributes { }
180
+
181
+ pub trait SvgAttributes { }
0 commit comments