Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated winit, glutin and glium dependencies #754

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ members = [

package.rust-version = "1.70"
resolver = "2"

[patch.crates-io]
glium = { git="https://github.com/glium/glium" }
2 changes: 1 addition & 1 deletion imgui-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false

[dev-dependencies]
copypasta = "0.8"
glium = { version = "0.32.1", default-features = true }
glium = { version = "0.33.0", default-features = true }
image = "0.23"
imgui = { path = "../imgui", features = ["tables-api"] }
imgui-glium-renderer = { path = "../imgui-glium-renderer" }
Expand Down
125 changes: 69 additions & 56 deletions imgui-examples/examples/support/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use glium::glutin;
use glium::glutin::event::{Event, WindowEvent};
use glium::glutin::event_loop::{ControlFlow, EventLoop};
use glium::glutin::window::WindowBuilder;
use glium::{Display, Surface};
use glium::glutin::surface::WindowSurface;
use glium::Surface;
use imgui::{Context, FontConfig, FontGlyphRanges, FontSource, Ui};
use imgui_glium_renderer::Renderer;
use imgui_winit_support::winit::dpi::LogicalSize;
use imgui_winit_support::winit::event::{Event, WindowEvent};
use imgui_winit_support::winit::event_loop::EventLoop;
use imgui_winit_support::winit::window::{Window, WindowBuilder};
use imgui_winit_support::{HiDpiMode, WinitPlatform};
use std::path::Path;
use std::time::Instant;
Expand All @@ -13,7 +14,8 @@ mod clipboard;

pub struct System {
pub event_loop: EventLoop<()>,
pub display: glium::Display,
pub window: Window,
pub display: glium::Display<WindowSurface>,
pub imgui: Context,
pub platform: WinitPlatform,
pub renderer: Renderer,
Expand All @@ -25,13 +27,14 @@ pub fn init(title: &str) -> System {
Some(file_name) => file_name.to_str().unwrap(),
None => title,
};
let event_loop = EventLoop::new();
let context = glutin::ContextBuilder::new().with_vsync(true);
let event_loop = EventLoop::new().expect("Failed to create EventLoop");

let builder = WindowBuilder::new()
.with_title(title.to_owned())
.with_inner_size(glutin::dpi::LogicalSize::new(1024f64, 768f64));
let display =
Display::new(builder, context, &event_loop).expect("Failed to initialize display");
.with_title(title)
.with_inner_size(LogicalSize::new(1024, 768));
let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new()
.set_window_builder(builder)
.build(&event_loop);

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

let mut platform = WinitPlatform::init(&mut imgui);
{
let gl_window = display.gl_window();
let window = gl_window.window();

let dpi_mode = if let Ok(factor) = std::env::var("IMGUI_EXAMPLE_FORCE_DPI_FACTOR") {
// Allow forcing of HiDPI factor for debugging purposes
match factor.parse::<f64>() {
Expand All @@ -57,7 +57,7 @@ pub fn init(title: &str) -> System {
HiDpiMode::Default
};

platform.attach_window(imgui.io_mut(), window, dpi_mode);
platform.attach_window(imgui.io_mut(), &window, dpi_mode);
}

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

System {
event_loop,
window,
display,
imgui,
platform,
Expand All @@ -115,6 +116,7 @@ impl System {
pub fn main_loop<F: FnMut(&mut bool, &mut Ui) + 'static>(self, mut run_ui: F) {
let System {
event_loop,
window,
display,
mut imgui,
mut platform,
Expand All @@ -123,46 +125,57 @@ impl System {
} = self;
let mut last_frame = Instant::now();

event_loop.run(move |event, _, control_flow| match event {
Event::NewEvents(_) => {
let now = Instant::now();
imgui.io_mut().update_delta_time(now - last_frame);
last_frame = now;
}
Event::MainEventsCleared => {
let gl_window = display.gl_window();
platform
.prepare_frame(imgui.io_mut(), gl_window.window())
.expect("Failed to prepare frame");
gl_window.window().request_redraw();
}
Event::RedrawRequested(_) => {
let ui = imgui.frame();

let mut run = true;
run_ui(&mut run, ui);
if !run {
*control_flow = ControlFlow::Exit;
event_loop
.run(move |event, window_target| match event {
Event::NewEvents(_) => {
let now = Instant::now();
imgui.io_mut().update_delta_time(now - last_frame);
last_frame = now;
}

let gl_window = display.gl_window();
let mut target = display.draw();
target.clear_color_srgb(1.0, 1.0, 1.0, 1.0);
platform.prepare_render(ui, gl_window.window());
let draw_data = imgui.render();
renderer
.render(&mut target, draw_data)
.expect("Rendering failed");
target.finish().expect("Failed to swap buffers");
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
event => {
let gl_window = display.gl_window();
platform.handle_event(imgui.io_mut(), gl_window.window(), &event);
}
})
Event::AboutToWait => {
platform
.prepare_frame(imgui.io_mut(), &window)
.expect("Failed to prepare frame");
window.request_redraw();
}
Event::WindowEvent {
event: WindowEvent::RedrawRequested,
..
} => {
let ui = imgui.frame();

let mut run = true;
run_ui(&mut run, ui);
if !run {
window_target.exit();
}

let mut target = display.draw();
target.clear_color_srgb(1.0, 1.0, 1.0, 1.0);
platform.prepare_render(ui, &window);
let draw_data = imgui.render();
renderer
.render(&mut target, draw_data)
.expect("Rendering failed");
target.finish().expect("Failed to swap buffers");
}
Event::WindowEvent {
event: WindowEvent::Resized(new_size),
..
} => {
if new_size.width > 0 && new_size.height > 0 {
display.resize((new_size.width, new_size.height));
}
platform.handle_event(imgui.io_mut(), &window, &event);
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => window_target.exit(),
event => {
platform.handle_event(imgui.io_mut(), &window, &event);
}
})
.expect("EventLoop error");
}
}
7 changes: 6 additions & 1 deletion imgui-glium-renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ license = "MIT OR Apache-2.0"
categories = ["gui", "rendering"]

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

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