From ed0509453514445f7bc0b292e340d9a5910019c6 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 11 Jul 2022 02:17:44 +0200 Subject: [PATCH] Replace core_graphics geometry types with those from objc2_foundation --- src/appkit/toolbar/item.rs | 6 ++-- src/appkit/window/class.rs | 22 +++++------- src/appkit/window/mod.rs | 15 ++++---- src/color/appkit_dynamic_color.rs | 2 +- src/color/mod.rs | 2 +- src/geometry.rs | 16 ++++----- src/image/image.rs | 59 ++++++++++++++----------------- src/layer/mod.rs | 2 +- src/layout/animator.rs | 2 +- src/layout/constraint.rs | 2 +- src/layout/dimension.rs | 2 +- src/layout/traits.rs | 8 ++--- src/listview/appkit.rs | 6 ++-- src/listview/mod.rs | 6 ++-- src/progress/mod.rs | 2 +- src/quicklook/config.rs | 5 ++- src/select/mod.rs | 5 ++- src/text/font.rs | 2 +- src/uikit/scene/mod.rs | 5 ++- src/uikit/window/mod.rs | 5 ++- src/utils/mod.rs | 32 +---------------- src/view/animator.rs | 2 +- src/webview/mod.rs | 5 ++- 23 files changed, 82 insertions(+), 131 deletions(-) diff --git a/src/appkit/toolbar/item.rs b/src/appkit/toolbar/item.rs index b8a36b80..3c6a2e56 100644 --- a/src/appkit/toolbar/item.rs +++ b/src/appkit/toolbar/item.rs @@ -3,12 +3,12 @@ //! //! UNFORTUNATELY, this is a very old and janky API. So... yeah. -use core_graphics::geometry::CGSize; use std::fmt; use objc::rc::{Id, Owned, Shared}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; +use objc2_foundation::NSSize; use crate::button::{BezelStyle, Button}; use crate::foundation::{id, NSString, NO, YES}; @@ -87,7 +87,7 @@ impl ToolbarItem { /// Sets the minimum size for this button. pub fn set_min_size(&mut self, width: f64, height: f64) { unsafe { - let size = CGSize::new(width.into(), height.into()); + let size = NSSize::new(width.into(), height.into()); let _: () = msg_send![&*self.objc, setMinSize: size]; } } @@ -95,7 +95,7 @@ impl ToolbarItem { /// Sets the maximum size for this button. pub fn set_max_size(&mut self, width: f64, height: f64) { unsafe { - let size = CGSize::new(width.into(), height.into()); + let size = NSSize::new(width.into(), height.into()); let _: () = msg_send![&*self.objc, setMaxSize: size]; } } diff --git a/src/appkit/window/class.rs b/src/appkit/window/class.rs index 09c6c02c..3b7d553d 100644 --- a/src/appkit/window/class.rs +++ b/src/appkit/window/class.rs @@ -3,7 +3,7 @@ use std::sync::Once; -use core_graphics::base::CGFloat; +use objc2_foundation::{CGFloat, NSSize}; use objc::declare::ClassDecl; use objc::runtime::{Class, Object, Sel}; @@ -11,7 +11,7 @@ use objc::{class, sel}; use crate::appkit::window::{WindowDelegate, WINDOW_DELEGATE_PTR}; use crate::foundation::{id, load_or_register_class, NSUInteger, BOOL, NO, YES}; -use crate::utils::{load, CGSize}; +use crate::utils::load; /// Called when an `NSWindowDelegate` receives a `windowWillClose:` event. /// Good place to clean up memory and what not. @@ -56,14 +56,11 @@ extern "C" fn did_change_screen_profile(this: &Object, _: Sel } /// Called when an `NSWindowDelegate` receives a `windowDidChangeScreen:` event. -extern "C" fn will_resize(this: &Object, _: Sel, _: id, size: CGSize) -> CGSize { +extern "C" fn will_resize(this: &Object, _: Sel, _: id, size: NSSize) -> NSSize { let window = load::(this, WINDOW_DELEGATE_PTR); - let s = window.will_resize(size.width as f64, size.height as f64); + let s = window.will_resize(size.width() as f64, size.height() as f64); - CGSize { - width: s.0 as CGFloat, - height: s.1 as CGFloat - } + NSSize::new(s.0 as CGFloat, s.1 as CGFloat) } /// Called when an `NSWindowDelegate` receives a `windowDidChangeScreen:` event. @@ -115,15 +112,12 @@ extern "C" fn did_enter_full_screen(this: &Object, _: Sel, _: } /// Called when an `NSWindowDelegate` receives a `windowDidChangeScreenProfile:` event. -extern "C" fn content_size_for_full_screen(this: &Object, _: Sel, _: id, size: CGSize) -> CGSize { +extern "C" fn content_size_for_full_screen(this: &Object, _: Sel, _: id, size: NSSize) -> NSSize { let window = load::(this, WINDOW_DELEGATE_PTR); - let (width, height) = window.content_size_for_full_screen(size.width as f64, size.height as f64); + let (width, height) = window.content_size_for_full_screen(size.width() as f64, size.height() as f64); - CGSize { - width: width as CGFloat, - height: height as CGFloat - } + NSSize::new(width as CGFloat, height as CGFloat) } /// Called when an `NSWindowDelegate` receives a `windowDidChangeScreenProfile:` event. diff --git a/src/appkit/window/mod.rs b/src/appkit/window/mod.rs index 3383c91b..403722b2 100644 --- a/src/appkit/window/mod.rs +++ b/src/appkit/window/mod.rs @@ -10,8 +10,7 @@ use block::ConcreteBlock; -use core_graphics::base::CGFloat; -use core_graphics::geometry::{CGRect, CGSize}; +use objc2_foundation::{CGFloat, NSRect, NSSize}; use objc::rc::{Id, Owned, Shared}; use objc::runtime::Object; @@ -74,7 +73,7 @@ impl Window { // Other types of backing (Retained/NonRetained) are archaic, dating back to the // NeXTSTEP era, and are outright deprecated... so we don't allow setting them. let buffered: NSUInteger = 2; - let dimensions: CGRect = config.initial_dimensions.into(); + let dimensions: NSRect = config.initial_dimensions.into(); let window = msg_send_id![ msg_send_id![class!(NSWindow), alloc], initWithContentRect: dimensions, @@ -135,7 +134,7 @@ where // Other types of backing (Retained/NonRetained) are archaic, dating back to the // NeXTSTEP era, and are outright deprecated... so we don't allow setting them. let buffered: NSUInteger = 2; - let dimensions: CGRect = config.initial_dimensions.into(); + let dimensions: NSRect = config.initial_dimensions.into(); let mut window: Id = msg_send_id![ msg_send_id![class, alloc], initWithContentRect: dimensions, @@ -238,7 +237,7 @@ impl Window { /// Sets the content size for this window. pub fn set_content_size>(&self, width: F, height: F) { unsafe { - let size = CGSize::new(width.into(), height.into()); + let size = NSSize::new(width.into(), height.into()); let _: () = msg_send![&*self.objc, setContentSize: size]; } } @@ -246,7 +245,7 @@ impl Window { /// Sets the minimum size this window can shrink to. pub fn set_minimum_content_size>(&self, width: F, height: F) { unsafe { - let size = CGSize::new(width.into(), height.into()); + let size = NSSize::new(width.into(), height.into()); let _: () = msg_send![&*self.objc, setContentMinSize: size]; } } @@ -254,7 +253,7 @@ impl Window { /// Sets the maximum size this window can shrink to. pub fn set_maximum_content_size>(&self, width: F, height: F) { unsafe { - let size = CGSize::new(width.into(), height.into()); + let size = NSSize::new(width.into(), height.into()); let _: () = msg_send![&*self.objc, setContentMaxSize: size]; } } @@ -262,7 +261,7 @@ impl Window { /// Sets the minimum size this window can shrink to. pub fn set_minimum_size>(&self, width: F, height: F) { unsafe { - let size = CGSize::new(width.into(), height.into()); + let size = NSSize::new(width.into(), height.into()); let _: () = msg_send![&*self.objc, setMinSize: size]; } } diff --git a/src/color/appkit_dynamic_color.rs b/src/color/appkit_dynamic_color.rs index 3e12c3df..da524d31 100644 --- a/src/color/appkit_dynamic_color.rs +++ b/src/color/appkit_dynamic_color.rs @@ -13,7 +13,7 @@ use std::os::raw::c_void; use std::sync::Once; -use core_graphics::base::CGFloat; +use objc2_foundation::CGFloat; use objc::declare::ClassDecl; use objc::runtime::{Class, Object, Sel, BOOL}; diff --git a/src/color/mod.rs b/src/color/mod.rs index 9dd25532..722d135a 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -16,8 +16,8 @@ use std::sync::{Arc, RwLock}; use core_foundation::base::TCFType; -use core_graphics::base::CGFloat; use core_graphics::color::CGColor; +use objc2_foundation::CGFloat; use objc::rc::{Id, Owned}; use objc::runtime::Object; diff --git a/src/geometry.rs b/src/geometry.rs index a0f3bfe5..903956c2 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -1,6 +1,6 @@ //! Wrapper methods for various geometry types (rects, sizes, ec). -use core_graphics::geometry::{CGPoint, CGRect, CGSize}; +use objc2_foundation::{NSPoint, NSRect, NSSize}; /// A struct that represents a box - top, left, width and height. You might use this for, say, /// setting the initial frame of a view. @@ -41,19 +41,19 @@ impl Rect { } } -impl From for CGRect { - fn from(rect: Rect) -> CGRect { - CGRect::new(&CGPoint::new(rect.left, rect.top), &CGSize::new(rect.width, rect.height)) +impl From for NSRect { + fn from(rect: Rect) -> NSRect { + NSRect::new(NSPoint::new(rect.left, rect.top), NSSize::new(rect.width, rect.height)) } } -impl From for Rect { - fn from(rect: CGRect) -> Rect { +impl From for Rect { + fn from(rect: NSRect) -> Rect { Rect { top: rect.origin.y as f64, left: rect.origin.x as f64, - width: rect.size.width as f64, - height: rect.size.height as f64 + width: rect.size.width() as f64, + height: rect.size.height() as f64 } } } diff --git a/src/image/image.rs b/src/image/image.rs index 54a73d85..07532cae 100644 --- a/src/image/image.rs +++ b/src/image/image.rs @@ -6,10 +6,7 @@ use objc::{class, msg_send, msg_send_id, sel}; use block::ConcreteBlock; use core_graphics::context::{CGContext, CGContextRef}; -use core_graphics::{ - base::CGFloat, - geometry::{CGPoint, CGRect, CGSize} -}; +use objc2_foundation::{CGFloat, NSPoint, NSRect, NSSize}; use super::icons::*; use crate::foundation::{id, NSData, NSString, NO, YES}; @@ -56,49 +53,47 @@ fn min_cgfloat(x: CGFloat, y: CGFloat) -> CGFloat { impl ResizeBehavior { /// Given a source and target rectangle, configures and returns a new rectangle configured with /// the resizing properties of this enum. - pub fn apply(&self, source: CGRect, target: CGRect) -> CGRect { + pub fn apply(&self, source: NSRect, target: NSRect) -> NSRect { // if equal, just return source - if source.origin.x == target.origin.x - && source.origin.y == target.origin.y - && source.size.width == target.size.width - && source.size.height == target.size.height - { + if source == target { return source; } - if source.origin.x == 0. && source.origin.y == 0. && source.size.width == 0. && source.size.height == 0. { + if source == NSRect::ZERO { return source; } - let mut scales = CGSize::new(0., 0.); - scales.width = (target.size.width / source.size.width).abs(); - scales.height = (target.size.height / source.size.height).abs(); + let mut scale_width = (target.size.width() / source.size.width()).abs(); + let mut scale_height = (target.size.height() / source.size.height()).abs(); match self { ResizeBehavior::AspectFit => { - scales.width = min_cgfloat(scales.width, scales.height); - scales.height = scales.width; + scale_width = min_cgfloat(scale_width, scale_height); + scale_height = scale_width; }, ResizeBehavior::AspectFill => { - scales.width = max_cgfloat(scales.width, scales.height); - scales.height = scales.width; + scale_width = max_cgfloat(scale_width, scale_height); + scale_height = scale_width; }, ResizeBehavior::Stretch => { /* will do this as default */ }, ResizeBehavior::Center => { - scales.width = 1.; - scales.height = 1.; + scale_width = 1.; + scale_height = 1.; } } - let mut result = source; - result.size.width *= scales.width; - result.size.height *= scales.height; - result.origin.x = target.origin.x + (target.size.width - result.size.width) / 2.; - result.origin.y = target.origin.y + (target.size.height - result.size.height) / 2.; - result + let result_size = NSSize::new(source.size.width() * scale_width, source.size.height() * scale_height); + + NSRect::new( + NSPoint::new( + target.origin.x + (target.size.width() - result_size.width()) / 2., + target.origin.y + (target.size.height() - result_size.height()) / 2. + ), + result_size + ) } } @@ -221,15 +216,15 @@ impl Image { /// Draw a custom image and get it back as a returned `Image`. pub fn draw(config: DrawConfig, handler: F) -> Self where - F: Fn(CGRect, &CGContextRef) -> bool + 'static + F: Fn(NSRect, &CGContextRef) -> bool + 'static { - let source_frame = CGRect::new(&CGPoint::new(0., 0.), &CGSize::new(config.source.0, config.source.1)); + let source_frame = NSRect::new(NSPoint::new(0., 0.), NSSize::new(config.source.0, config.source.1)); - let target_frame = CGRect::new(&CGPoint::new(0., 0.), &CGSize::new(config.target.0, config.target.1)); + let target_frame = NSRect::new(NSPoint::new(0., 0.), NSSize::new(config.target.0, config.target.1)); let resized_frame = config.resize.apply(source_frame, target_frame); - let block = ConcreteBlock::new(move |_destination: CGRect| unsafe { + let block = ConcreteBlock::new(move |_destination: NSRect| unsafe { let current_context: id = msg_send![class!(NSGraphicsContext), currentContext]; let context_ptr: core_graphics::sys::CGContextRef = msg_send![current_context, CGContext]; let context = CGContext::from_existing_context_ptr(context_ptr); @@ -237,8 +232,8 @@ impl Image { context.translate(resized_frame.origin.x, resized_frame.origin.y); context.scale( - resized_frame.size.width / config.source.0, - resized_frame.size.height / config.source.1 + resized_frame.size.width() / config.source.0, + resized_frame.size.height() / config.source.1 ); let result = handler(resized_frame, &context); diff --git a/src/layer/mod.rs b/src/layer/mod.rs index 0afa3f92..2e27832d 100644 --- a/src/layer/mod.rs +++ b/src/layer/mod.rs @@ -10,7 +10,7 @@ //! view.layer.set_corner_radius(4.0); //! ``` -use core_graphics::base::CGFloat; +use objc2_foundation::CGFloat; use objc::{class, msg_send, sel}; diff --git a/src/layout/animator.rs b/src/layout/animator.rs index 8780285e..58fc4c91 100644 --- a/src/layout/animator.rs +++ b/src/layout/animator.rs @@ -1,4 +1,4 @@ -use core_graphics::base::CGFloat; +use objc2_foundation::CGFloat; use objc::rc::{Id, Shared}; use objc::runtime::{Class, Object}; diff --git a/src/layout/constraint.rs b/src/layout/constraint.rs index e60efd33..66f72470 100644 --- a/src/layout/constraint.rs +++ b/src/layout/constraint.rs @@ -2,7 +2,7 @@ //! escape hatch, if you need it (we use it for things like width and height, which aren't handled //! by an axis). -use core_graphics::base::CGFloat; +use objc2_foundation::CGFloat; use objc::rc::{Id, Shared}; use objc::runtime::Object; diff --git a/src/layout/dimension.rs b/src/layout/dimension.rs index 09fdb0aa..ce2a7b1f 100644 --- a/src/layout/dimension.rs +++ b/src/layout/dimension.rs @@ -1,4 +1,4 @@ -use core_graphics::base::CGFloat; +use objc2_foundation::CGFloat; use objc::rc::{Id, Shared}; use objc::runtime::Object; diff --git a/src/layout/traits.rs b/src/layout/traits.rs index 8fc5de92..916b235c 100644 --- a/src/layout/traits.rs +++ b/src/layout/traits.rs @@ -1,12 +1,10 @@ //! Various traits related to controllers opting in to autolayout routines and support for view //! heirarchies. -use core_graphics::base::CGFloat; -use core_graphics::geometry::{CGPoint, CGRect, CGSize}; - use objc::rc::{Id, Shared}; use objc::runtime::Object; use objc::{msg_send, sel}; +use objc2_foundation::{CGFloat, NSRect}; use crate::foundation::{id, nil, to_bool, NSArray, NSString, NO, YES}; use crate::geometry::Rect; @@ -53,8 +51,8 @@ pub trait Layout: ObjcAccess { /// Note that Cacao, by default, opts into autolayout - you need to call /// `set_translates_autoresizing_mask_into_constraints` to enable frame-based layout calls (or /// use an appropriate initializer for a given view type). - fn set_frame>(&self, rect: R) { - let frame: CGRect = rect.into(); + fn set_frame>(&self, rect: R) { + let frame: NSRect = rect.into(); self.with_backing_obj_mut(move |backing_node| unsafe { let _: () = msg_send![backing_node, setFrame: frame]; diff --git a/src/listview/appkit.rs b/src/listview/appkit.rs index 6e703303..6262a210 100644 --- a/src/listview/appkit.rs +++ b/src/listview/appkit.rs @@ -33,11 +33,11 @@ extern "C" fn view_for_column( _table_column: id, item: NSInteger ) -> id { - /*use core_graphics::geometry::CGRect; + /*use objc2_foundation::NSRect; unsafe { //let superview: id = msg_send![table_view, superview]; - let frame: CGRect = msg_send![table_view, frame]; - let _: () = msg_send![table_column, setWidth:frame.size.width]; + let frame: NSRect = msg_send![table_view, frame]; + let _: () = msg_send![table_column, setWidth:frame.size.width()]; }*/ let view = load::(this, LISTVIEW_DELEGATE_PTR); diff --git a/src/listview/mod.rs b/src/listview/mod.rs index b24419fd..2ce7ee57 100644 --- a/src/listview/mod.rs +++ b/src/listview/mod.rs @@ -45,10 +45,10 @@ use std::collections::HashMap; use core_foundation::base::TCFType; -use core_graphics::base::CGFloat; use objc::rc::{Id, Owned, Shared}; use objc::runtime::{Class, Object}; use objc::{class, msg_send, msg_send_id, sel}; +use objc2_foundation::{CGFloat, NSSize}; use crate::color::Color; use crate::foundation::{id, nil, NSArray, NSInteger, NSString, NSUInteger, NO, YES}; @@ -60,7 +60,7 @@ use crate::layout::{LayoutAnchorDimension, LayoutAnchorX, LayoutAnchorY}; use crate::objc_access::ObjcAccess; use crate::scrollview::ScrollView; use crate::utils::properties::{ObjcProperty, PropertyNullable}; -use crate::utils::{os, CGSize, CellFactory}; +use crate::utils::{os, CellFactory}; use crate::view::{ViewAnimatorProxy, ViewDelegate}; #[cfg(feature = "appkit")] @@ -116,7 +116,7 @@ fn common_init(class: &Class) -> id { let _: () = msg_send![tableview, setWantsLayer: YES]; let _: () = msg_send![tableview, setUsesAutomaticRowHeights: YES]; let _: () = msg_send![tableview, setFloatsGroupRows: YES]; - //let _: () = msg_send![tableview, setIntercellSpacing:CGSize::new(0., 0.)]; + //let _: () = msg_send![tableview, setIntercellSpacing: NSSize::new(0., 0.)]; let _: () = msg_send![tableview, setColumnAutoresizingStyle:1]; //msg_send![tableview, setSelectionHighlightStyle:-1]; //let _: () = msg_send![tableview, setAllowsMultipleSelection:NO]; diff --git a/src/progress/mod.rs b/src/progress/mod.rs index 368f1b7f..2d579d7e 100644 --- a/src/progress/mod.rs +++ b/src/progress/mod.rs @@ -11,7 +11,7 @@ //! my_view.add_subview(&indicator); //! ``` -use core_graphics::base::CGFloat; +use objc2_foundation::CGFloat; use objc::rc::{Id, Shared}; use objc::runtime::{Class, Object}; diff --git a/src/quicklook/config.rs b/src/quicklook/config.rs index 773b5af3..87cb176c 100644 --- a/src/quicklook/config.rs +++ b/src/quicklook/config.rs @@ -1,12 +1,11 @@ use std::path::Path; -use core_graphics::base::CGFloat; use objc::rc::{Id, Shared}; use objc::runtime::Object; use objc::{class, msg_send, sel}; +use objc2_foundation::{CGFloat, NSSize}; use crate::foundation::{id, NSString, NSUInteger, YES}; -use crate::utils::CGSize; /// Describes the quality of the thumbnail you expect back from the /// generator service. @@ -107,7 +106,7 @@ impl ThumbnailConfig { } unsafe { - let size = CGSize::new(self.size.0, self.size.1); + let size = NSSize::new(self.size.0, self.size.1); // @TODO: Check nil here, or other bad conversion let from_url: id = msg_send![class!(NSURL), fileURLWithPath:&*file]; diff --git a/src/select/mod.rs b/src/select/mod.rs index 0f7077d6..177e9766 100644 --- a/src/select/mod.rs +++ b/src/select/mod.rs @@ -2,12 +2,11 @@ use std::sync::Once; -use core_graphics::geometry::CGRect; - use objc::declare::ClassDecl; use objc::rc::{Id, Shared}; use objc::runtime::{Class, Object, Sel}; use objc::{class, msg_send, msg_send_id, sel}; +use objc2_foundation::NSRect; use crate::control::Control; use crate::foundation::{id, nil, NSInteger, NSString, NO, YES}; @@ -85,7 +84,7 @@ impl Select { /// Creates a new `Select` instance, configures it appropriately, /// and retains the necessary Objective-C runtime pointer. pub fn new() -> Self { - let zero: CGRect = Rect::zero().into(); + let zero: NSRect = Rect::zero().into(); let view: id = unsafe { let alloc: id = msg_send![register_class(), alloc]; diff --git a/src/text/font.rs b/src/text/font.rs index 8e6f7349..ac307e18 100644 --- a/src/text/font.rs +++ b/src/text/font.rs @@ -2,7 +2,7 @@ use std::ops::Deref; -use core_graphics::base::CGFloat; +use objc2_foundation::CGFloat; use objc::rc::{Id, Shared}; use objc::runtime::{Class, Object}; diff --git a/src/uikit/scene/mod.rs b/src/uikit/scene/mod.rs index f78a9ef5..ef23c71d 100644 --- a/src/uikit/scene/mod.rs +++ b/src/uikit/scene/mod.rs @@ -3,11 +3,10 @@ //! This is required for things like having multiple instances of your app in the app switcher on //! iPad. In general, you probably won't need to tweak this though. -use core_graphics::geometry::CGRect; - use objc::rc::{Id, Owned}; use objc::runtime::Object; use objc::{class, msg_send, sel}; +use objc2_foundation::NSRect; use crate::foundation::id; use crate::geometry::Rect; @@ -43,7 +42,7 @@ impl Scene { pub fn get_bounds(&self) -> Rect { unsafe { let coordinate_space: id = msg_send![&*self.0, coordinateSpace]; - let rect: CGRect = msg_send![coordinate_space, bounds]; + let rect: NSRect = msg_send![coordinate_space, bounds]; rect } .into() diff --git a/src/uikit/window/mod.rs b/src/uikit/window/mod.rs index b9c228bc..7b4b8386 100644 --- a/src/uikit/window/mod.rs +++ b/src/uikit/window/mod.rs @@ -1,8 +1,7 @@ -use core_graphics::geometry::CGRect; - use objc::rc::{Id, Owned}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; +use objc2_foundation::NSRect; use crate::foundation::id; use crate::geometry::Rect; @@ -15,7 +14,7 @@ pub struct Window(pub Id); impl Window { pub fn new(frame: Rect) -> Self { Window(unsafe { - let rect: CGRect = frame.into(); + let rect: NSRect = frame.into(); let alloc = msg_send_id![class!(UIWindow), alloc]; msg_send_id![alloc, initWithFrame: rect].unwrap() }) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 1b2d5284..8e68555d 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -3,12 +3,10 @@ //! they go away one day. use core_foundation::base::CFIndex; -use core_graphics::base::CGFloat; - -use objc::{class, msg_send, sel}; use objc::rc::{Id, Shared}; use objc::runtime::Object; +use objc::{class, msg_send, sel}; use objc::{Encode, Encoding}; use crate::foundation::{id, BOOL, NO, YES}; @@ -68,34 +66,6 @@ where queue.exec_sync(method); } -/// Upstream core graphics does not implement Encode for certain things, so we wrap them here - -/// these are only used in reading certain types passed to us from some delegate methods. -#[repr(C)] -#[derive(Clone, Copy, Debug, Default, PartialEq)] -pub struct CGSize { - /// The width of this size. - pub width: CGFloat, - - /// The height of this size. - pub height: CGFloat -} - -impl CGSize { - /// Create and return a new `CGSize`. - pub fn new(width: CGFloat, height: CGFloat) -> Self { - CGSize { width, height } - } - - /// Create and return a `CGSizeZero` equivalent. - pub fn zero() -> Self { - CGSize { width: 0., height: 0. } - } -} - -unsafe impl Encode for CGSize { - const ENCODING: Encoding<'static> = Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); -} - #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq)] pub struct CFRange { diff --git a/src/view/animator.rs b/src/view/animator.rs index 837a4388..69ef6e18 100644 --- a/src/view/animator.rs +++ b/src/view/animator.rs @@ -1,4 +1,4 @@ -use core_graphics::base::CGFloat; +use objc2_foundation::CGFloat; use objc::rc::{Id, Shared}; use objc::runtime::{Class, Object}; diff --git a/src/webview/mod.rs b/src/webview/mod.rs index abe50f81..02fc9661 100644 --- a/src/webview/mod.rs +++ b/src/webview/mod.rs @@ -13,11 +13,10 @@ //! Apple does not ship `WKWebView` on tvOS, and as a result this control is not provided on that //! platform. -use core_graphics::geometry::CGRect; - use objc::rc::{Id, Owned, Shared}; use objc::runtime::Object; use objc::{class, msg_send, msg_send_id, sel}; +use objc2_foundation::NSRect; use crate::foundation::{id, nil, NSString, NO, YES}; use crate::geometry::Rect; @@ -76,7 +75,7 @@ fn allocate_webview(mut config: WebViewConfig, objc_delegate: Option<&Object>) - } } - let zero: CGRect = Rect::zero().into(); + let zero: NSRect = Rect::zero().into(); let webview_alloc: id = msg_send![register_webview_class(), alloc]; let webview: id = msg_send![webview_alloc, initWithFrame:zero configuration:configuration];