From 654aabac713f1cc2c60f5cac3a54d18482012cb7 Mon Sep 17 00:00:00 2001 From: Robin Date: Sat, 21 Jan 2023 19:30:16 +0100 Subject: [PATCH] viewports renderer should now work with viewports disabled --- .../src/lib.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/imgui-winit-glow-renderer-viewports/src/lib.rs b/imgui-winit-glow-renderer-viewports/src/lib.rs index 7e6fd73..86873eb 100644 --- a/imgui-winit-glow-renderer-viewports/src/lib.rs +++ b/imgui-winit-glow-renderer-viewports/src/lib.rs @@ -16,7 +16,7 @@ use glutin::{ surface::{GlSurface, Surface, SurfaceAttributesBuilder, WindowSurface}, }; use glutin_winit::DisplayBuilder; -use imgui::{BackendFlags, Id, Key, ViewportFlags}; +use imgui::{BackendFlags, Id, Key, ViewportFlags, ConfigFlags}; use raw_window_handle::HasRawWindowHandle; use thiserror::Error; use winit::{ @@ -401,11 +401,18 @@ impl Renderer { imgui.io_mut().keys_down[key as usize] = true; } winit::event::WindowEvent::CursorMoved { position, .. } => { - let window_pos = window.inner_position().unwrap().cast::(); - imgui.io_mut().mouse_pos = [ - position.x as f32 + window_pos.x, - position.y as f32 + window_pos.y, - ]; + if imgui.io().config_flags.contains(ConfigFlags::VIEWPORTS_ENABLE) { + let window_pos = window.inner_position().unwrap().cast::(); + imgui.io_mut().mouse_pos = [ + position.x as f32 + window_pos.x, + position.y as f32 + window_pos.y, + ]; + } else { + imgui.io_mut().mouse_pos = [ + position.x as f32, + position.y as f32, + ]; + } } winit::event::WindowEvent::MouseWheel { delta,