-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathHopscotchForBrazil.ns
4861 lines (4713 loc) · 149 KB
/
HopscotchForBrazil.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Newspeak3
'Hopscotch'
class HopscotchForBrazil usingPlatform: platform = (
(* Hopscotch is Newspeak's highly composable application framework.
Vassili Bykov. Hopscotch: Toward User Interface Composition
http://bracha.org/hopscotch-wasdett.pdf
Copyright 2008 Cadence Design Systems, Inc.
Copyright 2009 Ryan Macnak and other contributors.
Copyright 2012 Cadence Design Systems, Inc.
Licensed under the Apache License, Version 2.0 (the ''License''); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 *)
|
public HopscotchImages = platform squeak HopscotchImages.
private Form = platform squeak Form.
private Clipboard = platform squeak Clipboard.
private SharedQueue = platform squeak SharedQueue.
private Processor = platform squeak Processor.
private World = platform squeak World.
private Request = platform namespace Request.
public (* bogus *) Color = platform graphics Color.
private Point = platform graphics Point.
private Cursor = platform graphics Cursor.
private Rectangle = platform graphics Rectangle.
private List = platform collections List.
private Map = platform collections Map.
private brazil = platform brazil.
private Anchor = brazil areas Anchor.
private CellWidthEqualizer = brazil areas CellWidthEqualizer.
private Frame = brazil areas Frame.
public (* bogus *) Menu = brazil menus Menu.
public (* bogus *) MenuItem = brazil menus MenuItem.
public (* bogus *) SeparatorItem = brazil menus SeparatorItem.
private SubmenuItem = brazil menus SubmenuItem.
private AdHocMessageReceiver = brazil manipulation AdHocMessageReceiver.
private DragSource = brazil manipulation DragSource.
private DropTarget = brazil manipulation DropTarget.
private DragDropTracker = brazil manipulation DragDropTracker.
private ArbitraryArityBlockWrapper = brazil manipulation ArbitraryArityBlockWrapper.
private Font = brazil plumbing Font.
public Gradient = brazil plumbing Gradient.
private Viewport = brazil containers Viewport.
private Column = brazil containers Column.
private CompositeVisual = brazil containers CompositeVisual.
private Flow = brazil containers Flow.
private Row = brazil containers Row.
private SpyingWrapper = brazil containers SpyingWrapper.
private Wrapper = brazil containers Wrapper.
private Desktop = brazil containers Desktop.
private VerticalViewport = brazil containers VerticalViewport.
private Window = brazil containers Window.
private Icon = brazil widgets Icon.
private Label = brazil widgets Label.
private Button = brazil widgets Button.
private SensitiveIcon = brazil widgets SensitiveIcon.
private TextDisplay = brazil widgets TextDisplay.
private TextView = brazil widgets TextView.
private LineShape = brazil widgets LineShape.
private PolygonShape = brazil widgets PolygonShape.
private ActiveIcon = brazil widgets ActiveIcon.
private Blank = brazil widgets Blank.
private Hyperlink = brazil widgets Hyperlink.
private RectangleShape = brazil widgets RectangleShape.
private RoundedRectangleShape = brazil widgets RoundedRectangleShape.
private MessageBox = brazil tools MessageBox.
private cachedPlatform = platform.
public core = CoreClasses new.
public fragments = FragmentClasses new. (* after core *)
public composers = ComposerClasses new. (* after core, fragments *)
public canvas = CanvasClasses new. (* after core, composers *)
public outline = OutlineClasses new. (* after core *)
|composers postInit. core postInit) (
class CanvasClasses = (|
Composer = core Composer.
ColorDecorator = composers ColorDecorator.
DragSensitiveHolderComposer = composers DragSensitiveHolderComposer.
HolderComposer = composers HolderComposer.
|) (
public class CanvasComposer = Composer (
(* Displays its elements within a free-form scrollable area. The elements are either CanvasItems or CanvasDependents.
Slots:
items <List[CanvasItem]>
dropTargetCreationBlock <[DropTarget] | nil>
dragTracker <DragDropTracker> *)
| items dropTargetCreationBlock dragTracker |) (
abandonCanvasItemFrom: source <CanvasItemMoveDragSource> = (
self moveItem: source item to: source originalPosition
)
add: presenter <Presenter> at: location <Point> ^<CanvasItem> = (
^addItem:: CanvasItem withContent: presenter at: location.
)
addItem: item <CanvasItem | CanvasDecoration> ^<CanvasItem> = (
items add: item.
item parent: self.
hasVisual ifTrue: [item addVisualsTo: visual].
^item
)
canvasDo: action <[:CanvasComposer]> = (
^action value: self
)
public childrenDo: aBlock = (
items do: aBlock
)
color: aColor = (
addDecorator:: ColorDecorator new color: aColor
)
computeCurrentPositionForItemMove: source <CanvasItemMoveDragSource> ^<Point> = (
(* Compute the origin the item being moved by the source should have now, based on the current position of the mouse. When we implement client drag trajectory control, this is the place to hook it up. *)
^visual mousePoint - source grabPoint
)
createClientSuppliedDropTargetFor: session <DragDropSession> ^<DropTarget> = (
^dropTargetCreationBlock valueWithPossibleArgument: session
)
createDropTargetFor: session <DragDropSession> ^<DropTarget> = (
^if: session source
isMovingMyItem: [createDropTargetForItemMove]
otherwise: [createClientSuppliedDropTargetFor: session]
)
createDropTargetForItemMove = (
^DropTarget new
entryAction: [:source | pickUpCanvasItemFrom: source];
stepAction: [:source | moveCanvasItemFrom: source];
dropAction: [:source | dropCanvasItemFrom: source];
exitAction: [:source | abandonCanvasItemFrom: source]
)
createViewport ^<Viewport> = (
^createVisual
)
createVisual ^<Visual> = (
| viewport |
viewport:: Viewport new color: defaultColor.
items do:
[:each |
each addVisualsTo: viewport].
^viewport
)
defaultColor = (
^Color gray: 0.7
)
dropCanvasItemFrom: source <CanvasItemMoveDragSource> = (
(* Nothing to be done for the move - after the last step event the item is already where it should be. *)
)
dropTargetFor: session <DragDropSession> ^<DropTarget | nil> = (
^session
targetAt: self
ifAbsentPut: [createDropTargetFor: session]
)
elements: itemCollection <Collection[CanvasItem]> = (
items:: itemCollection asOrderedCollection
)
if: source <DragSource> isMovingMyItem: action <[]> otherwise: alternative <[]> = (
source identifyPayloadTo:
(AdHocMessageReceiver new
receive: #draggingCanvasItem:
using:
[:item |
source canvas == self ifTrue: [^action value]]).
^alternative value
)
ifInterestedInDragAt: windowRelativePoint <Point>
forSession: session <DragDropSession>
doWithTarget: targetBlock = (
(dropTargetCreationBlock notNil
and: [visualContainsPoint: windowRelativePoint])
ifTrue:
[(dropTargetFor: session) ifNotNil: targetBlock]
)
includes: containedChild <Fragment> = (
^includesItem: containedChild parent
)
includesItem: item <CanvasItem> = (
^items includes: item
)
move: containedChild <Fragment> to: newLocation <Point> = (
self move: containedChild parent to: newLocation.
)
moveCanvasItemFrom: source <CanvasItemMoveDragSource> = (
self
moveItem: source item
to: (computeCurrentPositionForItemMove: source)
)
moveItem: child <CanvasItem> to: newLocation <Point> = (
child position: newLocation.
)
pickUpCanvasItemFrom: source <CanvasItemMoveDragSource> = (
(* Nothing special to do; the item is physically moved by the step response. *)
)
public receiveRequestFrom: dispatcher <UpwardRequestDispatcher | DownwardRequestDispatcher> ^<Boolean> = (
(* Enable the receiver to receive messages sent using the sendUp/sendDown mechanism. *)
(self respondsTo: dispatcher selector) ifTrue:
[dispatcher message sendTo: self.
^true].
^false
)
remove: containedChild <Fragment> = (
self removeItem: containedChild parent
)
removeItem: child <CanvasItem> = (
items remove: child.
child noticeRemoval.
hasVisual ifTrue: [child removeVisualsFrom: visual].
child noticeAbandonment
)
visualContainsPoint: windowRelativePoint <Point> ^<Boolean> = (
^visual windowRelativeBounds containsPoint: windowRelativePoint
)
) : (
elements: itemCollection <Collection[CanvasItem]> = (
^self new elements: itemCollection
)
)
class CanvasDependent = Composer (
(* This abstract class captures the concept of a dependent canvas item, i.e. an item whose position and existence depends on that of its 'masters'. The item will receive notifications when the position of one of the masters change, as well as one of the master items has been removed. In response to these, concrete subclasses should make arrangements to update their own layout and to remove themselves if they should not exist without the master. *)
) (
addVisualsTo: container = (
subclassResponsibility
)
public childrenDo: aBlock = (
(* This is a leaf. *)
)
mastersDo: action <[:CanvasItem]> = (
(* A subclass must implement this method to invoke the argument with each of its masters as the argument. *)
subclassResponsibility
)
noticeLayoutChangeOfMaster: item <CanvasItem> = (
updateLayout
)
noticeRemovalOfMaster: item <CanvasItem> = (
(* A subclass should implement this to remove itself from the canvas if it cannot exist without the master. *)
subclassResponsibility
)
registerWithMasters = (
mastersDo: [:each | each addDependent: self]
)
remove = (
unregisterWithMasters.
parent removeItem: self
)
removeVisualsFrom: container = (
subclassResponsibility
)
replaceChild: aFragment with: anotherFragment = (
self error: 'this is a leaf'
)
unregisterWithMasters = (
mastersDo: [:each | each removeDependent: self]
)
updateLayout = (
(* Sent by one of the master items when its bounds have changed, as a chance for all dependents to update their layout. *)
subclassResponsibility
)
) : (
)
public class CanvasItem withContent: definition = HolderComposer withContent: definition (
(* This is a special kind of holder used as a wrapper around presenters placed inside a canvas. A part of its content can be marked as grabArea:, which will automatically equip it for drag-and-drop to pick up and drag the item. Canvas items can also manage dependents, which are subclasses of CanvasDependent providing decorations whose position and existence depends on the available items. For example, lines connecting the items can be implemented as dependents. A canvas item notifies all dependents when it is moved or deleted. *)
| internalPosition xAnchorFraction ::=0. yAnchorFraction ::=0. dependents ::= List new. |) (
addDependent: dependent = (
dependents add: dependent
)
addVisualsTo: viewport <Viewport> = (
viewport add: visual in: Anchor.
visual area
origin: position;
xAnchorFraction: xAnchorFraction;
yAnchorFraction: yAnchorFraction
)
canvasItemDo: action <[:CanvasItem]> = (
(* This message is sent by a containing grab area through the sendUp mechanism in order to find the item the area is supposed to move. *)
^action value: self
)
createVisual = (
| theVisual |
theVisual:: super createVisual.
theVisual boundsChangedChannel =>
[:ignored <Rectangle> | notifyDependentsOfLayoutChange].
^theVisual
)
public noticeRemoval = (
(* Sent by the canvas just after the item has been removed from it. *)
dependents copy do: [:each | each noticeRemovalOfMaster: self].
)
notifyDependentsOfLayoutChange = (
dependents do: [:each | each noticeLayoutChangeOfMaster: self]
)
position ^<Point> = (
^internalPosition
)
position: newPosition <Point> = (
internalPosition:: newPosition.
hasVisual ifTrue: [visual area anchorPosition: internalPosition]
)
public receiveRequestFrom: dispatcher <UpwardRequestDispatcher | DownwardRequestDispatcher>
^<Boolean> = (
(* Enable the receiver to receive messages sent using the sendUp/sendDown mechanism. *)
(self respondsTo: dispatcher selector) ifTrue:
[dispatcher message sendTo: self.
^true].
^false
)
remove = (
parent removeItem: self
)
removeDependent: dependent = (
dependents remove: dependent
)
removeVisualsFrom: viewport <Viewport> = (
viewport remove: visual
)
) : (
withContent: presenter <Presenter> at: location <Point> = (
^(self withContent: presenter)
position: location
)
)
public class CanvasItemGrabArea withContent: definition = DragSensitiveHolderComposer withContent: definition (
(* This class implements the move behavior of canvas items. The elements of the items wrapped with a grab area become a ''handle'' that cooperates with the canvas to pick up and move the item when dragged. *)
) (
containingCanvas ^<CanvasComposer | nil> = (
sendUp optional canvasDo: [:canvas | ^canvas].
^nil
)
containingCanvasItem ^<CanvasItem | nil> = (
sendUp optional canvasItemDo: [:item | ^item].
^nil
)
createDragSource = (
| canvas item |
canvas:: containingCanvas.
item:: containingCanvasItem.
^(canvas notNil and: [item notNil])
ifTrue:
[CanvasItemMoveDragSource new
canvas: canvas;
item: item;
grabPoint: (grabPointRelativeTo: item);
originalPosition: item position]
ifFalse:
[DragSource new]
)
grabPointRelativeTo: item <CanvasItem> = (
^tracker dragOrigin
translateFrom: tracker visual
to: item visual
)
) : (
)
class CanvasItemMoveDragSource = DragSource (
(* Represents the dragging of a canvas item initiated by grabbing the item's drag area. The item and the canvas that contains it are stored in the instance slots.
Slots:
canvas <Canvas> The canvas the dragged item belongs to.
item <CanvasItem> The item itself.
grabPoint <Point> The location of the mouse relative to the item at the time the drag started.
originalPosition <Point> The position of the item within the canvas at the time the drag started. *)
| canvas item grabPoint originalPosition |) (
public identifyPayloadTo: identificationReceiver = (
^identificationReceiver
try: [identificationReceiver draggingCanvasItem: item]
or: [super identifyPayloadTo: identificationReceiver]
)
) : (
)
class CanvasLineBetweenItems from: item1 <CanvasItem> to: item2 <CanvasItem> = CanvasDependent (
(* Creates and manages a line between two canvas items, so that the line goes from the center of one item to the center of the other. *)
|
lineColorS ::= Color black.
showArrowS ::= false.
arrowColorS ::= Color black.
arrowBorderColorS ::= nil. (* that is, use lineColor *)
arrowSizeS ::= 10.
arrowSweepS ::= 40 (* degrees *).
fromItem ::= item1.
toItem ::= item2.
line arrowhead
|registerWithMasters) (
addVisualsTo: viewport <Viewport> = (
viewport addAtBack: visual.
showArrow ifTrue:
[arrowhead:: createArrowheadShape.
viewport add: arrowhead inFrontOf: line].
updateLayout.
)
arrowBorderColor = (
^arrowBorderColorS ifNil: [lineColor]
)
arrowBorderColor: newColor <Color> = (
arrowBorderColorS:: newColor.
arrowhead ifNotNil: [:it | it borderColor: newColor]
)
arrowColor = (
^arrowColorS
)
arrowColor: newColor <Color> = (
arrowColorS:: newColor.
arrowhead ifNotNil: [:it | it color: newColor]
)
arrowSize = (
^arrowSizeS
)
arrowSize: newSize <Number> = (
arrowSizeS:: newSize.
arrowhead ifNotNil: [updateLayout]
)
arrowSweep = (
^arrowSweepS
)
arrowSweep: degrees <Number> = (
arrowSweepS:: degrees.
arrowhead ifNotNil: [updateLayout]
)
public childrenDo: action <[:Fragment]> = (
(* This is a leaf. *)
)
computeArrowVerticesPointingAt: toPoint <Point> from: fromPoint <Point> ^<Collection[Point]> = (
| halfSweep size direction point1 point2 |
halfSweep:: arrowSweepS // 2.
size:: arrowSize.
direction:: (toPoint - fromPoint) theta radiansToDegrees.
^{
toPoint.
toPoint - (Point r: size degrees: direction + halfSweep) rounded.
toPoint - (Point r: size degrees: direction - halfSweep) rounded.
}
)
createArrowheadShape = (
^PolygonShape new
borderColor: arrowBorderColor;
borderWidth: 1;
color: arrowColor;
visible: showArrow
)
createVisual = (
line:: LineShape new.
^line
)
edgePointOf: rect <Rectangle> goingTo: point <Point> ^<Point> = (
(* Compute a point at the intersection of the rectangle border and the line going from the rectangle center to the given point. *)
| center |
(rect containsPoint: point) ifTrue: [^point].
center:: rect center.
center y = point y ifFalse:
[ | k x |
k:: (point x - center x) / (point y - center y).
point y < center y
ifTrue:
[x:: (rect top - center y) * k + center x.
(x between: rect left and: rect right) ifTrue:
[^x rounded @ rect top]]
ifFalse:
[x:: (rect bottom - center y) * k + center x.
(x between: rect left and: rect right) ifTrue:
[^x rounded @ rect bottom]]].
center x = point x ifFalse:
[ | k y |
k:: (point y - center y) / (point x - center x).
point x < center x
ifTrue:
[y:: (rect left - center x) * k + center y.
(y between: rect top and: rect bottom) ifTrue:
[^rect left @ y rounded]]
ifFalse:
[y:: (rect right - center x) * k + center y.
(y between: rect top and: rect bottom) ifTrue:
[^rect right @ y rounded]]].
(* If the point is outside the rectangle, one of the four exit conditions above should have held. *)
error: 'eh?'
)
lineColor = (
^lineColorS
)
lineColor: newColor <Color> = (
lineColorS:: newColor.
line ifNotNil: [:it | it color: newColor]
)
mastersDo: action <[:CanvasItem]> = (
action
value: fromItem;
value: toItem
)
noticeRemovalOfMaster: item <CanvasItem> = (
remove
)
removeVisualsFrom: viewport <Viewport> = (
line ifNotNil: [:it | viewport remove: it].
arrowhead ifNotNil: [:it | viewport remove: it].
)
replaceChild: one <Fragment> with: two <Fragment> = (
self error: 'Canvas line decorations are leaves.'
)
showArrow = (
^showArrowS
)
showArrow: show <Boolean> = (
showArrowS:: show.
arrowhead notNil
ifTrue: [arrowhead visible: show]
ifFalse:
[line notNil ifTrue:
[arrowhead:: createArrowheadShape.
line parent add: arrowhead inFrontOf: line]]
)
updateLayout = (
| fromBounds toBounds fromPoint toPoint |
fromBounds:: fromItem visual bounds.
toBounds:: toItem visual bounds.
(fromBounds intersects: toBounds) ifTrue:
[line visible: false.
arrowhead ifNotNil: [:it | it visible: false].
^self].
fromPoint:: edgePointOf: fromBounds goingTo: toBounds center.
toPoint:: edgePointOf: toBounds goingTo: fromBounds center.
line area startPoint: fromPoint endPoint: toPoint.
arrowhead ifNotNil:
[:it |
it area vertices: (computeArrowVerticesPointingAt: toPoint from: fromPoint).
it visible: showArrow].
line visible: true.
)
) : (
)
) : (
)
class ComposerClasses = (|
Presenter = core Presenter.
Subject = core Subject.
Decorator = core Decorator.
Composer = core Composer.
BlankFragment = fragments BlankFragment.
HopscotchSubjectDragSource = fragments HopscotchSubjectDragSource.
HopscotchWastelandDropTarget = fragments HopscotchWastelandDropTarget.
OutlineItemPresenter (* = Outline OutlineItemPresenter *)
|) (
public class AdHocRoundedCornersHolderComposer withContent: definition = HolderComposer withContent: definition (
(* Until we clean up the whole decoration story so that there are a number of visual appearance gadgets that can be composed even more freely, here is a simple holder that shows itself as a rounded corners rectangle. *)
| color |) (
createVisual = (
| composite contentVisual roundedCornersRectangle |
composite:: CompositeVisual new.
contentVisual:: content visual.
roundedCornersRectangle:: RoundedRectangleShape new color: color.
composite
add: roundedCornersRectangle in: Frame;
add: contentVisual in: Frame.
roundedCornersRectangle area fullyCoverParent.
contentVisual area fullyCoverParent.
^composite.
)
) : (
)
class AggregatePresenter onSubject: s = Presenter onSubject: s () (
definition = (
^list: [subject model collect: [:each | each presenter]]
)
) : (
)
class AggregateSubject onModel: m = Subject onModel: m (
(* The model is a collection of other subjects. The presenter will display default presenters of those subjects. *)
) (
public createPresenter = (
^AggregatePresenter subject: self
)
public title = (
| titles |
titles:: (String new: 30) writeStream.
model
do: [:each | titles nextPutAll: each title]
separatedBy: [titles nextPutAll: ', '].
^titles contents
)
) : (
)
public class CellLayoutDecorator = Decorator (
(* A decorator that can be attached to a fragment contained by a row to control its layout parameters. Can be used for columns too, but in typical Hopscotch UIs there is no need to control column cell layout. *)
|
public size
public minimumSize
public expansibility
public compressibility
|) (
public decorate: aVisual = (
size ifNotNil: [:it | aVisual area principalSize: it].
minimumSize ifNotNil: [:it | aVisual area minimumSize: it].
(* general elasticity is obsolete and will go away. Until then, apply
the general before the specific so the specific can override. *)
expansibility ifNotNil: [:it | aVisual area expansibility: it].
compressibility ifNotNil: [:it | aVisual area compressibility: it].
^aVisual
)
public elasticity: newValue = (
(* Support the old API. *)
expansibility: newValue.
compressibility: newValue.
)
) : (
)
public class CenteringFrameComposer content: aFragment = FrameComposer content: aFragment (
) (
contentAreaClass = (
^Anchor
)
setupContentArea: anArea = (
anArea beCentered
)
) : (
)
public class ColorDecorator = Decorator (|
public color
|) (
public decorate: aVisual = (
aVisual color: color.
^aVisual
)
) : (
)
public class ColumnComposer definitions: fragments = SequenceComposer definitions: fragments (
(* Arranges the fragments it holds as a column. *)
) (
visualClass = (
^Column
)
) : (
)
public class DeferredContentComposer = Composer (|
public contentSource
public initialContent ::= BlankFragment new.
public contentFragment
|) (
public childrenDo: aBlock = (
contentFragment ifNotNil: aBlock
)
public collectDeferredContentInto: aCollection = (
aCollection add: self.
super collectDeferredContentInto: aCollection
)
public createDeferredContent = (
(* Evaluate the content source block to produce the actual content fragment and remember it to be installed later. This method is executed by a background process parallel to the main UI. *)
contentFragment:: contentSource value.
contentFragment parent: self.
contentFragment visual. (* Force computation of the subtree off of the UI thread. *)
^contentFragment
)
createVisual = (
^Wrapper with: initialContent visual
)
public installDeferredContent = (
(* Replace the placeholder blank with the real content fragment, typically computed before. *)
visualX content:
(contentFragment ifNil: [createDeferredContent])
visual
)
) : (
)
public class DisclosureComposer = TwoStateComposerWithToggleIcon (
(* Displays a ''heading'' fragment with a triangular ''expand'' button which shows or hides an additional ''details'' fragment. *)
|
public header
public bodyDefinition
bodyPresenter
contentHolder
|) (
bodyPartOrNil = (
^bodyPresenter
)
public childrenDo: aBlock = (
aBlock value: header.
bodyPresenter notNil ifTrue:
[aBlock value: bodyPresenter]
)
createVisual = (
(* IMPORTANT: a change in the structure of visuals created here also requires changing the #updateVisual:of: method. *)
| column |
column:: Column new.
column
addNew: Row setup:
[:row |
row
add: (Wrapper with: toggleIcon) beCentered;
addBlankSize: 3;
add: header visual.
header visual area elasticity: 1];
addNew: Row setup:
[:row |
row addBlankSize: 13.
contentHolder:: Wrapper new.
row add: contentHolder.
contentHolder area elasticity: 1].
isExpanded
ifTrue: [privateExpand].
^column
)
public header: headerPresenter <HopscotchPresenter> bodyDefinition: block <Block> = (
header:: headerPresenter.
header parent: self.
bodyDefinition:: block
)
headerPart = (
^header
)
installContentVisual: aVisual = (
contentHolder content: aVisual.
aVisual areaClass: Frame.
aVisual area fullyCoverParent
)
privateCollapse = (
contentHolder content: Blank new.
(* bodyPresenter:: nil *)
)
privateExpand = (
bodyPresenter ifNil:
[bodyPresenter:: bodyDefinition value.
bodyPresenter parent: self].
installContentVisual: bodyPresenter visual.
)
) : (
)
public class DragSensitiveHolderComposer withContent: definition = HolderComposer withContent: definition (
(* Turns the content into an area that can be dragged from. The content is passivized in the process--any mouse interaction with it is impossible, so presumably it is made of components that are passive in the first place, such as labels, images and their compositions. This class is abstract, to be specialized to interpret the dragging in a particular way. *)
| grabOverlay tracker |) (
createDragSource = (
subclassResponsibility
)
createGrabOverlay = (
grabOverlay:: RectangleShape new
borderWidth: 0;
color: Color transparent.
^grabOverlay
)
createTracker = (
tracker:: DragDropTracker new
attachTo: grabOverlay;
sourceCreationBlock: [createDragSource].
)
createVisual = (
| composite contentVisual |
createGrabOverlay.
createTracker.
composite:: CompositeVisual new.
contentVisual:: content visual.
composite
add: contentVisual in: Frame;
add: grabOverlay in: Frame.
grabOverlay area fullyCoverParent.
contentVisual area fullyCoverParent.
^composite.
)
) : (
)
public class DragSubjectHolderComposer withContent: definition = DragSensitiveHolderComposer withContent: definition (
(* A specialization of the abstract DragSensitiveHolderComposer allowing to drag out a Hopscotch Subject. *)
|
public subject
public image
|) (
public createDragSource = (
^HopscotchSubjectDragSource new
visual: visual;
subject: subject;
draggedImage: image;
wastelandTarget: HopscotchWastelandDropTarget new
)
) : (
)
public class DropTargetHolderComposer withContent: definition = HolderComposer withContent: definition (
| expectedSelector dropAction cachedTarget |) (
createTarget = (
^DropTarget new
dropAction: [:source | dropFrom: source]
)
public dropFrom: dragSource <DropSource> = (
dragSource identifyPayloadTo:
(AdHocMessageReceiver new
receive: expectedSelector
using: dropAction)
)
ifInterestedInDragAt: windowRelativePoint <Point>
forSession: session <DragDropSession>
doWithTarget: targetBlock = (
(visualContainsPoint: windowRelativePoint) ifTrue:
[targetBlock value: target]
)
public receiveRequestFrom: dispatcher ^<Boolean> = (
(* Receive and process a notice coming from one of the children (usually as the result of using #sendUp or #sendDown). *)
(self respondsTo: dispatcher selector) ifTrue:
[dispatcher message sendTo: self.
^true].
^false
)
target = (
^cachedTarget ifNil:
[cachedTarget:: createTarget.
cachedTarget]
)
visualContainsPoint: windowRelativePoint <Point> ^<Boolean> = (
^visual windowRelativeBounds containsPoint: windowRelativePoint
)
) : (
)
class EqualizerDecorator = Decorator (
| sequenceDefinition elementIndex |) (
public decorate: aVisual = (
CellWidthEqualizer
equalize: aVisual children
at: elementIndex.
^aVisual
)
) : (
)
public class FloatingHeaderComposer header: header <Fragment> body: body <Fragment> = Composer (
(* Holds onto two fragments: a header and a body. In a situation when the entire composer area is visible in the top-level presenter's viewport, acts as a column positioning the header fragment above the body fragment. However, if the area is partially scrolled out of view so the top is hidden, the header moves the header component down to keep it visible.
The composer will try to keep some of the body visible as the view is scrolled up, so at some point it will stop repositioning the header and will let it scroll up out of the view. When this will happen is determined by the minimumBodyToHeaderRatio parameter. If the ratio is 2, the default, the header will start scrolling out of view when the visible body height drops to twice the header height.
The top-level presenter that supplies the viewport for the entire page must register an interest in the #changed duct of its viewport's scrollPosition holder and send down the #respondToScrollingInViewport: message when the scroll position changes. That is taken care of in the standard Presenter>>createViewportWithVisual method.
*)
|
header = header.
body = body.
minimumBodyToHeaderRatio ::= 2.
headerVisual
bodyVisual
|header parent: self.
body parent: self) (
public childrenDo: aBlock = (
header childrenDo: aBlock.
body childrenDo: aBlock.
)
createVisual = (
| panel |
panel:: CompositeVisual new.
panel
add: (bodyVisual:: body visual) in: Frame;
add: (headerVisual:: header visual) in: Frame.
header visual notifications =>
[:change |
change = #naturalExtentChanged ifTrue:
[refreshHeaderLayout]].
repositionHeaderAt: 0.
^panel
)
headerHeight = (
^headerVisual naturalExtent y
)
public receiveRequestFrom: dispatcher <RequestDispatcher> ^<Boolean> = (
(* Receive a request sent from somewhere using sendDown or sendUp. We are interested specifically in the scrolling notifications sent by the top-level presenter that manages the main viewport. *)
^dispatcher selector = #respondToScrollingInViewport:
and: [dispatcher message sendTo: self. true]
)
public refresh = (
header refresh.
body refresh.
)
refreshHeaderLayout = (
repositionHeaderAt: header visual area topOffset
)
repositionHeaderAt: topPosition <Integer> = (
| height |
height:: headerHeight.
headerVisual area
leftFraction: 0 offset: 0
topFraction: 0 offset: topPosition
rightFraction: 1 offset: 0
bottomFraction: 0 offset: topPosition + height.
(* We update the body position too because headerHeight is not constant over time. *)
bodyVisual area
leftFraction: 0 offset: 0
topFraction: 0 offset: height
rightFraction: 1 offset: 0
bottomFraction: 1 offset: 0.
)
public respondToScrollingInViewport: viewport <VerticalViewport> = (
(* Received when the top-level viewport has been scrolled to a new position. If possible, move the header to keep it in sight. *)
| visibleBounds newTop |
visibleBounds:: visual localBounds translateFrom: visual to: viewport.
visibleBounds bottom < 0 ifTrue:
(* Scrolled up out of sight, don't bother adjusting. *)
[^self].
visibleBounds top > viewport localBounds bottom ifTrue:
(* Scrolled down out of sight, don't bother adjusting. *)
[^self].
newTop:: (visibleBounds top negated
min: visual localBounds bottom - ((minimumBodyToHeaderRatio + 1) * headerHeight))
max: 0.
repositionHeaderAt: newTop.
)
) : (
)
public class FloatingPanelComposer panel: panel <Fragment> = Composer (
(* Makes the content panel float within a potentially larger container space, keeping the panel positioned within the visible area of the main viewport as the viewport is scrolled. *)
|
panel = panel.
|panel parent: self) (
public childrenDo: aBlock = (
panel childrenDo: aBlock
)
createVisual = (
| column |
column:: Column new.
column
addBlankSize: 0;
add: panel visual.
^column
)
public receiveRequestFrom: dispatcher <RequestDispatcher> ^<Boolean> = (
(* Receive a request sent from somewhere using sendDown or sendUp. We are interested specifically in the scrolling notifications sent by the top-level presenter that manages the main viewport. *)
^dispatcher selector = #respondToScrollingInViewport:
and: [dispatcher message sendTo: self. true]
)
repositionPanelAt: newTop <Integer> = (
visual children first area height: newTop
)
public respondToScrollingInViewport: viewport <VerticalViewport> = (
(* Received when the top-level viewport has been scrolled to a new position. If possible, move the header to keep it in sight. *)
| visibleBounds newTop |
visibleBounds:: visual localBounds translateFrom: visual to: viewport.
visibleBounds bottom < 0 ifTrue:
(* Scrolled up out of sight, don't bother adjusting. *)
[^self].
visibleBounds top > viewport localBounds bottom ifTrue:
(* Scrolled down out of sight, don't bother adjusting. *)
[^self].
newTop:: (visibleBounds top negated
min: visual localBounds bottom - panel visual localBounds height)
max: 0.
repositionPanelAt: newTop.
)
) : (
)
public class FlowComposer definitions: fragments = SequenceComposer definitions: fragments () (
createVisual = (
| visual |
flag: #BOGUS. (* the right implementation is at the end. The current is a temporary one to hold us over until Flow can wholesale-set childedn. *)
visual:: visualClass new.
visual horizontalGap: 8.
children keysAndValuesDo:
[:index :each | | elasticity |
visual add: each visual].
^visual
(* ^super createVisual
horizontalGap: 8 *)
)
visualClass = (
^Flow
)
) : (
)
class FrameComposer content: aFragment = Composer (
| contentX ::= aFragment. |) (
public childrenDo: aBlock = (
content ifNotNil: aBlock
)
public content = (
^contentX
)
public content: aFragment = (
contentX:: aFragment.
aFragment parent: self
)
contentAreaClass = (
subclassResponsibility
)
createVisual ^<Visual> = (
| holder |
holder:: Wrapper with: content visual.
holder content areaClass: contentAreaClass.
setupContentArea: holder content area.
^holder
)
replaceChild: aFragment with: anotherFragment = (
aFragment == content ifFalse: [error: 'not the child'].
hasVisual ifTrue: [content noticeConcealment].
content parent: nil.
content: anotherFragment.
content parent: self.
hasVisual ifTrue:
[content noticeImminentExposure.
visualX content: content visual.
content noticeExposure]
)