From 54703670ad3b2f15a23b7ef5ae0e20f98ed073ef Mon Sep 17 00:00:00 2001 From: Jared Stephen Date: Tue, 24 Dec 2024 10:25:37 -0800 Subject: [PATCH] use logical size when building window --- examples/demo_gl.rs | 3 ++- examples/demo_glium.rs | 9 ++++++--- src/app_builder.rs | 14 ++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/examples/demo_gl.rs b/examples/demo_gl.rs index 73c2f0b..80edde4 100644 --- a/examples/demo_gl.rs +++ b/examples/demo_gl.rs @@ -4,6 +4,7 @@ use glutin::surface::{Surface, WindowSurface, GlSurface}; use glutin_winit::DisplayBuilder; use glutin::display::{GlDisplay, GetGlDisplay}; use winit::application::ApplicationHandler; +use winit::dpi::LogicalSize; use winit::event::WindowEvent; use winit::window::Window; use winit::raw_window_handle::HasWindowHandle; @@ -33,7 +34,7 @@ fn main() -> Result<(), Box> { let attrs = Window::default_attributes() .with_title("Thyme GL Demo") - .with_inner_size(winit::dpi::PhysicalSize::new(1280, 720)); + .with_inner_size(LogicalSize::new(1280, 720)); let display_builder = DisplayBuilder::new().with_window_attributes(Some(attrs)); let config_template_builder = ConfigTemplateBuilder::new(); diff --git a/examples/demo_glium.rs b/examples/demo_glium.rs index 95cd54c..472e891 100644 --- a/examples/demo_glium.rs +++ b/examples/demo_glium.rs @@ -1,4 +1,4 @@ -use winit::{application::ApplicationHandler, event::WindowEvent}; +use winit::{application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent, window::Window}; use thyme::{bench, Context, ContextBuilder, GliumRenderer, WinitError, WinitIo}; mod demo; @@ -16,10 +16,13 @@ fn main() -> Result<(), Box> { let event_loop = glium::winit::event_loop::EventLoop::builder() .build().map_err(|e| thyme::Error::Winit(WinitError::EventLoop(e)))?; + let attrs = Window::default_attributes() + .with_title("Thyme Demo") + .with_inner_size(LogicalSize::new(window_size[0], window_size[1])); + // create glium display let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new() - .with_title("Thyme Demo") - .with_inner_size(window_size[0] as u32, window_size[1] as u32) + .set_window_builder(attrs) .build(&event_loop); // create thyme backend diff --git a/src/app_builder.rs b/src/app_builder.rs index b08fca7..2fd719a 100644 --- a/src/app_builder.rs +++ b/src/app_builder.rs @@ -201,6 +201,7 @@ impl AppBuilder { use glutin::context::{ContextApi, ContextAttributesBuilder, Version, NotCurrentGlContext}; use glutin_winit::DisplayBuilder; use glutin::display::{GlDisplay, GetGlDisplay}; + use winit::dpi::LogicalSize; use winit::raw_window_handle::HasWindowHandle; use winit::window::Window; @@ -218,8 +219,8 @@ impl AppBuilder { .build().map_err(|e| Error::Winit(WinitError::EventLoop(e)))?; let attrs = Window::default_attributes() - .with_title("Thyme GL Demo") - .with_inner_size(winit::dpi::PhysicalSize::new(1280, 720)); + .with_title(&self.title) + .with_inner_size(LogicalSize::new(self.window_size.x as u32, self.window_size.y as u32)); let display_builder = DisplayBuilder::new().with_window_attributes(Some(attrs)); let config_template_builder = ConfigTemplateBuilder::new(); @@ -280,6 +281,8 @@ impl AppBuilder { /// in this Builder and using the [`GliumRenderer`](struct.GliumRenderer.html). #[cfg(feature="glium_backend")] pub fn build_glium(self) -> Result { + use winit::{dpi::LogicalSize, window::Window}; + use crate::winit_io::WinitError; if self.logger { @@ -289,9 +292,12 @@ impl AppBuilder { let event_loop = glium::winit::event_loop::EventLoop::builder() .build().map_err(|e| Error::Winit(WinitError::EventLoop(e)))?; - let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new() + let attrs = Window::default_attributes() .with_title(&self.title) - .with_inner_size(self.window_size.x as u32, self.window_size.y as u32) + .with_inner_size(LogicalSize::new(self.window_size.x as u32, self.window_size.y as u32)); + + let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new() + .set_window_builder(attrs) .build(&event_loop); let mut io = crate::WinitIo::new(&window, self.window_size)