Skip to content

Commit

Permalink
Remove dependency on core-foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Sep 12, 2023
1 parent f4568bf commit 747831e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 36 deletions.
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ rustdoc-args = ["--cfg", "docsrs"]
bitmask-enum = "2.2.1"
objc = { version = "=0.3.0-beta.2", package = "objc2" }
block = { version = "=0.2.0-alpha.6", package = "block2" }
# Temporary: Patched versions that implement `Encode` for common types
# Branch: `objc2`
core-foundation = { git = "https://github.com/madsmtm/core-foundation-rs.git", rev = "7d593d016175755e492a92ef89edca68ac3bd5cd" }
dispatch = "0.2.0"
infer = { version = "0.15", optional = true }
lazy_static = "1.4.0"
Expand All @@ -39,7 +36,7 @@ core-graphics = "0.23"
foreign-types = "0.5"

[features]
appkit = ["core-foundation/mac_os_10_8_features"]
appkit = []
uikit = []
autolayout = []
default = ["appkit", "autolayout"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ The following are a list of [Cargo features][cargo-features] that can be enabled

## General Notes
**Why not extend the existing cocoa-rs crate?**
A good question. At the end of the day, that crate (I believe, and someone can correct me if I'm wrong) is somewhat tied to Servo, and I wanted to experiment with what the best approach for representing the Cocoa UI model in Rust was. This crate doesn't ignore their work entirely, either - `core_foundation` is used internally and re-exported for general use.
A good question. At the end of the day, that crate (I believe, and someone can correct me if I'm wrong) is somewhat tied to Servo, and I wanted to experiment with what the best approach for representing the Cocoa UI model in Rust was.

**Why should I write in Rust, rather than X language?**
In _my_ case, I want to be able to write native applications for my devices (and the platform I like to build products for) without being locked in to writing in Apple-specific languages... and without writing in C/C++ or JavaScript (note: the _toolchain_, not the language - ES6/Typescript are fine). I want to do this because I'm tired of hitting a mountain of work when I want to port my applications to other ecosystems. I think that Rust offers a (growing, but significant) viable model for sharing code across platforms and ecosystems without sacrificing performance.
Expand Down
2 changes: 1 addition & 1 deletion src/appkit/segmentedcontrol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl SegmentedControl {
#[cfg(feature = "appkit")]
self.objc.with_mut(move |obj| unsafe {
let text: id = msg_send![obj, attributedTitle];
let len: isize = msg_send![text, length];
let len: usize = msg_send![text, length];

let mut attr_str = AttributedString::wrap(text);
attr_str.set_text_color(color.as_ref(), 0..len);
Expand Down
2 changes: 1 addition & 1 deletion src/button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl Button {
#[cfg(feature = "appkit")]
self.objc.with_mut(move |obj| unsafe {
let text: id = msg_send![obj, attributedTitle];
let len: isize = msg_send![text, length];
let len: usize = msg_send![text, length];

let mut attr_str = AttributedString::wrap(text);
attr_str.set_text_color(color.as_ref(), 0..len);
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
//!
//! [cargo-features]: https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-features-section
pub use core_foundation;
pub use lazy_static;
pub use objc;
pub use url;
Expand Down
12 changes: 6 additions & 6 deletions src/text/attributed_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::ops::{Deref, DerefMut, Range};
use std::os::raw::c_char;
use std::{fmt, slice, str};

use objc::foundation::NSRange;
use objc::rc::{Id, Owned};
use objc::runtime::Object;
use objc::{class, msg_send, msg_send_id, sel};

use crate::color::Color;
use crate::foundation::{id, to_bool, NSString, BOOL, NO, YES};
use crate::utils::CFRange;
use crate::foundation::{id, NSString};

use super::Font;

Expand Down Expand Up @@ -43,9 +43,9 @@ impl AttributedString {
}

/// Sets the text (foreground) color for the specified range.
pub fn set_text_color<C: AsRef<Color>>(&mut self, color: C, range: Range<isize>) {
pub fn set_text_color<C: AsRef<Color>>(&mut self, color: C, range: Range<usize>) {
let color: id = color.as_ref().into();
let range = CFRange::init(range.start, range.end);
let range = NSRange::from(range);

unsafe {
let _: () = msg_send![
Expand All @@ -58,8 +58,8 @@ impl AttributedString {
}

/// Set the font for the specified range.
pub fn set_font(&mut self, font: Font, range: Range<isize>) {
let range = CFRange::init(range.start, range.end);
pub fn set_font(&mut self, font: Font, range: Range<usize>) {
let range = NSRange::from(range);

unsafe {
let _: () = msg_send![
Expand Down
22 changes: 0 additions & 22 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//! belong to. These are typically internal, and if you rely on them... well, don't be surprised if
//! they go away one day.
use core_foundation::base::CFIndex;

use objc::rc::{Id, Shared};
use objc::runtime::Object;
use objc::{class, msg_send, sel};
Expand Down Expand Up @@ -66,26 +64,6 @@ where
queue.exec_sync(method);
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct CFRange {
pub location: CFIndex,
pub length: CFIndex
}

impl CFRange {
pub fn init(location: CFIndex, length: CFIndex) -> CFRange {
CFRange {
location: location,
length: length
}
}
}

unsafe impl Encode for CFRange {
const ENCODING: Encoding = Encoding::Struct("CFRange", &[CFIndex::ENCODING, CFIndex::ENCODING]);
}

/// A helper method for ensuring that Cocoa is running in multi-threaded mode.
///
/// Why do we need this? According to Apple, if you're going to make use of standard POSIX threads,
Expand Down

0 comments on commit 747831e

Please sign in to comment.