-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial2Resizing.t
More file actions
82 lines (68 loc) · 2.7 KB
/
Tutorial2Resizing.t
File metadata and controls
82 lines (68 loc) · 2.7 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
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
module Tutorial2Resizing where
import COCOA
import CTButton
import CTLabel
import CTTextArea
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
addTextArea -- Tutorial 2
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
-- Tutorial 2: Adding a text area that resizes when the window is resized
ta = new mkCocoaTextArea w
addTextArea = do
ta.setSize ({width=300, height=80})
ta.setPosition ({x=50, y=250})
ta.setDocumentSize ({width=400,height=800})
w1.setWindowResponder (new windowResponder ta) False
w1.addComponent ta
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)
-- Tutorial 2: Resizing the TextArea when the window is resized
windowResponder :: TextArea -> Class RespondsToWindowEvents
windowResponder textarea = class
onWindowResize size = request
newWidth = floor ((fromInt size.width) * 0.8)
newTaSize = {width=newWidth, height=80}
newX = floor ((fromInt size.width) * 0.1)
newTaPosition = {x=newX, y=250}
textarea.setSize newTaSize
textarea.setPosition newTaPosition
onWindowCloseRequest = request
result RespondsToWindowEvents {..}