@@ -3,9 +3,11 @@ extern crate wasm_bindgen;
3
3
use window:: { WindowAttributes , CreationError , MouseCursor } ;
4
4
use std:: collections:: VecDeque ;
5
5
use std:: rc:: Rc ;
6
+ use std:: cell:: RefCell ;
6
7
use dpi:: { PhysicalPosition , LogicalPosition , PhysicalSize , LogicalSize } ;
7
8
use icon:: Icon ;
8
9
use super :: event_loop:: { EventLoopWindowTarget } ;
10
+
9
11
use self :: wasm_bindgen:: prelude:: * ;
10
12
use self :: wasm_bindgen:: JsCast ;
11
13
@@ -86,7 +88,13 @@ pub struct Window {
86
88
}
87
89
88
90
pub ( crate ) struct WindowInternal {
89
- pending_events : Vec < :: event:: WindowEvent >
91
+ pub pending_events : RefCell < Vec < :: event:: WindowEvent > >
92
+ }
93
+
94
+ impl WindowInternal {
95
+ pub fn events ( & self ) -> Vec < :: event:: WindowEvent > {
96
+ self . pending_events . replace ( Vec :: new ( ) )
97
+ }
90
98
}
91
99
92
100
impl Window {
@@ -127,12 +135,24 @@ impl Window {
127
135
} ;
128
136
129
137
let internal = Rc :: new ( WindowInternal {
130
- pending_events : vec ! [ ]
138
+ pending_events : RefCell :: new ( Vec :: with_capacity ( 3 ) )
131
139
} ) ;
132
140
133
141
target. set_window ( internal. clone ( ) ) ;
134
142
135
143
// TODO: install WindowEvent handlers
144
+ let mut win = internal. clone ( ) ;
145
+ let click_handler = Closure :: wrap ( Box :: new ( move |event : web_sys:: MouseEvent | {
146
+ // TODO: process the event
147
+ win. pending_events . borrow_mut ( ) . push ( :: event:: WindowEvent :: MouseInput {
148
+ device_id : :: event:: DeviceId ( DeviceId ( 0 ) ) ,
149
+ state : :: event:: ElementState :: Pressed ,
150
+ button : :: event:: MouseButton :: Left ,
151
+ modifiers : Default :: default ( )
152
+ } ) ;
153
+ } ) as Box < FnMut ( web_sys:: MouseEvent ) > ) ;
154
+ element. set_onmousedown ( Some ( click_handler. as_ref ( ) . unchecked_ref ( ) ) ) ;
155
+ click_handler. forget ( ) ;
136
156
137
157
Ok ( Window {
138
158
canvas : element,
0 commit comments