epi: drag native window (#728)
* feat: drag window * Update epi/src/lib.rs Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com> * Update egui_demo_lib/src/backend_panel.rs Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com> * cargo fmt Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
parent
1b36863248
commit
f6fb4d942a
4 changed files with 24 additions and 0 deletions
|
@ -208,6 +208,13 @@ impl BackendPanel {
|
||||||
if ui.button("Quit").clicked() {
|
if ui.button("Quit").clicked() {
|
||||||
frame.quit();
|
frame.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ui
|
||||||
|
.button("Drag me to drag window")
|
||||||
|
.is_pointer_button_down_on()
|
||||||
|
{
|
||||||
|
frame.drag_window();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -328,6 +328,7 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: &epi::NativeOptions) {
|
||||||
quit,
|
quit,
|
||||||
window_size,
|
window_size,
|
||||||
decorated,
|
decorated,
|
||||||
|
drag_window,
|
||||||
} = app_output;
|
} = app_output;
|
||||||
|
|
||||||
if let Some(decorated) = decorated {
|
if let Some(decorated) = decorated {
|
||||||
|
@ -344,6 +345,10 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: &epi::NativeOptions) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if drag_window {
|
||||||
|
let _ = display.gl_window().window().drag_window();
|
||||||
|
}
|
||||||
|
|
||||||
if quit {
|
if quit {
|
||||||
running = false;
|
running = false;
|
||||||
} else if needs_repaint {
|
} else if needs_repaint {
|
||||||
|
|
|
@ -259,6 +259,7 @@ impl AppRunner {
|
||||||
quit: _, // Can't quit a web page
|
quit: _, // Can't quit a web page
|
||||||
window_size: _, // Can't resize a web page
|
window_size: _, // Can't resize a web page
|
||||||
decorated: _, // Can't show decorations
|
decorated: _, // Can't show decorations
|
||||||
|
drag_window: _, // Can't be dragged
|
||||||
} = app_output;
|
} = app_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,6 +252,14 @@ impl<'a> Frame<'a> {
|
||||||
self.0.output.decorated = Some(decorated);
|
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.
|
/// 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<dyn RepaintSignal> {
|
pub fn repaint_signal(&self) -> std::sync::Arc<dyn RepaintSignal> {
|
||||||
self.0.repaint_signal.clone()
|
self.0.repaint_signal.clone()
|
||||||
|
@ -410,5 +418,8 @@ pub mod backend {
|
||||||
|
|
||||||
/// Set to some bool to change window decorations
|
/// Set to some bool to change window decorations
|
||||||
pub decorated: Option<bool>,
|
pub decorated: Option<bool>,
|
||||||
|
|
||||||
|
/// Set to true to drap window
|
||||||
|
pub drag_window: bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue