Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: Add movable_by_window_background option to viewport #5412

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions crates/egui/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ pub struct ViewportBuilder {

// macOS:
pub fullsize_content_view: Option<bool>,
pub movable_by_window_background: Option<bool>,
pub title_shown: Option<bool>,
pub titlebar_buttons_shown: Option<bool>,
pub titlebar_shown: Option<bool>,
Expand Down Expand Up @@ -432,6 +433,15 @@ impl ViewportBuilder {
self
}

/// 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);
self
}

/// macOS: Set to `false` to hide the window title.
#[inline]
pub fn with_title_shown(mut self, title_shown: bool) -> Self {
Expand Down Expand Up @@ -631,6 +641,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,
Expand Down Expand Up @@ -816,6 +827,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;
Expand Down