Add platform::Window::titlebar_height

Nathan Sobo created

Change summary

gpui/src/platform.rs            |  1 +
gpui/src/platform/mac/window.rs | 13 +++++++++++++
gpui/src/platform/test.rs       |  4 ++++
3 files changed, 18 insertions(+)

Detailed changes

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

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 {

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