scide: LookupDialog - redo lookup on classes after partial lookup
[supercollider.git] / SCClassLibrary / Common / GUI / FlowLayout.sc
bloba5a47fc49109d3669c0de27034305021ab4f174f
1 Decorator {
2         place { arg view; this.subclassResponsibility(\place); }
4         remove { arg view; this.subclassResponsibility(\remove); }
6         clear { this.subclassResponsibility(\clear); }
8         bounds { this.subclassResponsibility(\bounds); }
10         bounds_ { arg bounds; this.subclassResponsibility(\bounds_); }
12         gap { this.subclassResponsibility(\gap); }
13         gap_ { arg gap; this.subclassResponsibility(\gap_); }
15         margin { this.subclassResponsibility(\margin); }
16         margin_ { arg margin; this.subclassResponsibility(\margin_); }
19 FlowLayout : Decorator {
20         var <bounds, <>margin, <>gap;
21         var <>left, <>top, <>maxHeight,<>maxRight;
22         var <>owner;
24         *new { arg bounds, margin, gap;
25                 ^super.newCopyArgs(bounds, margin, gap).init
26         }
27         init {
28                 gap = gap ? Point(4,4);
29                 margin = margin ? Point(4,4);
30                 this.reset;
31         }
32         clear { this.reset; }
33         reset {
34                 maxRight = left = bounds.left + margin.x;
35                 top = bounds.top + margin.y;
36                 maxHeight  = 0;
37         }
38         place { arg view;
39                 var height, width,vbounds;
40                 vbounds = view.bounds;
41                 width = vbounds.width;
42                 height = vbounds.height;
43                 if ((left + width) > (bounds.right - margin.x), { this.nextLine; });
45                 view.bounds = Rect(left, top, width, height);
47                 maxRight = max(maxRight,left + width);
48                 left = left + width + gap.x;
49                 maxHeight = max(maxHeight, height);
50         }
51         remove { }
52         nextLine {
53                 left = bounds.left + margin.x;
54                 top = top + maxHeight + gap.y;
55                 maxHeight = 0;
56         }
57         shift { arg x=0, y=0;
58                 left = left + x;
59                 top = top + y;
60         }
61         innerBounds {
62                 ^bounds.insetBy(margin.x * 2,margin.y * 2)
63         }
64         bounds_ { arg b;
65                 var d;
66                 left = left + ( d = (b.left - bounds.left));
67                 maxRight = maxRight + (d);
68                 top = top + (d = (b.top - bounds.top));
69                 maxHeight = maxHeight + (d);
70                 bounds = b;
71                 // and then you need to re-place all views
72                 // but nextLine will be broken, see FlowView
73         }
74         currentBounds {
75                 var currentBounds;
76                 currentBounds = bounds;
77                 currentBounds.height = top + maxHeight;
78                 ^currentBounds
79         }
80         // rounded out to the nearest rect + margin
81         used {
82                 ^Rect(bounds.left,bounds.top,
83                         maxRight + margin.x - bounds.left,
84                         (top + maxHeight + margin.y ) - bounds.top)
85         }
86         // largest allocatable rect starting in the current row
87         // going down as far as possible
88         indentedRemaining {
89                 var inb;
90                 inb = this.innerBounds;
91                 ^Rect(left,top,
92                         inb.width - (left - inb.left - margin.x),
93                         inb.height - (top - inb.top - margin.y))
94         }