[go: up one dir, main page]

Struct NSSize

Source
#[repr(C)]
pub struct NSSize { pub width: f64, pub height: f64, }
👎Deprecated: use the objc2-foundation crate instead

Fields§

§width: f64
👎Deprecated: use the objc2-foundation crate instead
§height: f64
👎Deprecated: use the objc2-foundation crate instead

Implementations§

Source§

impl NSSize

Source

pub fn new(width: f64, height: f64) -> NSSize

👎Deprecated: use the objc2-foundation crate instead
Examples found in repository?
examples/color.rs (line 89)
86unsafe fn create_window(title: id, color: id) -> id {
87    let window = NSWindow::alloc(nil)
88        .initWithContentRect_styleMask_backing_defer_(
89            NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)),
90            NSWindowStyleMask::NSTitledWindowMask
91                | NSWindowStyleMask::NSClosableWindowMask
92                | NSWindowStyleMask::NSResizableWindowMask
93                | NSWindowStyleMask::NSMiniaturizableWindowMask
94                | NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask,
95            NSBackingStoreType::NSBackingStoreBuffered,
96            NO,
97        )
98        .autorelease();
99
100    window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.));
101    window.setTitle_(title);
102    window.setBackgroundColor_(color);
103    window.makeKeyAndOrderFront_(nil);
104    window
105}
More examples
Hide additional examples
examples/tab_view.rs (line 15)
11fn main() {
12    unsafe {
13        // create a tab View
14        let tab_view = NSTabView::new(nil)
15            .initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)));
16
17        // create a tab view item
18        let tab_view_item =
19            NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView1"));
20
21        tab_view_item.setLabel_(NSString::alloc(nil).init_str("Tab view item 1"));
22        tab_view.addTabViewItem_(tab_view_item);
23
24        // create a second tab view item
25        let tab_view_item2 =
26            NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView2"));
27
28        tab_view_item2.setLabel_(NSString::alloc(nil).init_str("Tab view item 2"));
29        tab_view.addTabViewItem_(tab_view_item2);
30
31        // Create the app and set the content.
32        let app = create_app(NSString::alloc(nil).init_str("Tab View"), tab_view);
33        app.run();
34    }
35}
36
37unsafe fn create_app(title: id, content: id) -> id {
38    let _pool = NSAutoreleasePool::new(nil);
39
40    let app = NSApp();
41    app.setActivationPolicy_(NSApplicationActivationPolicyRegular);
42
43    // create Menu Bar
44    let menubar = NSMenu::new(nil).autorelease();
45    let app_menu_item = NSMenuItem::new(nil).autorelease();
46    menubar.addItem_(app_menu_item);
47    app.setMainMenu_(menubar);
48
49    // create Application menu
50    let app_menu = NSMenu::new(nil).autorelease();
51    let quit_prefix = NSString::alloc(nil).init_str("Quit ");
52    let quit_title =
53        quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName());
54    let quit_action = selector("terminate:");
55    let quit_key = NSString::alloc(nil).init_str("q");
56    let quit_item = NSMenuItem::alloc(nil)
57        .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key)
58        .autorelease();
59    app_menu.addItem_(quit_item);
60    app_menu_item.setSubmenu_(app_menu);
61
62    // create Window
63    let window = NSWindow::alloc(nil)
64        .initWithContentRect_styleMask_backing_defer_(
65            NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)),
66            NSWindowStyleMask::NSTitledWindowMask
67                | NSWindowStyleMask::NSClosableWindowMask
68                | NSWindowStyleMask::NSResizableWindowMask
69                | NSWindowStyleMask::NSMiniaturizableWindowMask
70                | NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask,
71            NSBackingStoreType::NSBackingStoreBuffered,
72            NO,
73        )
74        .autorelease();
75    window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.));
76    window.center();
77
78    window.setTitle_(title);
79    window.makeKeyAndOrderFront_(nil);
80
81    window.setContentView_(content);
82    let current_app = NSRunningApplication::currentApplication(nil);
83    current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
84
85    app
86}
examples/hello_world.rs (line 39)
10fn main() {
11    unsafe {
12        let _pool = NSAutoreleasePool::new(nil);
13
14        let app = NSApp();
15        app.setActivationPolicy_(NSApplicationActivationPolicyRegular);
16
17        // create Menu Bar
18        let menubar = NSMenu::new(nil).autorelease();
19        let app_menu_item = NSMenuItem::new(nil).autorelease();
20        menubar.addItem_(app_menu_item);
21        app.setMainMenu_(menubar);
22
23        // create Application menu
24        let app_menu = NSMenu::new(nil).autorelease();
25        let quit_prefix = NSString::alloc(nil).init_str("Quit ");
26        let quit_title =
27            quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName());
28        let quit_action = selector("terminate:");
29        let quit_key = NSString::alloc(nil).init_str("q");
30        let quit_item = NSMenuItem::alloc(nil)
31            .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key)
32            .autorelease();
33        app_menu.addItem_(quit_item);
34        app_menu_item.setSubmenu_(app_menu);
35
36        // create Window
37        let window = NSWindow::alloc(nil)
38            .initWithContentRect_styleMask_backing_defer_(
39                NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)),
40                NSWindowStyleMask::NSTitledWindowMask,
41                NSBackingStoreBuffered,
42                NO,
43            )
44            .autorelease();
45        window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.));
46        window.center();
47        let title = NSString::alloc(nil).init_str("Hello World!");
48        window.setTitle_(title);
49        window.makeKeyAndOrderFront_(nil);
50        let current_app = NSRunningApplication::currentApplication(nil);
51        current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
52        app.run();
53    }
54}
examples/nsvisualeffectview_blur.rs (line 46)
13fn main() {
14    unsafe {
15        // Create the app.
16        let _pool = NSAutoreleasePool::new(nil);
17
18        let app = NSApp();
19        app.setActivationPolicy_(NSApplicationActivationPolicyRegular);
20
21        // create Menu Bar
22        let menubar = NSMenu::new(nil).autorelease();
23        let app_menu_item = NSMenuItem::new(nil).autorelease();
24        menubar.addItem_(app_menu_item);
25        app.setMainMenu_(menubar);
26
27        // create Application menu
28        let app_menu = NSMenu::new(nil).autorelease();
29        let quit_prefix = NSString::alloc(nil).init_str("Quit ");
30        let quit_title =
31            quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName());
32        let quit_action = selector("terminate:");
33        let quit_key = NSString::alloc(nil).init_str("q");
34        let quit_item = NSMenuItem::alloc(nil)
35            .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key)
36            .autorelease();
37        app_menu.addItem_(quit_item);
38        app_menu_item.setSubmenu_(app_menu);
39
40        // Create some colors
41        let clear = NSColor::clearColor(nil);
42
43        // Create windows with different color types.
44        let window = NSWindow::alloc(nil)
45            .initWithContentRect_styleMask_backing_defer_(
46                NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)),
47                NSWindowStyleMask::NSTitledWindowMask
48                    | NSWindowStyleMask::NSClosableWindowMask
49                    | NSWindowStyleMask::NSResizableWindowMask
50                    | NSWindowStyleMask::NSMiniaturizableWindowMask
51                    | NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask,
52                NSBackingStoreType::NSBackingStoreBuffered,
53                NO,
54            )
55            .autorelease();
56
57        window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.));
58        window.setTitle_(NSString::alloc(nil).init_str("NSVisualEffectView_blur"));
59        window.setBackgroundColor_(clear);
60        window.makeKeyAndOrderFront_(nil);
61
62        //NSVisualEffectView blur
63        let ns_view = window.contentView();
64        let bounds = NSView::bounds(ns_view);
65        let blurred_view =
66            NSVisualEffectView::initWithFrame_(NSVisualEffectView::alloc(nil), bounds);
67        blurred_view.autorelease();
68
69        blurred_view.setMaterial_(NSVisualEffectMaterial::HudWindow);
70        blurred_view.setBlendingMode_(NSVisualEffectBlendingMode::BehindWindow);
71        blurred_view.setState_(NSVisualEffectState::FollowsWindowActiveState);
72        blurred_view.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable);
73
74        let _: () = msg_send![ns_view, addSubview: blurred_view positioned: NSWindowOrderingMode::NSWindowBelow relativeTo: 0];
75
76        app.run();
77    }
78}
examples/fullscreen.rs (line 91)
19fn main() {
20    unsafe {
21        let _pool = NSAutoreleasePool::new(nil);
22
23        let app = NSApp();
24        app.setActivationPolicy_(NSApplicationActivationPolicyRegular);
25
26        // create Menu Bar
27        let menubar = NSMenu::new(nil).autorelease();
28        let app_menu_item = NSMenuItem::new(nil).autorelease();
29        menubar.addItem_(app_menu_item);
30        app.setMainMenu_(menubar);
31
32        // create Application menu
33        let app_menu = NSMenu::new(nil).autorelease();
34        let quit_prefix = NSString::alloc(nil).init_str("Quit ");
35        let quit_title =
36            quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName());
37        let quit_action = selector("terminate:");
38        let quit_key = NSString::alloc(nil).init_str("q");
39        let quit_item = NSMenuItem::alloc(nil)
40            .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key)
41            .autorelease();
42        app_menu.addItem_(quit_item);
43        app_menu_item.setSubmenu_(app_menu);
44
45        // Create NSWindowDelegate
46        let superclass = class!(NSObject);
47        let mut decl = ClassDecl::new("MyWindowDelegate", superclass).unwrap();
48
49        extern "C" fn will_use_fillscreen_presentation_options(
50            _: &Object,
51            _: Sel,
52            _: id,
53            _: NSUInteger,
54        ) -> NSUInteger {
55            // Set initial presentation options for fullscreen
56            let options = NSApplicationPresentationOptions::NSApplicationPresentationFullScreen
57                | NSApplicationPresentationOptions::NSApplicationPresentationHideDock
58                | NSApplicationPresentationOptions::NSApplicationPresentationHideMenuBar
59                | NSApplicationPresentationOptions::NSApplicationPresentationDisableProcessSwitching;
60            options.bits()
61        }
62
63        extern "C" fn window_entering_fullscreen(_: &Object, _: Sel, _: id) {
64            // Reset HideDock and HideMenuBar settings during/after we entered fullscreen.
65            let options = NSApplicationPresentationOptions::NSApplicationPresentationHideDock
66                | NSApplicationPresentationOptions::NSApplicationPresentationHideMenuBar;
67            unsafe {
68                NSApp().setPresentationOptions_(options);
69            }
70        }
71
72        decl.add_method(
73            sel!(window:willUseFullScreenPresentationOptions:),
74            will_use_fillscreen_presentation_options
75                as extern "C" fn(&Object, Sel, id, NSUInteger) -> NSUInteger,
76        );
77        decl.add_method(
78            sel!(windowWillEnterFullScreen:),
79            window_entering_fullscreen as extern "C" fn(&Object, Sel, id),
80        );
81        decl.add_method(
82            sel!(windowDidEnterFullScreen:),
83            window_entering_fullscreen as extern "C" fn(&Object, Sel, id),
84        );
85
86        let delegate_class = decl.register();
87        let delegate_object = msg_send![delegate_class, new];
88
89        // create Window
90        let display = CGDisplay::main();
91        let size = NSSize::new(display.pixels_wide() as _, display.pixels_high() as _);
92        let window = NSWindow::alloc(nil)
93            .initWithContentRect_styleMask_backing_defer_(
94                NSRect::new(NSPoint::new(0., 0.), size),
95                NSWindowStyleMask::NSTitledWindowMask,
96                NSBackingStoreBuffered,
97                NO,
98            )
99            .autorelease();
100        window.setDelegate_(delegate_object);
101        let title = NSString::alloc(nil).init_str("Fullscreen!");
102        window.setTitle_(title);
103        window.makeKeyAndOrderFront_(nil);
104
105        let current_app = NSRunningApplication::currentApplication(nil);
106        current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
107        window.setCollectionBehavior_(
108            NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenPrimary,
109        );
110        window.toggleFullScreen_(nil);
111        app.run();
112    }
113}

Trait Implementations§

Source§

impl Clone for NSSize

Source§

fn clone(&self) -> NSSize

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Encode for NSSize

Source§

fn encode() -> Encoding

Returns the Objective-C type encoding for Self.
Source§

impl Copy for NSSize

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.