diff --git a/cidre/src/cg/affine_transform.rs b/cidre/src/cg/affine_transform.rs index 046ffc03..0f2b1e6a 100644 --- a/cidre/src/cg/affine_transform.rs +++ b/cidre/src/cg/affine_transform.rs @@ -3,12 +3,12 @@ use crate::cg; #[derive(Debug, Copy, Clone)] #[repr(C)] pub struct AffineTransform { - pub a: f64, - pub b: f64, - pub c: f64, - pub d: f64, - pub tx: f64, - pub ty: f64, + pub a: cg::Float, + pub b: cg::Float, + pub c: cg::Float, + pub d: cg::Float, + pub tx: cg::Float, + pub ty: cg::Float, } /* |--------------------------- Components ------------------------| diff --git a/cidre/src/cg/geometry.rs b/cidre/src/cg/geometry.rs index 0e07c9a6..5edc8f46 100644 --- a/cidre/src/cg/geometry.rs +++ b/cidre/src/cg/geometry.rs @@ -1,9 +1,9 @@ use crate::{arc, cf}; -// #[cfg(target_os = "watchos")] -// pub type Float = f32; +#[cfg(target_pointer_width = "32")] +pub type Float = f32; -// #[cfg(not(target_os = "watchos"))] +#[cfg(target_pointer_width = "64")] pub type Float = f64; #[derive(Clone, Copy, PartialEq, PartialOrd, Debug, Default)] diff --git a/cidre/src/cg/path.rs b/cidre/src/cg/path.rs index 0deb981b..bab9011e 100644 --- a/cidre/src/cg/path.rs +++ b/cidre/src/cg/path.rs @@ -314,21 +314,35 @@ impl PathMut { unsafe { CGPathMoveToPoint(self, m, x, y) } } + #[cfg(target_pointer_width = "64")] #[inline] pub fn move_to>(&mut self, x: F, y: F) { self.move_to_point(None, x.into(), y.into()) } + #[cfg(target_pointer_width = "32")] + #[inline] + pub fn move_to>(&mut self, x: F, y: F) { + self.move_to_point(None, x.into(), y.into()) + } + #[inline] pub fn line_to_point(&mut self, m: Option<&cg::AffineTransform>, x: cg::Float, y: cg::Float) { unsafe { CGPathAddLineToPoint(self, m, x, y) } } + #[cfg(target_pointer_width = "64")] #[inline] pub fn line_to>(&mut self, x: F, y: F) { self.line_to_point(None, x.into(), y.into()) } + #[cfg(target_pointer_width = "32")] + #[inline] + pub fn line_to>(&mut self, x: F, y: F) { + self.line_to_point(None, x.into(), y.into()) + } + #[inline] pub fn quad_curve_to_point( &mut self, @@ -341,11 +355,18 @@ impl PathMut { unsafe { CGPathAddQuadCurveToPoint(self, m, cpx, cpy, x, y) } } + #[cfg(target_pointer_width = "64")] #[inline] pub fn quad_to>(&mut self, cpx: F, cpy: F, x: F, y: F) { self.quad_curve_to_point(None, cpx.into(), cpy.into(), x.into(), y.into()) } + #[cfg(target_pointer_width = "32")] + #[inline] + pub fn quad_to>(&mut self, cpx: F, cpy: F, x: F, y: F) { + self.quad_curve_to_point(None, cpx.into(), cpy.into(), x.into(), y.into()) + } + #[inline] pub fn curve_to_point( &mut self, @@ -360,6 +381,7 @@ impl PathMut { unsafe { CGPathAddCurveToPoint(self, m, cp1x, cp1y, cp2x, cp2y, x, y) } } + #[cfg(target_pointer_width = "64")] #[inline] pub fn curve_to>(&mut self, cp1x: F, cp1y: F, cp2x: F, cp2y: F, x: F, y: F) { self.curve_to_point( @@ -373,6 +395,20 @@ impl PathMut { ) } + #[cfg(target_pointer_width = "32")] + #[inline] + pub fn curve_to>(&mut self, cp1x: F, cp1y: F, cp2x: F, cp2y: F, x: F, y: F) { + self.curve_to_point( + None, + cp1x.into(), + cp1y.into(), + cp2x.into(), + cp2y.into(), + x.into(), + y.into(), + ) + } + #[inline] pub fn close_subpath(&mut self) { unsafe { CGPathCloseSubpath(self) } @@ -438,6 +474,7 @@ impl PathMut { unsafe { CGPathAddArcToPoint(self, m, x1, y1, x2, y2, radius) } } + #[cfg(target_pointer_width = "64")] #[inline] pub fn arc_to>(&mut self, x1: F, y1: F, x2: F, y2: F, radius: F) { self.arc_to_point( @@ -450,6 +487,19 @@ impl PathMut { ) } + #[cfg(target_pointer_width = "32")] + #[inline] + pub fn arc_to>(&mut self, x1: F, y1: F, x2: F, y2: F, radius: F) { + self.arc_to_point( + None, + x1.into(), + y1.into(), + x2.into(), + y2.into(), + radius.into(), + ) + } + #[inline] pub fn add_path(&mut self, m: Option<&cg::AffineTransform>, path2: &Path) { unsafe { CGPathAddPath(self, m, path2) } diff --git a/cidre/src/ui.rs b/cidre/src/ui.rs index cf3115ac..6fe18f87 100644 --- a/cidre/src/ui.rs +++ b/cidre/src/ui.rs @@ -40,6 +40,7 @@ mod scene; pub use scene::AnySceneDelegate; pub use scene::Scene; pub use scene::SceneDelegate; +pub use scene::SceneDelegateImpl; mod scene_session; pub use scene_session::SceneCfg; @@ -57,6 +58,7 @@ pub fn app_main( principal_class_name: Option<&crate::ns::String>, delegate_class_name: Option<&crate::ns::String>, ) -> std::ffi::c_int { + // TODO: pass original args unsafe { UIApplicationMain( 0, diff --git a/cidre/src/ui/application.rs b/cidre/src/ui/application.rs index 7359692e..dea91371 100644 --- a/cidre/src/ui/application.rs +++ b/cidre/src/ui/application.rs @@ -5,6 +5,23 @@ pub trait AppDelegate { #[objc::optional] #[objc::msg_send(applicationDidFinishLaunching:)] fn app_did_finish_launching(&mut self, app: &App); + + #[objc::optional] + #[objc::msg_send(application:configurationForConnectingSceneSession:options:)] + fn app_cfg_for_connecting_scene_session<'ar>( + &mut self, + app: &App, + session: &ui::SceneSession, + options: &ui::SceneConnectionOpts, + ) -> &'ar mut ui::SceneCfg; + + #[objc::optional] + #[objc::msg_send(window)] + fn window(&self) -> Option<&ui::Window>; + + #[objc::optional] + #[objc::msg_send(setWindow:)] + fn set_window(&mut self, val: Option<&ui::Window>); } define_obj_type!( diff --git a/cidre/src/ui/scene_session.rs b/cidre/src/ui/scene_session.rs index 718b9feb..83b538fa 100644 --- a/cidre/src/ui/scene_session.rs +++ b/cidre/src/ui/scene_session.rs @@ -1,4 +1,8 @@ -use crate::{arc, define_cls, define_obj_type, ns, objc, ui}; +use crate::{ + arc, define_cls, define_obj_type, ns, + objc::{self, Obj}, + ui, +}; define_obj_type!( #[doc(alias = "UISceneConfiguration")] @@ -10,7 +14,7 @@ impl arc::A { pub fn init_with_name_role( self, name: Option<&ns::String>, - session_role: ui::SceneSessionRole, + session_role: &ui::SceneSessionRole, ) -> arc::R; } @@ -19,7 +23,7 @@ impl SceneCfg { pub fn with_name_role( name: Option<&ns::String>, - session_role: ui::SceneSessionRole, + session_role: &ui::SceneSessionRole, ) -> arc::R { Self::alloc().init_with_name_role(name, session_role) } @@ -37,7 +41,7 @@ impl SceneCfg { pub fn delegate_class(&self) -> Option<&ns::Class>; #[objc::msg_send(setDelegateClass:)] - pub fn set_delegate_class(&mut self, val: Option<&ns::Class>); + pub fn set_delegate_class(&mut self, val: Option<&ns::Class>); #[objc::msg_send(userInfo)] pub fn user_info(&self) -> Option<&ns::Dictionary>; @@ -50,6 +54,9 @@ define_obj_type!( impl SceneSession { #[objc::msg_send(scene)] pub fn scene(&self) -> Option<&ui::Scene>; + + #[objc::msg_send(role)] + pub fn role(&self) -> &ui::SceneSessionRole; } extern "C" { diff --git a/cidre/src/ui/view.rs b/cidre/src/ui/view.rs index 66a25c74..87049b87 100644 --- a/cidre/src/ui/view.rs +++ b/cidre/src/ui/view.rs @@ -1,6 +1,6 @@ #[cfg(feature = "ca")] use crate::ca; -use crate::{arc, define_obj_type, ns, objc}; +use crate::{arc, define_obj_type, ns, objc, ui}; define_obj_type!(pub View(ns::Id), UI_VIEW); @@ -8,6 +8,18 @@ impl View { #[cfg(feature = "ca")] #[objc::msg_send(layer)] pub fn layer(&self) -> &ca::Layer; + + #[objc::msg_send(backgroundColor)] + pub fn background_color(&self) -> Option<&ui::Color>; + + #[objc::msg_send(setBackgroundColor:)] + pub fn set_background_color(&mut self, val: Option<&ui::Color>); + + #[objc::msg_send(isHidden)] + pub fn is_hidden(&self) -> bool; + + #[objc::msg_send(setHidden:)] + pub fn set_hidden(&self, val: bool); } #[link(name = "ui", kind = "static")] diff --git a/cidre/src/ui/window.rs b/cidre/src/ui/window.rs index 1f0327f1..4e2daa51 100644 --- a/cidre/src/ui/window.rs +++ b/cidre/src/ui/window.rs @@ -5,12 +5,24 @@ define_obj_type!( UI_WINDOW ); +impl arc::A { + #[objc::msg_send(initWithWindowScene:)] + pub fn init_with_window_scene(self, scene: &ui::WindowScene) -> arc::R; +} + impl Window { + pub fn with_window_scene(scene: &ui::WindowScene) -> arc::R { + Self::alloc().init_with_window_scene(scene) + } + #[objc::msg_send(rootViewController)] pub fn root_vc(&self) -> Option<&ui::ViewController>; #[objc::msg_send(setRootViewController:)] pub fn set_root_vc(&mut self, val: Option<&ui::ViewController>); + + #[objc::msg_send(makeKeyAndVisible)] + pub fn make_key_and_visible(&self); } #[link(name = "ui", kind = "static")] diff --git a/cidre/src/ui/window_scene.rs b/cidre/src/ui/window_scene.rs index 6a78339e..1138aa3b 100644 --- a/cidre/src/ui/window_scene.rs +++ b/cidre/src/ui/window_scene.rs @@ -1,14 +1,17 @@ use crate::{define_obj_type, objc, ui}; define_obj_type!( + #[doc(alias = "UIWindowScene")] pub WindowScene(ui::Scene) ); #[objc::protocol(UIWindowSceneDelegate)] -pub trait WindowSceneDelegate { +pub trait WindowSceneDelegate: ui::SceneDelegate { + #[objc::optional] #[objc::msg_send(window)] fn window(&self) -> Option<&ui::Window>; + #[objc::optional] #[objc::msg_send(setWindow:)] fn set_window(&mut self, val: Option<&ui::Window>); }