Skip to content

Commit

Permalink
continue on ui kit and watchos
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jan 2, 2025
1 parent 1ab08a5 commit 35f32a7
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 15 deletions.
12 changes: 6 additions & 6 deletions cidre/src/cg/affine_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------------|
Expand Down
6 changes: 3 additions & 3 deletions cidre/src/cg/geometry.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
50 changes: 50 additions & 0 deletions cidre/src/cg/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,21 +314,35 @@ impl PathMut {
unsafe { CGPathMoveToPoint(self, m, x, y) }
}

#[cfg(target_pointer_width = "64")]
#[inline]
pub fn move_to<F: Into<f64>>(&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<F: Into<f32>>(&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<F: Into<f64>>(&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<F: Into<f32>>(&mut self, x: F, y: F) {
self.line_to_point(None, x.into(), y.into())
}

#[inline]
pub fn quad_curve_to_point(
&mut self,
Expand All @@ -341,11 +355,18 @@ impl PathMut {
unsafe { CGPathAddQuadCurveToPoint(self, m, cpx, cpy, x, y) }
}

#[cfg(target_pointer_width = "64")]
#[inline]
pub fn quad_to<F: Into<f64>>(&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<F: Into<f32>>(&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,
Expand All @@ -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<F: Into<f64>>(&mut self, cp1x: F, cp1y: F, cp2x: F, cp2y: F, x: F, y: F) {
self.curve_to_point(
Expand All @@ -373,6 +395,20 @@ impl PathMut {
)
}

#[cfg(target_pointer_width = "32")]
#[inline]
pub fn curve_to<F: Into<f32>>(&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) }
Expand Down Expand Up @@ -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<F: Into<f64>>(&mut self, x1: F, y1: F, x2: F, y2: F, radius: F) {
self.arc_to_point(
Expand All @@ -450,6 +487,19 @@ impl PathMut {
)
}

#[cfg(target_pointer_width = "32")]
#[inline]
pub fn arc_to<F: Into<f32>>(&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) }
Expand Down
2 changes: 2 additions & 0 deletions cidre/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions cidre/src/ui/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
15 changes: 11 additions & 4 deletions cidre/src/ui/scene_session.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -10,7 +14,7 @@ impl arc::A<SceneCfg> {
pub fn init_with_name_role(
self,
name: Option<&ns::String>,
session_role: ui::SceneSessionRole,
session_role: &ui::SceneSessionRole,
) -> arc::R<SceneCfg>;
}

Expand All @@ -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> {
Self::alloc().init_with_name_role(name, session_role)
}
Expand All @@ -37,7 +41,7 @@ impl SceneCfg {
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>>);
pub fn set_delegate_class<T: Obj>(&mut self, val: Option<&ns::Class<T>>);

#[objc::msg_send(userInfo)]
pub fn user_info(&self) -> Option<&ns::Dictionary<ns::String, ns::Id>>;
Expand All @@ -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" {
Expand Down
14 changes: 13 additions & 1 deletion cidre/src/ui/view.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#[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);

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")]
Expand Down
12 changes: 12 additions & 0 deletions cidre/src/ui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@ define_obj_type!(
UI_WINDOW
);

impl arc::A<Window> {
#[objc::msg_send(initWithWindowScene:)]
pub fn init_with_window_scene(self, scene: &ui::WindowScene) -> arc::R<Window>;
}

impl Window {
pub fn with_window_scene(scene: &ui::WindowScene) -> arc::R<Self> {
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")]
Expand Down
5 changes: 4 additions & 1 deletion cidre/src/ui/window_scene.rs
Original file line number Diff line number Diff line change
@@ -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>);
}

0 comments on commit 35f32a7

Please sign in to comment.