-
Notifications
You must be signed in to change notification settings - Fork 11
/
HopscotchDemo.ns
104 lines (103 loc) · 3.52 KB
/
HopscotchDemo.ns
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
Newspeak3
'Root'
class HopscotchDemo packageUsing: manifest = (
|
private findImage = manifest findImage.
private peekingEye = manifest peekingeye1610.
|
) (
class Demo usingPlatform: p = (|
Subject = p hopscotch core Subject.
Presenter = p hopscotch core Presenter.
Color = p graphics Color.
Point = p graphics Point.
Stopwatch = p kernel Stopwatch.
TextEditorFragment = p hopscotch fragments TextEditorFragment.
|) (
class DemoPresenter onSubject: s = Presenter onSubject: s (| counter ::= 0. |) (
public definition = (
| slowHolder echo |
^(column: {
row: {
filler.
(label: 'Hello, Hopscotch Demo!') color: (Color r: 1 g: 0 b: 0).
filler.
}.
row: {
(label: 'Allow this really long label to get cut off by the other one') compressibility: 1.
filler compressibility: 0.
label: 'Dont cut me off'.
}.
label: ' This label should have a leading space and should be cut off rather than wrapping onto another line.'.
textDisplay: ' This text display should have a leading space. There should be lots of space between these words. This text should wrap. Until after here.
This is after a newline.'.
row: {label: 'Nested'. label: ' in '. label: 'Outer'. filler. sampleMenu. filler}.
echo:: textDisplay: ''.
TextEditorFragment new changeResponse: [:editor | echo text: editor textBeingAccepted].
row: {
link: 'Alan Kay' action: [echo text: '"In computer terms, Smalltalk is a recursion on the notion of computer itself. Instead of dividing "computer stuff" into things each less strong than the whole--like data structures, procedures, and functions which are the usual paraphernalia of programming languages--each Smalltalk object is a recursion on the entire possibilities of the computer. Thus its semantics are a bit like having thousands and thousands of computers all hooked together by a very fast network." --Alan Kay, The Early History of Smalltalk'].
mediumBlank.
link: 'Puck' action: [echo text: 'Yet but three? Come one more
Two of both kinds make up four'].
mediumBlank.
(link: 'Clear' action: [echo text: '']) color: (Color r: 1 g: 0 b: 0).
blank: 25.
link: 'Alert' action: [alert: 'Bar'].
}.
slowHolder:: holder: [column: {slow. slow}].
button: 'Do it again!' action: [slowHolder refresh].
image: peekingEye.
}) color: (Color r: 0.855 g: 0.855 b: 0.9)
)
fib: n = (
^n < 2 ifTrue: [1] ifFalse: [(fib: n - 1) + (fib: n - 2)]
)
public isKindOfDemoPresenter ^ <Boolean> = (
^true
)
isMyKind: f <Fragment> ^ <Boolean> = (
^f isKindOfDemoPresenter
)
sampleMenu ^ <DropDownMenuFragment> = (
^dropDownMenu: [{{counter printString. [counter:: counter + 1. alert: counter]}. {'one'. [alert: '1']}. {'two'. [alert: '2']}. #separator. {'three'. [alert: '3']}. {subject elapsedMilliseconds printString. [alert: 'Dynamic!']} }]
)
slow = (
^initially:
(label: 'Doing something slow...')
deferred: [
slowFib.
row: {
label: 'Done!'.
mediumBlank.
image: findImage.}].
)
slowFib = (
| stopwatch ::= Stopwatch new start. |
[ fib: 20.
stopwatch elapsedMilliseconds < 1000] whileTrue.
)
) : (
)
public class DemoSubject new = Subject onModel: nil (
| stopwatch = Stopwatch new. |
stopwatch start) (
public createPresenter = (
^DemoPresenter onSubject: self
)
isMyKind: other ^ <Boolean> = (
^other isKindOfDemoPresenter
)
public elapsedMilliseconds = (
^stopwatch elapsedMilliseconds
)
) : (
)
) : (
)
public main: platform args: args = (
| demo |
demo:: Demo usingPlatform: platform.
platform hopscotch core HopscotchWindow openSubject: demo DemoSubject new.
)
) : (
)