Add platform::Window::titlebar_height

This commit is contained in:
Nathan Sobo 2021-08-06 09:08:29 -06:00
parent 34eb2c446f
commit e16c62ed0e
3 changed files with 18 additions and 0 deletions

View File

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

View File

@ -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 {

View File

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