From bb63fcdb7fd88011d9fea270ccd36854b36934c1 Mon Sep 17 00:00:00 2001 From: Boby <40067018+bobyclaws@users.noreply.github.com> Date: Sat, 16 Apr 2022 21:42:37 +0530 Subject: [PATCH] added `epi::Frame::set_window_pos` this allows setting the position of window at runtime --- egui-winit/src/epi.rs | 8 ++++++++ egui_web/src/backend.rs | 1 + epi/src/lib.rs | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/egui-winit/src/epi.rs b/egui-winit/src/epi.rs index 349349c9af6..3bdcdf3e32f 100644 --- a/egui-winit/src/epi.rs +++ b/egui-winit/src/epi.rs @@ -96,6 +96,7 @@ pub fn handle_app_output( window_title, decorated, drag_window, + window_pos, } = app_output; if let Some(decorated) = decorated { @@ -116,6 +117,13 @@ pub fn handle_app_output( window.set_title(&window_title); } + if let Some(window_pos) = window_pos { + window.set_outer_position(winit::dpi::PhysicalPosition { + x: window_pos.x as f64, + y: window_pos.y as f64, + }); + } + if drag_window { let _ = window.drag_window(); } diff --git a/egui_web/src/backend.rs b/egui_web/src/backend.rs index 23d43cf0e4d..2f9982aa64f 100644 --- a/egui_web/src/backend.rs +++ b/egui_web/src/backend.rs @@ -268,6 +268,7 @@ impl AppRunner { window_title: _, // TODO: change title of window decorated: _, // Can't toggle decorations drag_window: _, // Can't be dragged + window_pos: _, // Can't set position of a web page } = app_output; } diff --git a/epi/src/lib.rs b/epi/src/lib.rs index bbc0e8380f9..88a72a05729 100644 --- a/epi/src/lib.rs +++ b/epi/src/lib.rs @@ -323,6 +323,11 @@ impl Frame { self.output.decorated = Some(decorated); } + /// set the position of the outer window + pub fn set_window_pos(&mut self, pos: egui::Pos2) { + self.output.window_pos = Some(pos); + } + /// When called, the native window will follow the /// movement of the cursor while the primary mouse button is down. /// @@ -503,5 +508,8 @@ pub mod backend { /// Set to true to drag window while primary mouse button is down. pub drag_window: bool, + + /// Set to some position to move the outer window (e.g. glium window) to this position + pub window_pos: Option, } }