From e1c33310afdcfaee2c7d708b8dd91a5e369ba832 Mon Sep 17 00:00:00 2001 From: Jack Hogan Date: Sun, 15 Sep 2024 12:09:24 -0400 Subject: [PATCH 1/2] Added more helper functions --- src/appkit/app/mod.rs | 6 ++++++ src/appkit/window/mod.rs | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/appkit/app/mod.rs b/src/appkit/app/mod.rs index a266d925..c43ea471 100644 --- a/src/appkit/app/mod.rs +++ b/src/appkit/app/mod.rs @@ -224,6 +224,12 @@ impl App { }); } + pub fn update_windows() { + shared_application(|app| unsafe { + let _: () = msg_send![app, updateWindows]; + }); + } + /// Unregisters for remote notifications from APNS. pub fn unregister_for_remote_notifications() { shared_application(|app| unsafe { diff --git a/src/appkit/window/mod.rs b/src/appkit/window/mod.rs index e25b5661..23c3ee3e 100644 --- a/src/appkit/window/mod.rs +++ b/src/appkit/window/mod.rs @@ -20,6 +20,7 @@ use objc::{class, msg_send, msg_send_id, sel}; use crate::appkit::toolbar::{Toolbar, ToolbarDelegate}; use crate::color::Color; use crate::foundation::{id, nil, to_bool, NSInteger, NSString, NSUInteger, NO, YES}; +use crate::geometry::Rect; use crate::layout::Layout; use crate::objc_access::ObjcAccess; use crate::utils::{os, Controller}; @@ -338,6 +339,49 @@ impl Window { } } + pub fn set_scale(&self, rect: Rect) { + let rect: CGRect = rect.into(); + unsafe { + let _: () = msg_send![&*self.objc, setFrame:rect display:YES]; + } + } + + pub fn set_ignores_mouse_events(&self, ignore: bool) { + unsafe { + let _: () = msg_send![&*self.objc, setIgnoresMouseEvents:match ignore { + true => YES, + false => NO, + }]; + } + } + + pub fn set_accepts_mouse_moved_events(&self, accept: bool) { + unsafe { + let _: () = msg_send![&*self.objc, setAcceptsMouseMovedEvents:match accept { + true => YES, + false => NO, + }]; + } + } + + pub fn set_is_visible(&self, visible: bool) { + unsafe { + let _: () = msg_send![&*self.objc, setIsVisible:match visible { + true => YES, + false => NO, + }]; + } + } + + pub fn set_has_shadow(&self, shadow: bool) { + unsafe { + let _: () = msg_send![&*self.objc, setHasShadow:match shadow { + true => YES, + false => NO, + }]; + } + } + /// Return the objc ContentView from the window pub(crate) unsafe fn content_view(&self) -> id { let id: *mut Object = msg_send![&*self.objc, contentView]; From df5709986d3a7766ba32230a8dc9dde524a28a63 Mon Sep 17 00:00:00 2001 From: Jack Hogan Date: Mon, 16 Sep 2024 16:42:22 -0400 Subject: [PATCH 2/2] Add docs --- src/appkit/app/mod.rs | 1 + src/appkit/window/mod.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/appkit/app/mod.rs b/src/appkit/app/mod.rs index c43ea471..8b57f576 100644 --- a/src/appkit/app/mod.rs +++ b/src/appkit/app/mod.rs @@ -224,6 +224,7 @@ impl App { }); } + /// Sends an update() message to each onscreen window. pub fn update_windows() { shared_application(|app| unsafe { let _: () = msg_send![app, updateWindows]; diff --git a/src/appkit/window/mod.rs b/src/appkit/window/mod.rs index 23c3ee3e..e555d499 100644 --- a/src/appkit/window/mod.rs +++ b/src/appkit/window/mod.rs @@ -339,13 +339,16 @@ impl Window { } } - pub fn set_scale(&self, rect: Rect) { + /// Sets the origin and size of the window’s frame rectangle according to a given frame rectangle, + /// thereby setting its position and size onscreen. + pub fn set_frame(&self, rect: Rect) { let rect: CGRect = rect.into(); unsafe { let _: () = msg_send![&*self.objc, setFrame:rect display:YES]; } } + /// Sets whether the window is transparent to mouse events. pub fn set_ignores_mouse_events(&self, ignore: bool) { unsafe { let _: () = msg_send![&*self.objc, setIgnoresMouseEvents:match ignore { @@ -355,6 +358,7 @@ impl Window { } } + /// Sets whether the window accepts mouse-moved events. pub fn set_accepts_mouse_moved_events(&self, accept: bool) { unsafe { let _: () = msg_send![&*self.objc, setAcceptsMouseMovedEvents:match accept { @@ -364,6 +368,7 @@ impl Window { } } + /// Sets the window’s visible state to the value you specify. pub fn set_is_visible(&self, visible: bool) { unsafe { let _: () = msg_send![&*self.objc, setIsVisible:match visible { @@ -373,6 +378,7 @@ impl Window { } } + /// Sets whether the window has a shadow. pub fn set_has_shadow(&self, shadow: bool) { unsafe { let _: () = msg_send![&*self.objc, setHasShadow:match shadow {