Steals the current thread to run the UI event loop and calls the application function back to continue execution This is required because some operating systems (OS X) can't handle UI events from any thread other than the one that's created when the app starts. `flo_draw` will work without this call on operating systems with more robust event handling designs. This will also ensure that any grap
(app_fn: TAppFn)
| 69 | /// not required. |
| 70 | /// |
| 71 | pub fn with_2d_graphics<TAppFn: 'static+Send+FnOnce() -> ()>(app_fn: TAppFn) { |
| 72 | // The event loop thread will send us a proxy once it's initialized |
| 73 | let (send_proxy, recv_proxy) = mpsc::channel(); |
| 74 | |
| 75 | // Run the application on a background thread |
| 76 | thread::Builder::new() |
| 77 | .name("Application thread".into()) |
| 78 | .spawn(move || { |
| 79 | GLUTIN_THREAD.sync(move |thread| { |
| 80 | // Wait for the proxy to be created |
| 81 | let proxy = recv_proxy.recv().expect("Glutin thread will send us a proxy after initialising"); |
| 82 | |
| 83 | // Create the main thread object |
| 84 | *thread = Some(Arc::new(GlutinThread { |
| 85 | event_proxy: Desync::new(proxy) |
| 86 | })); |
| 87 | }); |
| 88 | |
| 89 | // Call back to start the app running |
| 90 | let stop_glutin = StopGlutinWhenDropped; |
| 91 | |
| 92 | app_fn(); |
| 93 | |
| 94 | mem::drop(stop_glutin); |
| 95 | }) |
| 96 | .expect("Application thread is running"); |
| 97 | |
| 98 | // Run the graphics thread on this thread |
| 99 | run_glutin_thread(send_proxy); |
| 100 | } |
| 101 | |
| 102 | /// |
| 103 | /// Starts the glutin thread running |