From ad249bc5974308acf62f666d4992de885146944e Mon Sep 17 00:00:00 2001 From: Jim Eckerlein Date: Fri, 29 Nov 2024 09:28:06 +0100 Subject: [PATCH 1/2] macOS: add movable_by_window_background option to viewport --- crates/egui-winit/src/lib.rs | 4 +++- crates/egui/src/viewport.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index a78339d01fe..9968f31e8ff 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -1596,6 +1596,7 @@ pub fn create_winit_window_attributes( // macOS: fullsize_content_view: _fullsize_content_view, + movable_by_window_background: _movable_by_window_background, title_shown: _title_shown, titlebar_buttons_shown: _titlebar_buttons_shown, titlebar_shown: _titlebar_shown, @@ -1742,7 +1743,8 @@ pub fn create_winit_window_attributes( .with_title_hidden(!_title_shown.unwrap_or(true)) .with_titlebar_buttons_hidden(!_titlebar_buttons_shown.unwrap_or(true)) .with_titlebar_transparent(!_titlebar_shown.unwrap_or(true)) - .with_fullsize_content_view(_fullsize_content_view.unwrap_or(false)); + .with_fullsize_content_view(_fullsize_content_view.unwrap_or(false)) + .with_movable_by_window_background(_movable_by_window_background.unwrap_or(false)); } window_attributes diff --git a/crates/egui/src/viewport.rs b/crates/egui/src/viewport.rs index 31cbc623e39..f2868cedf51 100644 --- a/crates/egui/src/viewport.rs +++ b/crates/egui/src/viewport.rs @@ -291,6 +291,7 @@ pub struct ViewportBuilder { // macOS: pub fullsize_content_view: Option, + pub movable_by_window_background: Option, pub title_shown: Option, pub titlebar_buttons_shown: Option, pub titlebar_shown: Option, @@ -432,6 +433,13 @@ impl ViewportBuilder { self } + /// macOS: Set to `true` to allow the window to be moved by dragging the background. + #[inline] + pub fn with_movable_by_background(mut self, value: bool) -> Self { + self.movable_by_window_background = Some(value); + self + } + /// macOS: Set to `false` to hide the window title. #[inline] pub fn with_title_shown(mut self, title_shown: bool) -> Self { @@ -631,6 +639,7 @@ impl ViewportBuilder { visible: new_visible, drag_and_drop: new_drag_and_drop, fullsize_content_view: new_fullsize_content_view, + movable_by_window_background: new_movable_by_window_background, title_shown: new_title_shown, titlebar_buttons_shown: new_titlebar_buttons_shown, titlebar_shown: new_titlebar_shown, @@ -816,6 +825,13 @@ impl ViewportBuilder { recreate_window = true; } + if new_movable_by_window_background.is_some() + && self.movable_by_window_background != new_movable_by_window_background + { + self.movable_by_window_background = new_movable_by_window_background; + recreate_window = true; + } + if new_drag_and_drop.is_some() && self.drag_and_drop != new_drag_and_drop { self.drag_and_drop = new_drag_and_drop; recreate_window = true; From 789d32d10f4f6f898b1c5ba8e182fe628f1cbb3a Mon Sep 17 00:00:00 2001 From: Jim Eckerlein Date: Tue, 17 Dec 2024 16:32:55 +0100 Subject: [PATCH 2/2] add warning about behaviour with draggable window background --- crates/egui/src/viewport.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/egui/src/viewport.rs b/crates/egui/src/viewport.rs index f2868cedf51..e41adfd8ef7 100644 --- a/crates/egui/src/viewport.rs +++ b/crates/egui/src/viewport.rs @@ -434,6 +434,8 @@ impl ViewportBuilder { } /// macOS: Set to `true` to allow the window to be moved by dragging the background. + /// + /// Enabling this feature can result in unexpected behaviour with draggable UI widgets such as sliders. #[inline] pub fn with_movable_by_background(mut self, value: bool) -> Self { self.movable_by_window_background = Some(value);