rust_macios/appkit/
ns_view_controller.rs1use bitflags::bitflags;
2use objc::{class, msg_send, sel, sel_impl};
3
4use crate::{
5 foundation::{NSBundle, UInt},
6 object,
7 objective_c_runtime::{id, traits::FromId},
8};
9
10use super::{interface_impl, INSResponder, INSView, NSNibName, NSView};
11
12bitflags! {
13 pub struct NSViewControllerTransitionOptions: UInt {
14 const NONE = 0x0;
15 const CROSSFADE = 0x1;
16 const SLIDE_UP = 0x10;
17 const SLIDE_DOWN = 0x20;
18 const SLIDE_LEFT = 0x40;
19 const SLIDE_RIGHT = 0x80;
20 const SLIDE_FORWARD = 0x140;
21 const SLIDE_BACKWARD = 0x180;
22 const ALLOW_USER_INTERACTION = 0x1000;
23 }
24}
25
26object! {
27 unsafe pub struct NSViewController;
29}
30
31impl NSViewController {
32 pub fn new() -> Self {
34 unsafe { Self::from_id(msg_send![class!(NSViewController), new]) }
35 }
36}
37
38impl Default for NSViewController {
39 fn default() -> Self {
40 Self::new()
41 }
42}
43
44impl INSResponder for NSViewController {}
45
46#[interface_impl(NSResponder)]
47impl NSViewController {
48 #[method]
53 pub fn init_with_nib_name_bundle(nib_name: NSNibName, bundle: NSBundle) -> Self
54 where
55 Self: Sized + FromId,
56 {
57 unsafe {
58 let obj: id = msg_send![Self::m_class(), alloc];
59 Self::from_id(msg_send![obj, initWithNibName: nib_name bundle: bundle])
60 }
61 }
62
63 #[method]
65 pub fn load_view(&self) {
66 unsafe { msg_send![self.m_self(), loadView] }
67 }
68
69 #[property]
74 pub fn represented_object(&self) -> id {
75 unsafe { msg_send![self.m_self(), representedObject] }
76 }
77
78 #[property]
83 pub fn nib_bundle(&self) -> NSBundle {
84 unsafe { NSBundle::from_id(msg_send![self.m_self(), nibBundle]) }
85 }
86
87 #[property]
89 pub fn nib_name(&self) -> NSNibName {
90 unsafe { NSNibName::from_id(msg_send![self.m_self(), nibName]) }
91 }
92
93 #[property]
98 pub fn view(&self) -> NSView {
99 unsafe { NSView::from_id(msg_send![self.m_self(), view]) }
100 }
101
102 #[property]
108 pub fn set_view<V>(&self, view: V)
109 where
110 V: INSView,
111 {
112 unsafe { msg_send![self.m_self(), setView: view] }
113 }
114
115 #[property]
117 pub fn title(&self) -> id {
118 unsafe { msg_send![self.m_self(), title] }
119 }
120
121 #[property]
127 pub fn set_title(&self, title: id) {
128 unsafe { msg_send![self.m_self(), setTitle: title] }
129 }
130
131 #[property]
136 pub fn view_did_load(&self) {
137 unsafe { msg_send![self.m_self(), viewDidLoad] }
138 }
139}