1 USING: accessors ui.gadgets ui.gadgets.packs ui.gadgets.worlds
2 tools.test namespaces models kernel dlists deques math sets
3 math.parser ui sequences hashtables assocs io arrays prettyprint
4 io.streams.string math.geometry.rect ;
9 ! c contains b contains a
12 "b" get "a" get add-gadget drop
14 "c" get "b" get add-gadget drop
17 "a" get { 100 200 } >>loc drop
18 "b" get { 200 100 } >>loc drop
20 ! give c a loc, it doesn't matter
21 "c" get { -1000 23 } >>loc drop
23 ! what is the location of a inside c?
24 "a" get "c" get relative-loc
28 "g1" get { 10 10 } >>loc
31 "g2" get { 20 20 } >>loc
34 "g3" get { 100 200 } >>dim drop
36 "g2" get "g1" get add-gadget drop
37 "g3" get "g2" get add-gadget drop
39 [ { 30 30 } ] [ "g1" get screen-loc ] unit-test
40 [ { 30 30 } ] [ "g1" get screen-rect rect-loc ] unit-test
41 [ { 30 30 } ] [ "g1" get screen-rect rect-dim ] unit-test
42 [ { 20 20 } ] [ "g2" get screen-loc ] unit-test
43 [ { 20 20 } ] [ "g2" get screen-rect rect-loc ] unit-test
44 [ { 50 180 } ] [ "g2" get screen-rect rect-dim ] unit-test
45 [ { 0 0 } ] [ "g3" get screen-loc ] unit-test
46 [ { 0 0 } ] [ "g3" get screen-rect rect-loc ] unit-test
47 [ { 100 200 } ] [ "g3" get screen-rect rect-dim ] unit-test
50 "g1" get { 300 300 } >>dim drop
52 "g1" get "g2" get add-gadget drop
53 "g2" get { 20 20 } >>loc
56 "g1" get "g3" get add-gadget drop
57 "g3" get { 100 100 } >>loc
60 [ t ] [ { 30 30 } "g2" get inside? ] unit-test
62 [ t ] [ { 30 30 } "g1" get (pick-up) "g2" get eq? ] unit-test
64 [ t ] [ { 30 30 } "g1" get pick-up "g2" get eq? ] unit-test
66 [ t ] [ { 110 110 } "g1" get pick-up "g3" get eq? ] unit-test
69 "g2" get "g4" get add-gadget drop
70 "g4" get { 5 5 } >>loc
73 [ t ] [ { 25 25 } "g1" get pick-up "g4" get eq? ] unit-test
75 TUPLE: mock-gadget < gadget graft-called ungraft-called ;
77 : <mock-gadget> ( -- gadget )
78 mock-gadget new-gadget 0 >>graft-called 0 >>ungraft-called ;
81 [ 1+ ] change-graft-called drop ;
83 M: mock-gadget ungraft*
84 [ 1+ ] change-ungraft-called drop ;
86 ! We can't print to output-stream here because that might be a pane
87 ! stream, and our graft-queue rebinding here would be captured
88 ! by code adding children to the pane...
90 <dlist> \ graft-queue [
91 [ ] [ <mock-gadget> dup queue-graft unqueue-graft ] unit-test
92 [ t ] [ graft-queue deque-empty? ] unit-test
95 <dlist> \ graft-queue [
96 [ t ] [ graft-queue deque-empty? ] unit-test
99 [ ] [ "g" get queue-graft ] unit-test
100 [ f ] [ graft-queue deque-empty? ] unit-test
101 [ { f t } ] [ "g" get graft-state>> ] unit-test
102 [ ] [ "g" get graft-later ] unit-test
103 [ { f t } ] [ "g" get graft-state>> ] unit-test
104 [ ] [ "g" get ungraft-later ] unit-test
105 [ { f f } ] [ "g" get graft-state>> ] unit-test
106 [ t ] [ graft-queue deque-empty? ] unit-test
107 [ ] [ "g" get ungraft-later ] unit-test
108 [ ] [ "g" get graft-later ] unit-test
109 [ ] [ notify-queued ] unit-test
110 [ { t t } ] [ "g" get graft-state>> ] unit-test
111 [ t ] [ graft-queue deque-empty? ] unit-test
112 [ ] [ "g" get graft-later ] unit-test
113 [ 1 ] [ "g" get graft-called>> ] unit-test
114 [ ] [ "g" get ungraft-later ] unit-test
115 [ { t f } ] [ "g" get graft-state>> ] unit-test
116 [ ] [ notify-queued ] unit-test
117 [ 1 ] [ "g" get ungraft-called>> ] unit-test
118 [ { f f } ] [ "g" get graft-state>> ] unit-test
123 <mock-gadget> over <model> >>model
124 "g" get over add-gadget drop
125 swap 1+ number>string set
129 { "g" "1" "2" "3" } [ get graft-state>> ] map prune ;
131 : notify-combo ( ? ? -- )
132 nl "===== Combo: " write 2dup 2array . nl
133 <dlist> \ graft-queue [
134 <mock-gadget> "g" set
135 [ ] [ add-some-children ] unit-test
136 [ V{ { f f } } ] [ status-flags ] unit-test
137 [ ] [ "g" get graft ] unit-test
138 [ V{ { f t } } ] [ status-flags ] unit-test
139 dup [ [ ] [ notify-queued ] unit-test ] when
140 [ ] [ "g" get clear-gadget ] unit-test
141 [ [ t ] [ graft-queue [ front>> ] [ back>> ] bi eq? ] unit-test ] unless
142 [ [ ] [ notify-queued ] unit-test ] when
143 [ ] [ add-some-children ] unit-test
144 [ { f t } ] [ "1" get graft-state>> ] unit-test
145 [ { f t } ] [ "2" get graft-state>> ] unit-test
146 [ { f t } ] [ "3" get graft-state>> ] unit-test
147 [ ] [ graft-queue [ "x" print notify ] slurp-deque ] unit-test
148 [ ] [ notify-queued ] unit-test
149 [ V{ { t t } } ] [ status-flags ] unit-test
152 { { f f } { f t } { t f } { t t } } [ notify-combo ] assoc-each
153 ] with-string-writer print
155 \ <gadget> must-infer
156 \ unparent must-infer
157 \ add-gadget must-infer
158 \ add-gadgets must-infer
159 \ clear-gadget must-infer
161 \ relayout must-infer
162 \ relayout-1 must-infer
163 \ pref-dim must-infer