diff --git a/egui_demo_lib/src/backend_panel.rs b/egui_demo_lib/src/backend_panel.rs index a73ec70d..a24ce8e4 100644 --- a/egui_demo_lib/src/backend_panel.rs +++ b/egui_demo_lib/src/backend_panel.rs @@ -208,6 +208,13 @@ impl BackendPanel { if ui.button("Quit").clicked() { frame.quit(); } + + if ui + .button("Drag me to drag window") + .is_pointer_button_down_on() + { + frame.drag_window(); + } } } diff --git a/egui_glium/src/backend.rs b/egui_glium/src/backend.rs index 357616e9..61673e6b 100644 --- a/egui_glium/src/backend.rs +++ b/egui_glium/src/backend.rs @@ -328,6 +328,7 @@ pub fn run(mut app: Box, native_options: &epi::NativeOptions) { quit, window_size, decorated, + drag_window, } = app_output; if let Some(decorated) = decorated { @@ -344,6 +345,10 @@ pub fn run(mut app: Box, native_options: &epi::NativeOptions) { ); } + if drag_window { + let _ = display.gl_window().window().drag_window(); + } + if quit { running = false; } else if needs_repaint { diff --git a/egui_web/src/backend.rs b/egui_web/src/backend.rs index 69ab6a34..ffa1be43 100644 --- a/egui_web/src/backend.rs +++ b/egui_web/src/backend.rs @@ -259,6 +259,7 @@ impl AppRunner { quit: _, // Can't quit a web page window_size: _, // Can't resize a web page decorated: _, // Can't show decorations + drag_window: _, // Can't be dragged } = app_output; } diff --git a/epi/src/lib.rs b/epi/src/lib.rs index 9398bb7b..0bb2b43a 100644 --- a/epi/src/lib.rs +++ b/epi/src/lib.rs @@ -252,6 +252,14 @@ impl<'a> Frame<'a> { self.0.output.decorated = Some(decorated); } + /// When called, the native window will follow the + /// movement of the cursor while the primary mouse button is down. + /// + /// Does not work on the web, and works badly on Mac. + pub fn drag_window(&mut self) { + self.0.output.drag_window = true; + } + /// If you need to request a repaint from another thread, clone this and send it to that other thread. pub fn repaint_signal(&self) -> std::sync::Arc { self.0.repaint_signal.clone() @@ -410,5 +418,8 @@ pub mod backend { /// Set to some bool to change window decorations pub decorated: Option, + + /// Set to true to drap window + pub drag_window: bool, } }