diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index e541273fa48..602389b8a68 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -1623,6 +1623,7 @@ pub fn create_winit_window_attributes( title_shown: _title_shown, titlebar_buttons_shown: _titlebar_buttons_shown, titlebar_shown: _titlebar_shown, + has_shadow: _has_shadow, // Windows: drag_and_drop: _drag_and_drop, @@ -1767,7 +1768,8 @@ pub fn create_winit_window_attributes( .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_movable_by_window_background(_movable_by_window_background.unwrap_or(false)); + .with_movable_by_window_background(_movable_by_window_background.unwrap_or(false)) + .with_has_shadow(_has_shadow.unwrap_or(true)); } window_attributes diff --git a/crates/egui/src/viewport.rs b/crates/egui/src/viewport.rs index 9aba699100e..17a74762ff5 100644 --- a/crates/egui/src/viewport.rs +++ b/crates/egui/src/viewport.rs @@ -295,6 +295,7 @@ pub struct ViewportBuilder { pub title_shown: Option, pub titlebar_buttons_shown: Option, pub titlebar_shown: Option, + pub has_shadow: Option, // windows: pub drag_and_drop: Option, @@ -381,6 +382,10 @@ impl ViewportBuilder { /// The default is `false`. /// If this is not working, it's because the graphic context doesn't support transparency, /// you will need to set the transparency in the eframe! + /// + /// ## Platform-specific + /// + /// **macOS:** When using this feature to create an overlay-like UI, you likely want to combine this with [`Self::with_has_shadow`] set to `false` in order to avoid ghosting artifacts. #[inline] pub fn with_transparent(mut self, transparent: bool) -> Self { self.transparent = Some(transparent); @@ -434,7 +439,6 @@ 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 { @@ -463,6 +467,19 @@ impl ViewportBuilder { self } + /// macOS: Set to `false` to make the window render without a drop shadow. + /// + /// The default is `true`. + /// + /// Disabling this feature can solve ghosting issues experienced if using [`Self::with_transparent`]. + /// + /// Look at winit for more details + #[inline] + pub fn with_has_shadow(mut self, has_shadow: bool) -> Self { + self.has_shadow = Some(has_shadow); + self + } + /// windows: Whether show or hide the window icon in the taskbar. #[inline] pub fn with_taskbar(mut self, show: bool) -> Self { @@ -654,6 +671,7 @@ impl ViewportBuilder { title_shown: new_title_shown, titlebar_buttons_shown: new_titlebar_buttons_shown, titlebar_shown: new_titlebar_shown, + has_shadow: new_has_shadow, close_button: new_close_button, minimize_button: new_minimize_button, maximize_button: new_maximize_button, @@ -824,6 +842,11 @@ impl ViewportBuilder { recreate_window = true; } + if new_has_shadow.is_some() && self.has_shadow != new_has_shadow { + self.has_shadow = new_has_shadow; + recreate_window = true; + } + if new_taskbar.is_some() && self.taskbar != new_taskbar { self.taskbar = new_taskbar; recreate_window = true;