Skip to content

Commit 5d70df3

Browse files
committed
docs,quickstart: make examples self-contained
1 parent d683e31 commit 5d70df3

File tree

1 file changed

+51
-28
lines changed

1 file changed

+51
-28
lines changed

gui-easy/gui/easy/scribblings/quickstart.scrbl

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,50 @@
1313

1414
@centered[@image[(build-path media "1.1-hello-world.png") #:scale 0.5]]
1515

16-
@racketblock[
16+
@codeblock|{
17+
#lang racket/base
18+
19+
(require racket/gui/easy)
20+
1721
(window
1822
(text "Hello, World!"))
19-
]
23+
}|
2024

2125
The code above describes a view hierarchy rooted in a window that
2226
contains the text ``Hello, World!''. By itself, it doesn't do much,
2327
but you can take it and pass it to @racket[render] to convert it into
2428
a native GUI:
2529

26-
@racketblock[
30+
@codeblock|{
31+
#lang racket/base
32+
33+
(require racket/gui/easy)
34+
2735
(render
2836
(window
2937
(text "Hello, World!")))
30-
]
38+
}|
3139

3240
@section{Counter}
3341

3442
@centered[@image[(build-path media "1.2-counter.png") #:scale 0.5]]
3543

3644
State in @tt{gui-easy} is held by @tech{observables}.
3745

38-
@racketblock[
39-
(define |@count| (|@| 0))
46+
@codeblock|{
47+
#lang racket/base
48+
49+
(require racket/gui/easy
50+
racket/gui/easy/operator)
51+
52+
(define @count (@ 0))
4053
(render
4154
(window
4255
(hpanel
43-
(button "-" (λ () (|@count| . <~ . sub1)))
44-
(text (|@count| . ~> . number->string))
45-
(button "+" (λ () (|@count| . <~ . add1))))))
46-
]
56+
(button "-" (λ () (@count . <~ . sub1)))
57+
(text (@count . ~> . number->string))
58+
(button "+" (λ () (@count . <~ . add1))))))
59+
}|
4760

4861
Here we define an observable called @racket[|@count|] that holds the
4962
current value of a counter. The two @racket[button]s change the value
@@ -58,22 +71,27 @@ laid out horizontally by the @racket[hpanel].
5871
Since views are at their core just descriptions of a GUI, it's easy to
5972
abstract over them and make them reusable.
6073

61-
@racketblock[
62-
(define (counter |@count| action)
74+
@codeblock|{
75+
#lang racket/base
76+
77+
(require racket/gui/easy
78+
racket/gui/easy/operator)
79+
80+
(define (counter @count action)
6381
(hpanel
6482
(button "-" (λ () (action sub1)))
65-
(text (|@count| . ~> . number->string))
83+
(text (@count . ~> . number->string))
6684
(button "+" (λ () (action add1)))))
6785

68-
(define |@counter-1| (|@| 0))
69-
(define |@counter-2| (|@| 0))
86+
(define @counter-1 (@ 0))
87+
(define @counter-2 (@ 0))
7088

7189
(render
7290
(window
7391
(vpanel
74-
(counter |@counter-1| (λ (proc) (|@counter-1| . <~ . proc)))
75-
(counter |@counter-2| (λ (proc) (|@counter-2| . <~ . proc))))))
76-
]
92+
(counter @counter-1 (λ (proc) (@counter-1 . <~ . proc)))
93+
(counter @counter-2 (λ (proc) (@counter-2 . <~ . proc))))))
94+
}|
7795

7896
@section{Dynamic Counters}
7997

@@ -82,8 +100,13 @@ abstract over them and make them reusable.
82100
Taking the previous example further, we can render a dynamic list of
83101
counters.
84102

85-
@racketblock[
86-
(define |@counters| (|@| '((0 . 0))))
103+
@codeblock|{
104+
#lang racket/base
105+
106+
(require racket/gui/easy
107+
racket/gui/easy/operator)
108+
109+
(define @counters (@ '((0 . 0))))
87110

88111
(define (append-counter counts)
89112
(define next-id (add1 (apply max (map car counts))))
@@ -95,11 +118,11 @@ counters.
95118
(cons k (proc (cdr entry)))
96119
entry)))
97120

98-
(define (counter |@count| action)
121+
(define (counter @count action)
99122
(hpanel
100123
#:stretch '(#t #f)
101124
(button "-" (λ () (action sub1)))
102-
(text (|@count| . ~> . number->string))
125+
(text (@count . ~> . number->string))
103126
(button "+" (λ () (action add1)))))
104127

105128
(render
@@ -109,16 +132,16 @@ counters.
109132
(hpanel
110133
#:alignment '(center top)
111134
#:stretch '(#t #f)
112-
(button "Add counter" (λ () (|@counters| . <~ . append-counter))))
135+
(button "Add counter" (λ () (@counters . <~ . append-counter))))
113136
(list-view
114-
|@counters|
137+
@counters
115138
#:key car
116-
(λ (k |@entry|)
139+
(λ (k @entry)
117140
(counter
118-
(|@entry| . ~> . cdr)
141+
(@entry . ~> . cdr)
119142
(λ (proc)
120-
(|@counters| . <~ . (λ (counts) (update-count counts k proc))))))))))
121-
]
143+
(@counters . <~ . (λ (counts) (update-count counts k proc))))))))))
144+
}|
122145

123146
Here the @racket[|@counters|] observable holds a list of pairs where
124147
the first element of a pair is the id of each counter and the second

0 commit comments

Comments
 (0)