-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamlLib.ml
149 lines (131 loc) · 5.32 KB
/
CamlLib.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
open UIKit
let greetings =
[| "English", "Hello World!"
; "Spanish", "Hola Mundo!"
; "French", "Bonjour, le monde !"
|]
let hello_vc text =
let vc = _new_ UIViewController.self
and label = _new_ UILabel.self in
let view = vc |> UIViewController.view
and frame = UIScreen.self |> UIScreenClass.mainScreen |> UIScreen.bounds
in
view |> UIView.setFrame frame;
view |> UIView.setBackgroundColor (UIColor.self |> UIColorClass.systemBackgroundColor);
label |> UILabel.setText text;
label |> UILabel.setTextColor (UIColor.self |> UIColorClass.systemBlackColor);
label |> UILabel.setTextAlignment _UITextAlignmentCenter;
label |> UIView.setFrame frame;
view |> UIView.addSubview label;
vc
module GreetingsTVC = struct
module LLong = Objc.LLong
let cellID = new_string "Cell"
let numberOfSectionsInTableView =
UITableViewControllerMethods.numberOfSectionsInTableView'
(fun _self _cmd _tv -> LLong.of_int 1)
let titleForHeaderInSection =
UITableViewControllerMethods.tableView'titleForHeaderInSection'
(fun _self _cmd _tv _section -> new_string "Language")
let numberOfRowsInSection =
UITableViewControllerMethods.tableView'numberOfRowsInSection'
(fun _self _cmd _tv _section -> LLong.of_int (Array.length greetings))
let cellForRowAtIndexPath =
UITableViewControllerMethods.tableView'cellForRowAtIndexPath'
(fun _self _cmd tv index_path ->
let cell =
tv |> UITableView.dequeueReusableCellWithIdentifier' cellID
~forIndexPath: index_path
and i = index_path |> NSIndexPath.row in
cell
|> UITableViewCell.textLabel
|> UILabel.setText (new_string (fst greetings.(i)));
cell
|> UITableViewCell.setAccessoryType _UITableViewCellAccessoryDisclosureIndicator;
cell)
let didSelectRowAtIndexPath =
UITableViewDelegate.tableView'didSelectRowAtIndexPath'
(fun self _cmd _tv index_path ->
let i = index_path |> NSIndexPath.row in
let vc = hello_vc (new_string (snd greetings.(i))) in
let nav_vc =
alloc UINavigationController.self
|> UINavigationController.initWithRootViewController vc
in
self
|> UIViewController.parentViewController
|> UISplitViewController.showDetailViewController nav_vc ~sender: self)
let viewDidLoad =
UIViewControllerMethods.viewDidLoad
(fun self cmd ->
msg_super cmd ~self ~args: Objc_type.noargs ~return: Objc_type.void;
self |> UIViewController.setTitle (new_string "Greetings");
self
|> UITableViewController.tableView
|> UITableView.registerClass UITableViewCell.self
~forCellReuseIdentifier: cellID)
let self =
Class.define "GreetingsTVC"
~superclass: UITableViewController.self
~methods:
[ numberOfSectionsInTableView
; titleForHeaderInSection
; numberOfRowsInSection
; cellForRowAtIndexPath
; didSelectRowAtIndexPath
; viewDidLoad
]
end
module SceneDelegate = struct
let willConnectToSession =
UISceneDelegate.scene'willConnectToSession'options'
(fun self _cmd scene _session _opts ->
let win = alloc UIWindow.self |> UIWindow.initWithWindowScene scene
and vc =
alloc UISplitViewController.self
|> UISplitViewController.initWithStyle _UISplitViewControllerStyleDoubleColumn
and master_vc = _new_ GreetingsTVC.self
in
vc
|> UISplitViewController.setViewController master_vc
~forColumn: _UISplitViewControllerColumnPrimary;
self |> UIWindowController.setWindow win;
win |> UIWindow.setRootViewController vc;
vc |> UISplitViewController.showColumn _UISplitViewControllerColumnPrimary;
win |> UIWindow.makeKeyAndVisible)
(* This class is referenced in Info.plist, UISceneConfigurations key.
It is instantiated from UIApplicationMain. *)
let _self =
Class.define "SceneDelegate"
~superclass: UIResponder.self
~protocols: [Objc.get_protocol "UIWindowSceneDelegate"]
~properties: [Property.define "window" Objc_type.id]
~methods: [willConnectToSession]
end
module AppDelegate = struct
(* This class is referenced in main.m. It is instantiated from UIApplicationMain. *)
let _self =
Class.define "AppDelegate"
~superclass: UIResponder.self
~methods:
[ UIApplicationDelegate.application'didFinishLaunchingWithOptions'
(fun self _cmd _app _opts ->
NSNotificationCenter.self
|> NSNotificationCenterClass.defaultCenter
|> NSNotificationCenter.addObserver self
~selector_: (selector "sceneActivated")
~name: _UISceneDidActivateNotification
~object_: nil;
true)
; Method.define
~cmd: (selector "sceneActivated")
~args: Objc_type.[id]
~return: Objc_type.void
(fun _self _cmd _scene -> Printf.eprintf "sceneActivated...\n%!")
; UIApplicationDelegate.application'configurationForConnectingSceneSession'options'
(fun _self _cmd _app conn_session _opts ->
alloc UISceneConfiguration.self
|> UISceneConfiguration.initWithName (new_string "Default Configuration")
~sessionRole: (UISceneSession.role conn_session))
]
end