diff --git a/cidre/pomace/ui/ui.h b/cidre/pomace/ui/ui.h index af8c76aa..a5d86cb9 100644 --- a/cidre/pomace/ui/ui.h +++ b/cidre/pomace/ui/ui.h @@ -11,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN Class UI_DEVICE; Class UI_VIEW; +Class UI_SCENE; +Class UI_SCENE_CONFIGURATION; Class UI_COLOR; Class UI_RESPONDER; Class UI_VIEW_CONTROLLER; @@ -25,8 +27,10 @@ static void ui_initializer(void) if (!initialized) { initialized = 1; - UI_DEVICE = NSClassFromString(@"UIDevice");//[UIDevice class]; - UI_VIEW = NSClassFromString(@"UIView");//[UIView class]; + UI_DEVICE = NSClassFromString(@"UIDevice"); + UI_SCENE = NSClassFromString(@"UIScene"); + UI_VIEW = NSClassFromString(@"UIView"); + UI_SCENE_CONFIGURATION = NSClassFromString(@"UISceneConfiguration"); UI_COLOR = [UIColor class]; UI_RESPONDER = NSClassFromString(@"UIResponder");//[UIResponder class]; UI_VIEW_CONTROLLER = NSClassFromString(@"UIViewController");//[UIViewController class]; diff --git a/cidre/src/ui.rs b/cidre/src/ui.rs index 36b5b7da..8d9d19d5 100644 --- a/cidre/src/ui.rs +++ b/cidre/src/ui.rs @@ -24,3 +24,41 @@ mod interaction; pub use interaction::AnyInteraction; pub use interaction::Interaction; pub use interaction::InteractionImpl; + +mod scene_definitions; +pub use scene_definitions::SceneSessionRole; + +mod scene; +pub use scene::AnySceneDelegate; +pub use scene::Scene; +pub use scene::SceneDelegate; + +mod scene_session; +pub use scene_session::SceneCfg; +pub use scene_session::SceneSession; + +mod scene_options; +pub use scene_options::SceneConnectionOpts; + +pub fn app_main( + principal_class_name: Option<&crate::ns::String>, + delegate_class_name: Option<&crate::ns::String>, +) -> std::ffi::c_int { + unsafe { + UIApplicationMain( + 0, + std::ptr::null(), + principal_class_name, + delegate_class_name, + ) + } +} + +extern "C" { + fn UIApplicationMain( + argc: std::ffi::c_int, + argv: *const *const std::ffi::c_char, + principal_class_name: Option<&crate::ns::String>, + delegate_class_name: Option<&crate::ns::String>, + ) -> std::ffi::c_int; +} diff --git a/cidre/src/ui/scene.rs b/cidre/src/ui/scene.rs new file mode 100644 index 00000000..418dc518 --- /dev/null +++ b/cidre/src/ui/scene.rs @@ -0,0 +1,38 @@ +use crate::{arc, define_cls, define_obj_type, ns, objc, ui}; + +define_obj_type!( + pub Scene(ui::Responder) +); + +impl Scene { + define_cls!(UI_SCENE); + + #[objc::msg_send(delegate)] + pub fn delegate(&self) -> Option<&AnySceneDelegate>; + + #[objc::msg_send(setDelegate:)] + pub fn set_delegate(&mut self, val: Option<&D>); +} + +#[objc::protocol(UISceneDelegate)] +pub trait SceneDelegate: objc::Obj { + #[objc::optional] + #[objc::msg_send(scene:willConnectToSession:options:)] + fn scene_will_connect_to_session( + &mut self, + scene: &Scene, + session: &ui::SceneSession, + options: &ui::SceneConnectionOpts, + ); +} + +define_obj_type!( + pub AnySceneDelegate(ns::Id) +); + +impl SceneDelegate for AnySceneDelegate {} + +#[link(name = "ui", kind = "static")] +extern "C" { + static UI_SCENE: &'static objc::Class; +} diff --git a/cidre/src/ui/scene_definitions.rs b/cidre/src/ui/scene_definitions.rs new file mode 100644 index 00000000..960150e6 --- /dev/null +++ b/cidre/src/ui/scene_definitions.rs @@ -0,0 +1,6 @@ +use crate::{define_obj_type, ns}; + +define_obj_type!( + #[doc(alias = "UISceneSessionRole")] + pub SceneSessionRole(ns::String) +); diff --git a/cidre/src/ui/scene_options.rs b/cidre/src/ui/scene_options.rs new file mode 100644 index 00000000..c9a32760 --- /dev/null +++ b/cidre/src/ui/scene_options.rs @@ -0,0 +1,5 @@ +use crate::{define_obj_type, ns}; + +define_obj_type!( + pub SceneConnectionOpts(ns::Id) +); diff --git a/cidre/src/ui/scene_session.rs b/cidre/src/ui/scene_session.rs new file mode 100644 index 00000000..718b9feb --- /dev/null +++ b/cidre/src/ui/scene_session.rs @@ -0,0 +1,57 @@ +use crate::{arc, define_cls, define_obj_type, ns, objc, ui}; + +define_obj_type!( + #[doc(alias = "UISceneConfiguration")] + pub SceneCfg(ns::Id) +); + +impl arc::A { + #[objc::msg_send(initWithName:sessionRole:)] + pub fn init_with_name_role( + self, + name: Option<&ns::String>, + session_role: ui::SceneSessionRole, + ) -> arc::R; +} + +impl SceneCfg { + define_cls!(UI_SCENE_CONFIGURATION); + + pub fn with_name_role( + name: Option<&ns::String>, + session_role: ui::SceneSessionRole, + ) -> arc::R { + Self::alloc().init_with_name_role(name, session_role) + } + + #[objc::msg_send(name)] + pub fn name(&self) -> Option<&ns::String>; + + #[objc::msg_send(setName:)] + pub fn set_name(&mut self, val: Option<&ns::String>); + + #[objc::msg_send(role)] + pub fn role(&self) -> &ui::SceneSessionRole; + + #[objc::msg_send(delegateClass)] + pub fn delegate_class(&self) -> Option<&ns::Class>; + + #[objc::msg_send(setDelegateClass:)] + pub fn set_delegate_class(&mut self, val: Option<&ns::Class>); + + #[objc::msg_send(userInfo)] + pub fn user_info(&self) -> Option<&ns::Dictionary>; +} + +define_obj_type!( + pub SceneSession(ns::Id) +); + +impl SceneSession { + #[objc::msg_send(scene)] + pub fn scene(&self) -> Option<&ui::Scene>; +} + +extern "C" { + static UI_SCENE_CONFIGURATION: &'static objc::Class; +}