cmake build system: visiblity support for clang
[supercollider.git] / SCClassLibrary / Common / GUI / FlowLayout.sc
blobdaa1a329187aafff2cff450d1d1d8eb657461cc2
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         nextLine {
52                 left = bounds.left + margin.x;
53                 top = top + maxHeight + gap.y;
54                 maxHeight = 0;
55         }
56         shift { arg x=0, y=0;
57                 left = left + x;
58                 top = top + y;
59         }
60         innerBounds {
61                 ^bounds.insetBy(margin.x * 2,margin.y * 2)
62         }
63         bounds_ { arg b;
64                 var d;
65                 left = left + ( d = (b.left - bounds.left));
66                 maxRight = maxRight + (d);
67                 top = top + (d = (b.top - bounds.top));
68                 maxHeight = maxHeight + (d);
69                 bounds = b;
70                 // and then you need to re-place all views
71                 // but nextLine will be broken, see FlowView
72         }
73         currentBounds {
74                 var currentBounds;
75                 currentBounds = bounds;
76                 currentBounds.height = top + maxHeight;
77                 ^currentBounds
78         }
79         // rounded out to the nearest rect + margin
80         used {
81                 ^Rect(bounds.left,bounds.top,
82                         maxRight + margin.x - bounds.left,
83                         (top + maxHeight + margin.y ) - bounds.top)
84         }
85         // largest allocatable rect starting in the current row
86         // going down as far as possible
87         indentedRemaining {
88                 var inb;
89                 inb = this.innerBounds;
90                 ^Rect(left,top,
91                         inb.width - (left - inb.left - margin.x),
92                         inb.height - (top - inb.top - margin.y))
93         }