Skip to content

Commit

Permalink
Added helper functions (#126)
Browse files Browse the repository at this point in the history
* Added more helper functions

* Add docs
  • Loading branch information
ImTheSquid authored Sep 16, 2024
1 parent 7ffe398 commit 6fc579f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/appkit/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ impl App {
});
}

/// Sends an update() message to each onscreen window.
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 {
Expand Down
50 changes: 50 additions & 0 deletions src/appkit/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -338,6 +339,55 @@ impl<T> Window<T> {
}
}

/// 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 {
true => YES,
false => NO,
}];
}
}

/// 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 {
true => YES,
false => NO,
}];
}
}

/// 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 {
true => YES,
false => NO,
}];
}
}

/// Sets whether the window has a shadow.
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];
Expand Down

0 comments on commit 6fc579f

Please sign in to comment.