Skip to content

Commit

Permalink
continue on UIKit
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Dec 30, 2024
1 parent 1b72125 commit 85fbbe5
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cidre/pomace/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand Down
38 changes: 38 additions & 0 deletions cidre/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
38 changes: 38 additions & 0 deletions cidre/src/ui/scene.rs
Original file line number Diff line number Diff line change
@@ -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<D: SceneDelegate>(&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<Scene>;
}
6 changes: 6 additions & 0 deletions cidre/src/ui/scene_definitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::{define_obj_type, ns};

define_obj_type!(
#[doc(alias = "UISceneSessionRole")]
pub SceneSessionRole(ns::String)
);
5 changes: 5 additions & 0 deletions cidre/src/ui/scene_options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::{define_obj_type, ns};

define_obj_type!(
pub SceneConnectionOpts(ns::Id)
);
57 changes: 57 additions & 0 deletions cidre/src/ui/scene_session.rs
Original file line number Diff line number Diff line change
@@ -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<SceneCfg> {
#[objc::msg_send(initWithName:sessionRole:)]
pub fn init_with_name_role(
self,
name: Option<&ns::String>,
session_role: ui::SceneSessionRole,
) -> arc::R<SceneCfg>;
}

impl SceneCfg {
define_cls!(UI_SCENE_CONFIGURATION);

pub fn with_name_role(
name: Option<&ns::String>,
session_role: ui::SceneSessionRole,
) -> arc::R<Self> {
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<ns::Id>>;

#[objc::msg_send(setDelegateClass:)]
pub fn set_delegate_class(&mut self, val: Option<&ns::Class<ns::Id>>);

#[objc::msg_send(userInfo)]
pub fn user_info(&self) -> Option<&ns::Dictionary<ns::String, ns::Id>>;
}

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<SceneCfg>;
}

0 comments on commit 85fbbe5

Please # to comment.