use bitflags::bitflags;
use objc::{class, msg_send, sel, sel_impl};
use crate::{
foundation::{NSBundle, UInt},
object,
objective_c_runtime::{id, traits::FromId},
};
use super::{interface_impl, INSResponder, INSView, NSNibName, NSView};
bitflags! {
pub struct NSViewControllerTransitionOptions: UInt {
const NONE = 0x0;
const CROSSFADE = 0x1;
const SLIDE_UP = 0x10;
const SLIDE_DOWN = 0x20;
const SLIDE_LEFT = 0x40;
const SLIDE_RIGHT = 0x80;
const SLIDE_FORWARD = 0x140;
const SLIDE_BACKWARD = 0x180;
const ALLOW_USER_INTERACTION = 0x1000;
}
}
object! {
unsafe pub struct NSViewController;
}
impl NSViewController {
pub fn new() -> Self {
unsafe { Self::from_id(msg_send![class!(NSViewController), new]) }
}
}
impl Default for NSViewController {
fn default() -> Self {
Self::new()
}
}
impl INSResponder for NSViewController {}
#[interface_impl(NSResponder)]
impl NSViewController {
#[method]
pub fn init_with_nib_name_bundle(nib_name: NSNibName, bundle: NSBundle) -> Self
where
Self: Sized + FromId,
{
unsafe {
let obj: id = msg_send![Self::m_class(), alloc];
Self::from_id(msg_send![obj, initWithNibName: nib_name bundle: bundle])
}
}
#[method]
pub fn load_view(&self) {
unsafe { msg_send![self.m_self(), loadView] }
}
#[property]
pub fn represented_object(&self) -> id {
unsafe { msg_send![self.m_self(), representedObject] }
}
#[property]
pub fn nib_bundle(&self) -> NSBundle {
unsafe { NSBundle::from_id(msg_send![self.m_self(), nibBundle]) }
}
#[property]
pub fn nib_name(&self) -> NSNibName {
unsafe { NSNibName::from_id(msg_send![self.m_self(), nibName]) }
}
#[property]
pub fn view(&self) -> NSView {
unsafe { NSView::from_id(msg_send![self.m_self(), view]) }
}
#[property]
pub fn set_view<V>(&self, view: V)
where
V: INSView,
{
unsafe { msg_send![self.m_self(), setView: view] }
}
#[property]
pub fn title(&self) -> id {
unsafe { msg_send![self.m_self(), title] }
}
#[property]
pub fn set_title(&self, title: id) {
unsafe { msg_send![self.m_self(), setTitle: title] }
}
#[property]
pub fn view_did_load(&self) {
unsafe { msg_send![self.m_self(), viewDidLoad] }
}
}