1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

macOS: Add movable_by_window_background option to viewport (#5412)

Add an option called `movable_by_window_background` alongside a new
builder method. When set to true, the window is movable by dragging its
background ([Apple
Docs](https://developer.apple.com/documentation/appkit/nswindow/ismovablebywindowbackground))

This is exclusive to macOS systems, similar to `fullsize_content_view`.

* [x] I have followed the instructions in the PR template
This commit is contained in:
Jim
2025-03-20 11:05:22 +01:00
committed by GitHub
parent 52732b23a6
commit d54e29d375
2 changed files with 21 additions and 1 deletions

View File

@@ -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>,
@@ -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 {
@@ -640,6 +650,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,
@@ -825,6 +836,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;