Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Add bindings to NSInsetRect and NSRectToCGRect, and make various geometry types copyable. #129

Merged
merged 1 commit into from
May 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/foundation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::mem;
use std::ptr;
use base::{id, class, BOOL, nil};
use core_graphics::base::CGFloat;
use core_graphics::geometry::CGRect;
use libc;
use objc;

Expand All @@ -25,6 +28,7 @@ pub type NSUInteger = libc::c_ulong;
const UTF8_ENCODING: usize = 4;

#[repr(C)]
#[derive(Copy, Clone)]
pub struct NSPoint {
pub x: f64,
pub y: f64,
Expand All @@ -50,6 +54,7 @@ unsafe impl objc::Encode for NSPoint {
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct NSSize {
pub width: f64,
pub height: f64,
Expand All @@ -75,6 +80,7 @@ unsafe impl objc::Encode for NSSize {
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct NSRect {
pub origin: NSPoint,
pub size: NSSize,
Expand All @@ -88,6 +94,20 @@ impl NSRect {
size: size
}
}

#[inline]
pub fn as_CGRect(&self) -> &CGRect {
unsafe {
mem::transmute::<&NSRect, &CGRect>(self)
}
}

#[inline]
pub fn inset(&self, x: CGFloat, y: CGFloat) -> NSRect {
unsafe {
NSInsetRect(*self, x, y)
}
}
}

#[repr(C)]
Expand Down Expand Up @@ -330,3 +350,9 @@ impl NSFastEnumeration for id {
}
}
}

#[link(name = "Foundation", kind = "framework")]
extern {
fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect;
}