feat(macos): add setters to set title bar style on macOS (#926)

* feat(macos): add setters to set title bar style on macOS

* fix: bool to BOOL
This commit is contained in:
Jason Tsai
2024-05-15 23:44:30 +08:00
committed by GitHub
parent 422f29c635
commit 7e8f75e916
3 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
'tao': patch
---
On macOS, add `set_fullsize_content_view` and `set_titlebar_transparent` to `Window` to set the title bar style.

View File

@@ -74,6 +74,16 @@ pub trait WindowExtMacOS {
/// Returns the window's tabbing identifier.
fn tabbing_identifier(&self) -> String;
/// The content view consumes the full size of the window.
///
/// <https://developer.apple.com/documentation/appkit/nsfullsizecontentviewwindowmask>
fn set_fullsize_content_view(&self, fullsize: bool);
/// A Boolean value that indicates whether the title bar draws its background.
///
/// <https://developer.apple.com/documentation/appkit/nswindow/1419167-titlebarappearstransparent>
fn set_titlebar_transparent(&self, transparent: bool);
}
impl WindowExtMacOS for Window {
@@ -141,6 +151,16 @@ impl WindowExtMacOS for Window {
fn tabbing_identifier(&self) -> String {
self.window.tabbing_identifier()
}
#[inline]
fn set_fullsize_content_view(&self, fullsize: bool) {
self.window.set_fullsize_content_view(fullsize);
}
#[inline]
fn set_titlebar_transparent(&self, transparent: bool) {
self.window.set_titlebar_transparent(transparent);
}
}
/// Corresponds to `NSApplicationActivationPolicy`.

View File

@@ -1613,6 +1613,26 @@ impl WindowExtMacOS for UnownedWindow {
ns_string_to_rust(tabbing_identifier)
}
}
#[inline]
fn set_fullsize_content_view(&self, fullsize: bool) {
let mut mask = unsafe { self.ns_window.styleMask() };
if fullsize {
mask |= NSWindowStyleMask::NSFullSizeContentViewWindowMask;
} else {
mask &= !NSWindowStyleMask::NSFullSizeContentViewWindowMask;
}
self.set_style_mask_sync(mask);
}
#[inline]
fn set_titlebar_transparent(&self, transparent: bool) {
unsafe {
self
.ns_window
.setTitlebarAppearsTransparent_(transparent as BOOL);
}
}
}
impl Drop for UnownedWindow {