Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca05418

Browse files
Rob2309sanbox-irl
authored andcommitted
Updated winit, glutin and glium dependencies
1 parent 8b2722d commit ca05418

File tree

18 files changed

+1214
-937
lines changed

18 files changed

+1214
-937
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ members = [
1313

1414
package.rust-version = "1.70"
1515
resolver = "2"
16+
17+
[patch.crates-io]
18+
glium = { git="https://github.com/glium/glium" }

imgui-examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ publish = false
1010

1111
[dev-dependencies]
1212
copypasta = "0.8"
13-
glium = { version = "0.32.1", default-features = true }
13+
glium = { version = "0.33.0", default-features = true }
1414
image = "0.23"
1515
imgui = { path = "../imgui", features = ["tables-api"] }
1616
imgui-glium-renderer = { path = "../imgui-glium-renderer" }

imgui-examples/examples/support/mod.rs

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use glium::glutin;
2-
use glium::glutin::event::{Event, WindowEvent};
3-
use glium::glutin::event_loop::{ControlFlow, EventLoop};
4-
use glium::glutin::window::WindowBuilder;
5-
use glium::{Display, Surface};
1+
use glium::glutin::surface::WindowSurface;
2+
use glium::Surface;
63
use imgui::{Context, FontConfig, FontGlyphRanges, FontSource, Ui};
74
use imgui_glium_renderer::Renderer;
5+
use imgui_winit_support::winit::dpi::LogicalSize;
6+
use imgui_winit_support::winit::event::{Event, WindowEvent};
7+
use imgui_winit_support::winit::event_loop::EventLoop;
8+
use imgui_winit_support::winit::window::{Window, WindowBuilder};
89
use imgui_winit_support::{HiDpiMode, WinitPlatform};
910
use std::path::Path;
1011
use std::time::Instant;
@@ -13,7 +14,8 @@ mod clipboard;
1314

1415
pub struct System {
1516
pub event_loop: EventLoop<()>,
16-
pub display: glium::Display,
17+
pub window: Window,
18+
pub display: glium::Display<WindowSurface>,
1719
pub imgui: Context,
1820
pub platform: WinitPlatform,
1921
pub renderer: Renderer,
@@ -25,13 +27,14 @@ pub fn init(title: &str) -> System {
2527
Some(file_name) => file_name.to_str().unwrap(),
2628
None => title,
2729
};
28-
let event_loop = EventLoop::new();
29-
let context = glutin::ContextBuilder::new().with_vsync(true);
30+
let event_loop = EventLoop::new().expect("Failed to create EventLoop");
31+
3032
let builder = WindowBuilder::new()
31-
.with_title(title.to_owned())
32-
.with_inner_size(glutin::dpi::LogicalSize::new(1024f64, 768f64));
33-
let display =
34-
Display::new(builder, context, &event_loop).expect("Failed to initialize display");
33+
.with_title(title)
34+
.with_inner_size(LogicalSize::new(1024, 768));
35+
let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new()
36+
.set_window_builder(builder)
37+
.build(&event_loop);
3538

3639
let mut imgui = Context::create();
3740
imgui.set_ini_filename(None);
@@ -44,9 +47,6 @@ pub fn init(title: &str) -> System {
4447

4548
let mut platform = WinitPlatform::init(&mut imgui);
4649
{
47-
let gl_window = display.gl_window();
48-
let window = gl_window.window();
49-
5050
let dpi_mode = if let Ok(factor) = std::env::var("IMGUI_EXAMPLE_FORCE_DPI_FACTOR") {
5151
// Allow forcing of HiDPI factor for debugging purposes
5252
match factor.parse::<f64>() {
@@ -57,7 +57,7 @@ pub fn init(title: &str) -> System {
5757
HiDpiMode::Default
5858
};
5959

60-
platform.attach_window(imgui.io_mut(), window, dpi_mode);
60+
platform.attach_window(imgui.io_mut(), &window, dpi_mode);
6161
}
6262

6363
// Fixed font size. Note imgui_winit_support uses "logical
@@ -103,6 +103,7 @@ pub fn init(title: &str) -> System {
103103

104104
System {
105105
event_loop,
106+
window,
106107
display,
107108
imgui,
108109
platform,
@@ -115,6 +116,7 @@ impl System {
115116
pub fn main_loop<F: FnMut(&mut bool, &mut Ui) + 'static>(self, mut run_ui: F) {
116117
let System {
117118
event_loop,
119+
window,
118120
display,
119121
mut imgui,
120122
mut platform,
@@ -123,46 +125,57 @@ impl System {
123125
} = self;
124126
let mut last_frame = Instant::now();
125127

126-
event_loop.run(move |event, _, control_flow| match event {
127-
Event::NewEvents(_) => {
128-
let now = Instant::now();
129-
imgui.io_mut().update_delta_time(now - last_frame);
130-
last_frame = now;
131-
}
132-
Event::MainEventsCleared => {
133-
let gl_window = display.gl_window();
134-
platform
135-
.prepare_frame(imgui.io_mut(), gl_window.window())
136-
.expect("Failed to prepare frame");
137-
gl_window.window().request_redraw();
138-
}
139-
Event::RedrawRequested(_) => {
140-
let ui = imgui.frame();
141-
142-
let mut run = true;
143-
run_ui(&mut run, ui);
144-
if !run {
145-
*control_flow = ControlFlow::Exit;
128+
event_loop
129+
.run(move |event, window_target| match event {
130+
Event::NewEvents(_) => {
131+
let now = Instant::now();
132+
imgui.io_mut().update_delta_time(now - last_frame);
133+
last_frame = now;
146134
}
147-
148-
let gl_window = display.gl_window();
149-
let mut target = display.draw();
150-
target.clear_color_srgb(1.0, 1.0, 1.0, 1.0);
151-
platform.prepare_render(ui, gl_window.window());
152-
let draw_data = imgui.render();
153-
renderer
154-
.render(&mut target, draw_data)
155-
.expect("Rendering failed");
156-
target.finish().expect("Failed to swap buffers");
157-
}
158-
Event::WindowEvent {
159-
event: WindowEvent::CloseRequested,
160-
..
161-
} => *control_flow = ControlFlow::Exit,
162-
event => {
163-
let gl_window = display.gl_window();
164-
platform.handle_event(imgui.io_mut(), gl_window.window(), &event);
165-
}
166-
})
135+
Event::AboutToWait => {
136+
platform
137+
.prepare_frame(imgui.io_mut(), &window)
138+
.expect("Failed to prepare frame");
139+
window.request_redraw();
140+
}
141+
Event::WindowEvent {
142+
event: WindowEvent::RedrawRequested,
143+
..
144+
} => {
145+
let ui = imgui.frame();
146+
147+
let mut run = true;
148+
run_ui(&mut run, ui);
149+
if !run {
150+
window_target.exit();
151+
}
152+
153+
let mut target = display.draw();
154+
target.clear_color_srgb(1.0, 1.0, 1.0, 1.0);
155+
platform.prepare_render(ui, &window);
156+
let draw_data = imgui.render();
157+
renderer
158+
.render(&mut target, draw_data)
159+
.expect("Rendering failed");
160+
target.finish().expect("Failed to swap buffers");
161+
}
162+
Event::WindowEvent {
163+
event: WindowEvent::Resized(new_size),
164+
..
165+
} => {
166+
if new_size.width > 0 && new_size.height > 0 {
167+
display.resize((new_size.width, new_size.height));
168+
}
169+
platform.handle_event(imgui.io_mut(), &window, &event);
170+
}
171+
Event::WindowEvent {
172+
event: WindowEvent::CloseRequested,
173+
..
174+
} => window_target.exit(),
175+
event => {
176+
platform.handle_event(imgui.io_mut(), &window, &event);
177+
}
178+
})
179+
.expect("EventLoop error");
167180
}
168181
}

imgui-glium-renderer/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ license = "MIT OR Apache-2.0"
1010
categories = ["gui", "rendering"]
1111

1212
[dependencies]
13-
glium = { version = "0.32.1", default-features = false }
13+
glium = { version = "0.33.0", default-features = false }
1414
imgui = { version = "0.11.0", path = "../imgui" }
1515

1616
[dev-dependencies]
17+
glium = { version = "0.33.0", default-features = false, features = ["glutin_backend"] }
1718
imgui-winit-support = {path = "../imgui-winit-support"}
19+
glutin = "0.31.1"
20+
glutin-winit = "0.4.2"
21+
winit = { version = "0.29.3", features = ["rwh_05"] }
22+
raw-window-handle = "0.5.0"

0 commit comments

Comments
 (0)