88extern crate conrod_core;
99extern crate conrod_example_shared;
1010extern crate conrod_gfx;
11+ #[ macro_use]
1112extern crate conrod_winit;
1213extern crate gfx;
1314extern crate gfx_core;
1415extern crate gfx_window_glutin;
1516extern crate glutin;
1617extern crate find_folder;
1718extern crate image;
18-
19- use self :: conrod_winit:: winit;
19+ extern crate winit;
2020
2121use conrod_example_shared:: { WIN_W , WIN_H } ;
2222use gfx:: Device ;
@@ -25,6 +25,24 @@ const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.0];
2525
2626type DepthFormat = gfx:: format:: DepthStencil ;
2727
28+ // A wrapper around the winit window that allows us to implement the trait necessary for enabling
29+ // the winit <-> conrod conversion functions.
30+ struct WindowRef < ' a > ( & ' a winit:: Window ) ;
31+
32+ // Implement the `WinitWindow` trait for `WindowRef` to allow for generating compatible conversion
33+ // functions.
34+ impl < ' a > conrod_winit:: WinitWindow for WindowRef < ' a > {
35+ fn get_inner_size ( & self ) -> Option < ( u32 , u32 ) > {
36+ winit:: Window :: get_inner_size ( & self . 0 ) . map ( Into :: into)
37+ }
38+ fn hidpi_factor ( & self ) -> f32 {
39+ winit:: Window :: get_hidpi_factor ( & self . 0 ) as _
40+ }
41+ }
42+
43+ // Generate the winit <-> conrod_core type conversion fns.
44+ conrod_winit:: conversion_fns!( ) ;
45+
2846fn main ( ) {
2947 // Builder for window
3048 let builder = glutin:: WindowBuilder :: new ( )
@@ -121,7 +139,7 @@ fn main() {
121139 events_loop. poll_events ( |event|{
122140
123141 // Convert winit event to conrod event, requires conrod to be built with the `winit` feature
124- if let Some ( event) = conrod_winit :: convert_event ( event. clone ( ) , window. window ( ) ) {
142+ if let Some ( event) = convert_event ( event. clone ( ) , & WindowRef ( window. window ( ) ) ) {
125143 ui. handle_event ( event) ;
126144 }
127145
0 commit comments