Skip to content

Commit e262d6d

Browse files
committed
updated to winit 0.30
1 parent b3542ba commit e262d6d

File tree

3 files changed

+53
-43
lines changed

3 files changed

+53
-43
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ categories = ["gui"]
1111

1212
[dependencies]
1313
imgui = "0.12.0"
14-
winit = { version = "0.29.3", default-features = false }
14+
winit = { version = "0.30", default-features = false }

README.md

+51-41
Original file line numberDiff line numberDiff line change
@@ -21,57 +21,67 @@ use imgui::Context;
2121
use imgui_winit_support::{HiDpiMode, WinitPlatform};
2222
use std::time::Instant;
2323
use 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
3032
let 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
3436
platform.attach_window(imgui.io_mut(), &window, HiDpiMode::Default); // step 2
3537
3638
let 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

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl CursorSettings {
366366
match self.cursor {
367367
Some(mouse_cursor) if !self.draw_cursor => {
368368
window.set_cursor_visible(true);
369-
window.set_cursor_icon(to_winit_cursor(mouse_cursor));
369+
window.set_cursor(to_winit_cursor(mouse_cursor));
370370
}
371371
_ => window.set_cursor_visible(false),
372372
}

0 commit comments

Comments
 (0)