-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial1CompHierarchy.t
More file actions
57 lines (46 loc) · 1.73 KB
/
Tutorial1CompHierarchy.t
File metadata and controls
57 lines (46 loc) · 1.73 KB
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
module Tutorial1CompHierarchy where
import COCOA
import CTButton
import CTLabel
root w = class
osx = new cocoa w
w1 = new mkCocoaWindow w
start app = action
w1.setPosition ({x=100,y=100})
w1.setSize ({width=400,height=400})
w1.setBackgroundColor web_gray
w1.setTitle "Tutorial"
createComponentHierarchy -- Tutorial 1
app.addWindow w1
-- Tutorial 1: Building a component hierarchy
button = new mkCocoaButton w
label = new mkCocoaLabel w
leftContainer = new mkCocoaContainer w
rightContainer = new mkCocoaContainer w
createComponentHierarchy = do
leftContainer.setSize ({width=200, height=200})
leftContainer.setBackgroundColor ({r=100,g=100,b=200})
leftContainer.setPosition ({x=0,y=0})
rightContainer.setSize ({width=200, height=200})
rightContainer.setBackgroundColor ({r=100,g=200,b=100})
rightContainer.setPosition ({x=200, y=0})
button.setTitle "Click me!"
button.setSize ({width=110,height=21})
button.setPosition ({x=40, y=100})
button.setClickResponder (new buttonHandler label)
leftContainer.addComponent button
label.setText "Click counter"
label.setSize ({width=150, height=36})
label.setPosition ({x=40, y=100})
rightContainer.addComponent label
w1.addComponent leftContainer
w1.addComponent rightContainer
result action
osx.startApplication start
-- Tutorial 1: Updating a label with a button click count
buttonHandler :: Label -> Class Action
buttonHandler label = class
clickCount := 0
result action
clickCount := clickCount + 1
label.setText ("Click #" ++ show clickCount)