Skip to content

Commit

Permalink
[add] uiview
Browse files Browse the repository at this point in the history
  • Loading branch information
rozaliev committed May 25, 2015
1 parent f961136 commit 1a7576d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/api/ios/mod.rs
Expand Up @@ -124,21 +124,21 @@ pub type CGFloat = f32;
pub type CGFloat = f64;

#[repr(C)]
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CGPoint {
pub x: CGFloat,
pub y: CGFloat,
}

#[repr(C)]
#[derive(Debug)]
#[derive(Debug, Clone)]
struct CGRect {
origin: CGPoint,
size: CGSize
}

#[repr(C)]
#[derive(Debug)]
#[derive(Debug, Clone)]
struct CGSize {
width: CGFloat,
height: CGFloat
Expand Down Expand Up @@ -185,6 +185,13 @@ impl Window {
unsafe {
decl.register();
}

let superclass = Class::get("UIView").unwrap();
let mut decl = ClassDecl::new(superclass, "MainView").unwrap();

unsafe {
decl.register();
}
}

fn create_delegate_class() {
Expand All @@ -195,14 +202,28 @@ impl Window {
let main_screen: id = msg_send![Class::get("UIScreen").unwrap(), mainScreen];
let bounds: CGRect = msg_send![main_screen, bounds];
let window: id = msg_send![Class::get("UIWindow").unwrap(), alloc];
let mut window: id = msg_send![window, initWithFrame:bounds];
let mut window: id = msg_send![window, initWithFrame:bounds.clone()];

let view_controller: id = msg_send![Class::get("MainViewController").unwrap(), alloc];
let view_controller: id = msg_send![view_controller, init];


let class = Class::get("MainView").unwrap();
let view:id = msg_send![class, alloc];
let view:id = msg_send![view, initWithFrame:bounds];

let color: id = msg_send![Class::get("UIColor").unwrap(), redColor];

let _: () = msg_send![view, setBackgroundColor:color];

let _: () = msg_send![view_controller, setView:view];


let _: () = msg_send![window, setRootViewController:view_controller];

let _: () = msg_send![window, addSubview:view];
let _: () = msg_send![window, makeKeyAndVisible];


let _: () = msg_send![this, performSelector:sel!(postLaunch:) withObject:nil afterDelay:0.0];
}
Expand Down

0 comments on commit 1a7576d

Please sign in to comment.