From e16c62ed0e2ad6186c6474ea456bcd74e7c61bfd Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 6 Aug 2021 09:08:29 -0600 Subject: [PATCH] Add platform::Window::titlebar_height --- gpui/src/platform.rs | 1 + gpui/src/platform/mac/window.rs | 13 +++++++++++++ gpui/src/platform/test.rs | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/gpui/src/platform.rs b/gpui/src/platform.rs index 62225d66e8343a4587abe7690a212227f9c3927f..05c03811feb0013660dd7f89c291aa104ec33ca9 100644 --- a/gpui/src/platform.rs +++ b/gpui/src/platform.rs @@ -92,6 +92,7 @@ pub trait Window: WindowContext { pub trait WindowContext { fn size(&self) -> Vector2F; fn scale_factor(&self) -> f32; + fn titlebar_height(&self) -> f32; fn present_scene(&mut self, scene: Scene); } diff --git a/gpui/src/platform/mac/window.rs b/gpui/src/platform/mac/window.rs index 56969e80892f34266d72ec8cd166825f3a61a658..f12fe38ce6bd0184f46eb6f147e55f540c8231dd 100644 --- a/gpui/src/platform/mac/window.rs +++ b/gpui/src/platform/mac/window.rs @@ -15,6 +15,7 @@ use cocoa::{ foundation::{NSAutoreleasePool, NSInteger, NSSize, NSString}, quartzcore::AutoresizingMask, }; +use core_graphics::display::CGRect; use ctor::ctor; use foreign_types::ForeignType as _; use objc::{ @@ -336,6 +337,10 @@ impl platform::WindowContext for Window { fn present_scene(&mut self, scene: Scene) { self.0.as_ref().borrow_mut().present_scene(scene); } + + fn titlebar_height(&self) -> f32 { + self.0.as_ref().borrow().titlebar_height() + } } impl platform::WindowContext for WindowState { @@ -352,6 +357,14 @@ impl platform::WindowContext for WindowState { } } + fn titlebar_height(&self) -> f32 { + unsafe { + let frame = NSWindow::frame(self.native_window); + let content_layout_rect: CGRect = msg_send![self.native_window, contentLayoutRect]; + (frame.size.height - content_layout_rect.size.height) as f32 + } + } + fn present_scene(&mut self, scene: Scene) { self.scene_to_render = Some(scene); unsafe { diff --git a/gpui/src/platform/test.rs b/gpui/src/platform/test.rs index 77e23d5aa6773c5790545f04c47dca4291f22b40..86b1153424bc7bb9937ec66cd9047a44aa8f1cf1 100644 --- a/gpui/src/platform/test.rs +++ b/gpui/src/platform/test.rs @@ -164,6 +164,10 @@ impl super::WindowContext for Window { self.scale_factor } + fn titlebar_height(&self) -> f32 { + 24. + } + fn present_scene(&mut self, scene: crate::Scene) { self.current_scene = Some(scene); }