Skip to content

Commit

Permalink
iOS Abstract Out the UIView type from winit (#609)
Browse files Browse the repository at this point in the history
* remove opengl code from winit

* iOS: restrict EventsLoop to be created on the main thread
iOS: Window can only be made once, make Drop on Window thread safe
iOS: make DelegateState owned by Window, cleanup
iOS: fixes from merge (class! macro)

* update the changelog

* Fixed nitpicks
  • Loading branch information
mtak- authored and francesca64 committed Jul 25, 2018
1 parent 01cb8e5 commit 72b24a9
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 114 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- On MacOS, the key state for modifiers key events is now properly set.
- On iOS, the view is now set correctly. This makes it possible to render things (instead of being stuck on a black screen), and touch events work again.
- Added NetBSD support.
- **Breaking:** On iOS, `UIView` is now the default root view. `WindowBuilderExt::with_root_view_class` can be used to set the root view objective-c class to `GLKView` (OpenGLES) or `MTKView` (Metal/MoltenVK).
- On iOS, the `UIApplication` is not started until `Window::new` is called.

# Version 0.16.2 (2018-07-07)

Expand Down
18 changes: 17 additions & 1 deletion src/os/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::os::raw::c_void;

use {MonitorId, Window};
use {MonitorId, Window, WindowBuilder};

/// Additional methods on `Window` that are specific to iOS.
pub trait WindowExt {
Expand All @@ -29,6 +29,22 @@ impl WindowExt for Window {
}
}

/// Additional methods on `WindowBuilder` that are specific to iOS.
pub trait WindowBuilderExt {
/// Sets the root view class used by the `Window`, otherwise a barebones `UIView` is provided.
///
/// The class will be initialized by calling `[root_view initWithFrame:CGRect]`
fn with_root_view_class(self, root_view_class: *const c_void) -> WindowBuilder;
}

impl WindowBuilderExt for WindowBuilder {
#[inline]
fn with_root_view_class(mut self, root_view_class: *const c_void) -> WindowBuilder {
self.platform_specific.root_view_class = unsafe { &*(root_view_class as *const _) };
self
}
}

/// Additional methods on `MonitorId` that are specific to iOS.
pub trait MonitorIdExt {
/// Returns a pointer to the `UIScreen` that is used by this monitor.
Expand Down
11 changes: 2 additions & 9 deletions src/platform/ios/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]

use std::ffi::CString;
use std::mem;
use std::os::raw::*;

use objc::runtime::Object;
Expand All @@ -15,19 +14,11 @@ pub type Boolean = u32;

pub const kCFRunLoopRunHandledSource: i32 = 4;

pub const UIViewAutoresizingFlexibleWidth: NSUInteger = 1 << 1;
pub const UIViewAutoresizingFlexibleHeight: NSUInteger = 1 << 4;

#[cfg(target_pointer_width = "32")]
pub type CGFloat = f32;
#[cfg(target_pointer_width = "64")]
pub type CGFloat = f64;

#[cfg(target_pointer_width = "32")]
pub type NSUInteger = u32;
#[cfg(target_pointer_width = "64")]
pub type NSUInteger = u64;

#[repr(C)]
#[derive(Debug, Clone)]
pub struct CGPoint {
Expand Down Expand Up @@ -76,6 +67,8 @@ extern {
pub fn longjmp(env: *mut c_void, val: c_int);
}

pub type JmpBuf = [c_int; 27];

pub trait NSString: Sized {
unsafe fn alloc(_: Self) -> id {
msg_send![class!(NSString), alloc]
Expand Down
Loading

0 comments on commit 72b24a9

Please sign in to comment.