2 summary:: A view decorator which autowraps the view contents
3 categories:: GUI>Layout
4 related:: Classes/SCContainerView, Classes/CompositeView, Classes/SCTopView
7 FlowLayout is a decorator which automatically arranges views inside a container view in a row, and starts a new row if there is not enough space left for the next view. link::Classes/SCWindow:: and link::Classes/SCCompositeView:: both have code::addFlowLayout:: methods which assign FlowLayout to their view decorators and return the decorator.
13 An instance of link::Classes/Rect::. Normally set to the code::parent.bounds::.
15 An instance of link::Classes/Point::. The horizontal and vertical inner margins, within which the parent's subviews are placed.
17 An instance of link::Classes/Point::. The horizontal and vertical layout gap between the subviews.
24 //change the gaps and margins to see how they work
25 w.view.decorator = FlowLayout( w.view.bounds, 10@10, 20@5 );
26 16.do{ Slider2D( w.view,80@80 ).background_( Color.rand ) };
33 w.addFlowLayout( 10@10, 20@5 ); // a shortcut method, see SCContainerView
34 16.do{ Slider2D( w.view,80@80 ).background_( Color.rand ) };
40 subsection:: Accessing Instance Variables
43 Forces the decorator to start a new line:
47 q = w.addFlowLayout( 10@10, 20@5 );
48 Slider2D( w.view,140@140 ).background_( Color.rand );
50 Slider2D( w.view,140@140 ).background_( Color.rand );
55 method:: indentedRemaining
56 Returns and instance of link::Classes/Rect::. This is a very useful method which tells you how much space is left in a row, before the next row starts. The height of code::indentedRemaining::, is the full height remaining in the FlowLayout.
59 //normally you will only use the width of indentedRemaining
61 w.view.decorator = d = FlowLayout.new( w.view.bounds, 10@10, 20@5 );
62 Slider2D( w.view,150@150 ).background_( Color.rand );
63 Slider2D( w.view,150@150 ).background_( Color.rand );
64 Slider( w.view, d.indentedRemaining.width@150) //fits this view perfectly to the right innerBounds
65 .background_( Color.rand );
71 ( //here the third view is fit to both the right and bottom innerBounds
73 w.view.decorator = d = FlowLayout.new( w.view.bounds, 10@10, 20@5 );
74 Slider2D( w.view,140@140 ).background_( Color.rand );
75 Slider2D( w.view,140@140 ).background_( Color.rand );
77 Slider2D( w.view, d.indentedRemaining ).background_( Color.rand );
83 The outer bounds in which the decorator places the subviews in the parent view.
85 An instance of link::Classes/Rect::.
88 Returns the bounds inset by margin.
91 The horizontal and vertical layout gap between the subviews.
93 An instance of link::Classes/Point::.
96 The horizontal and vertical inner margins, within which the parent's subviews are placed.
98 An instance of link::Classes/Point::.
101 subsection:: Subclassing and Internal Methods
103 The following methods are usually not used directly or are called by a primitive. Programmers can still call or override these as needed.
106 Get the current left indentation or manually set it.
113 w.view.decorator = d = FlowLayout.new( w.view.bounds, 10@10, 20@5 );
114 Slider2D( w.view,150@150 ).background_( Color.rand );
115 d.left_(220); //manually set the new indentation
116 Slider2D( w.view,150@150 ).background_( Color.rand );
122 Get the current top indentation or manually set it.
129 w.view.decorator = d = FlowLayout.new( w.view.bounds, 10@10, 20@5 );
130 Slider2D( w.view,150@150 ).background_( Color.rand );
131 d.top_(50); //manually set the new indentation
132 Slider2D( w.view,150@150 ).background_( Color.rand );
133 Slider2D( w.view,150@150 ).background_( Color.rand );
139 Set the current left and top indentation (see above).
142 Get/set maximium height of the subviews in the current position.
149 w.view.decorator = d = FlowLayout.new( w.view.bounds, 10@10, 20@5 );
150 Slider2D( w.view,100@160 ).background_( Color.rand );
151 Slider2D( w.view,150@150 ).background_( Color.rand );
152 "first row maxHeight: " ++ d.maxHeight.postln;
153 Slider2D( w.view,150@150 ).background_( Color.rand );
154 "second row maxHeight: " ++ d.maxHeight.postln;
160 Get/set maximium right of the subviews in the current position.
167 w.view.decorator = d = FlowLayout.new( w.view.bounds, 10@10, 20@5 );
168 Slider2D( w.view,100@160 ).background_( Color.rand );
169 "first row maxRight: " ++ d.maxRight.postln;
170 Slider2D( w.view,150@150 ).background_( Color.rand );
171 Slider2D( w.view,150@150 ).background_( Color.rand );
172 "second row maxRight: " ++ d.maxRight.postln;
177 method:: currentBounds
178 Gets a link::Classes/Rect:: with code::bounds.width:: and code::height = top + maxHeight::.
183 w.view.decorator = d = FlowLayout.new( w.view.bounds, 10@10, 10@5 );
184 Slider2D( w.view,100@160 ).background_( Color.rand );
185 d.currentBounds.postln;
186 Slider2D( w.view,150@150 ).background_( Color.rand );
187 d.currentBounds.postln;
188 Slider2D( w.view,150@150 ).background_( Color.rand );
189 d.currentBounds.postln;
195 Gets a link::Classes/Rect:: with the space actually used.
200 w.view.decorator = d = FlowLayout.new( w.view.bounds, 10@10, 20@5 );
201 Slider2D( w.view,100@160 ).background_( Color.rand );
203 Slider2D( w.view,150@150 ).background_( Color.rand );
205 Slider2D( w.view,150@150 ).background_( Color.rand );
212 Resets the layout mechanism to 0,0.