Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added helper functions #126

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading