@@ -21,57 +21,67 @@ use imgui::Context;
2121use imgui_winit_support::{HiDpiMode, WinitPlatform};
2222use std::time::Instant;
2323use winit::event::{Event, WindowEvent};
24- use winit::event_loop::{ControlFlow, EventLoop} ;
25- use winit::window::Window ;
24+ use winit::event_loop::EventLoop;
25+ use winit::window::WindowAttributes ;
2626
27- let mut event_loop = EventLoop::new().expect("Failed to create EventLoop");
28- let mut window = Window::new(&event_loop).unwrap();
27+ let event_loop = EventLoop::new().expect("Failed to create EventLoop");
28+ let window = event_loop
29+ .create_window(WindowAttributes::default())
30+ .expect("couldn't create window");
2931
3032let mut imgui = Context::create();
3133// configure imgui-rs Context if necessary
3234
33- let mut platform = WinitPlatform::init (&mut imgui); // step 1
35+ let mut platform = WinitPlatform::new (&mut imgui); // step 1
3436platform.attach_window(imgui.io_mut(), &window, HiDpiMode::Default); // step 2
3537
3638let mut last_frame = Instant::now();
37- let mut run = true;
38- event_loop.run(move |event, window_target| {
39- match event {
40- Event::NewEvents(_) => {
41- // other application-specific logic
42- let now = Instant::now();
43- imgui.io_mut().update_delta_time(now - last_frame);
44- last_frame = now;
45- },
46- Event::AboutToWait => {
47- // other application-specific logic
48- platform.prepare_frame(imgui.io_mut(), &window) // step 4
49- .expect("Failed to prepare frame");
50- window.request_redraw();
51- }
52- Event::WindowEvent { event: WindowEvent::RedrawRequested, .. } => {
53- let ui = imgui.frame();
54- // application-specific rendering *under the UI*
55-
56- // construct the UI
57-
58- platform.prepare_render(&ui, &window); // step 5
59- // render the UI with a renderer
60- let draw_data = imgui.render();
61- // renderer.render(..., draw_data).expect("UI rendering failed");
62-
63- // application-specific rendering *over the UI*
64- },
65- Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
66- window_target.exit();
67- }
68- // other application-specific event handling
69- event => {
70- platform.handle_event(imgui.io_mut(), &window, &event); // step 3
39+ event_loop
40+ .run(move |event, window_target| {
41+ match event {
42+ Event::NewEvents(_) => {
43+ // other application-specific logic
44+ let now = Instant::now();
45+ imgui.io_mut().update_delta_time(now - last_frame);
46+ last_frame = now;
47+ }
48+ Event::AboutToWait => {
49+ // other application-specific logic
50+ platform
51+ .prepare_frame(imgui.io_mut(), &window) // step 4
52+ .expect("Failed to prepare frame");
53+ window.request_redraw();
54+ }
55+ Event::WindowEvent {
56+ event: WindowEvent::RedrawRequested,
57+ ..
58+ } => {
59+ let ui = imgui.frame();
60+ // application-specific rendering *under the UI*
61+
62+ // construct the UI
63+
64+ platform.prepare_render(ui, &window); // step 5
65+ // render the UI with a renderer
66+ let draw_data = imgui.render();
67+ // renderer.render(..., draw_data).expect("UI rendering failed");
68+
69+ // application-specific rendering *over the UI*
70+ }
71+ Event::WindowEvent {
72+ event: WindowEvent::CloseRequested,
73+ ..
74+ } => {
75+ window_target.exit();
76+ }
7177 // other application-specific event handling
78+ event => {
79+ platform.handle_event(imgui.io_mut(), &window, &event); // step 3
80+ // other application-specific event handling
81+ }
7282 }
73- }
74- }) .expect("EventLoop error");
83+ })
84+ .expect("EventLoop error");
7585```
7686
7787## License
0 commit comments