3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.layout.BoxLayout"></div>/**
10 * @class Ext.layout.BoxLayout
11 * @extends Ext.layout.ContainerLayout
12 * <p>Base Class for HBoxLayout and VBoxLayout Classes. Generally it should not need to be used directly.</p>
14 Ext.layout.BoxLayout = Ext.extend(Ext.layout.ContainerLayout, {
15 <div id="cfg-Ext.layout.BoxLayout-defaultMargins"></div>/**
16 * @cfg {Object} defaultMargins
17 * <p>If the individual contained items do not have a <tt>margins</tt>
18 * property specified, the default margins from this property will be
19 * applied to each item.</p>
20 * <br><p>This property may be specified as an object containing margins
21 * to apply in the format:</p><pre><code>
24 right: (right margin),
25 bottom: (bottom margin),
28 * <p>This property may also be specified as a string containing
29 * space-separated, numeric margin values. The order of the sides associated
30 * with each value matches the way CSS processes margin values:</p>
31 * <div class="mdetail-params"><ul>
32 * <li>If there is only one value, it applies to all sides.</li>
33 * <li>If there are two values, the top and bottom borders are set to the
34 * first value and the right and left are set to the second.</li>
35 * <li>If there are three values, the top is set to the first value, the left
36 * and right are set to the second, and the bottom is set to the third.</li>
37 * <li>If there are four values, they apply to the top, right, bottom, and
38 * left, respectively.</li>
40 * <p>Defaults to:</p><pre><code>
41 * {top:0, right:0, bottom:0, left:0}
44 defaultMargins : {left:0,top:0,right:0,bottom:0},
45 <div id="cfg-Ext.layout.BoxLayout-padding"></div>/**
46 * @cfg {String} padding
47 * <p>Sets the padding to be applied to all child items managed by this layout.</p>
48 * <p>This property must be specified as a string containing
49 * space-separated, numeric padding values. The order of the sides associated
50 * with each value matches the way CSS processes padding values:</p>
51 * <div class="mdetail-params"><ul>
52 * <li>If there is only one value, it applies to all sides.</li>
53 * <li>If there are two values, the top and bottom borders are set to the
54 * first value and the right and left are set to the second.</li>
55 * <li>If there are three values, the top is set to the first value, the left
56 * and right are set to the second, and the bottom is set to the third.</li>
57 * <li>If there are four values, they apply to the top, right, bottom, and
58 * left, respectively.</li>
60 * <p>Defaults to: <code>"0"</code></p>
63 // documented in subclasses
70 extraCls : 'x-box-item',
71 targetCls : 'x-box-layout-ct',
72 innerCls : 'x-box-inner',
74 constructor : function(config){
75 Ext.layout.BoxLayout.superclass.constructor.call(this, config);
76 if(Ext.isString(this.defaultMargins)){
77 this.defaultMargins = this.parseMargins(this.defaultMargins);
82 isValidParent : function(c, target){
83 return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
87 renderAll : function(ct, target){
89 // the innerCt prevents wrapping and shuffling while
90 // the container is resizing
91 this.innerCt = target.createChild({cls:this.innerCls});
92 this.padding = this.parseMargins(this.padding);
94 Ext.layout.BoxLayout.superclass.renderAll.call(this, ct, this.innerCt);
97 onLayout : function(ct, target){
98 this.renderAll(ct, target);
101 getLayoutTargetSize : function(){
102 var target = this.container.getLayoutTarget(), ret;
104 ret = target.getViewSize();
105 ret.width -= target.getPadding('lr');
106 ret.height -= target.getPadding('tb');
112 renderItem : function(c){
113 if(Ext.isString(c.margins)){
114 c.margins = this.parseMargins(c.margins);
115 }else if(!c.margins){
116 c.margins = this.defaultMargins;
118 Ext.layout.BoxLayout.superclass.renderItem.apply(this, arguments);
122 <div id="cls-Ext.layout.VBoxLayout"></div>/**
123 * @class Ext.layout.VBoxLayout
124 * @extends Ext.layout.BoxLayout
125 * <p>A layout that arranges items vertically down a Container. This layout optionally divides available vertical
126 * space between child items containing a numeric <code>flex</code> configuration.</p>
127 * This layout may also be used to set the widths of child items by configuring it with the {@link #align} option.
129 Ext.layout.VBoxLayout = Ext.extend(Ext.layout.BoxLayout, {
130 <div id="cfg-Ext.layout.VBoxLayout-align"></div>/**
131 * @cfg {String} align
132 * Controls how the child items of the container are aligned. Acceptable configuration values for this
134 * <div class="mdetail-params"><ul>
135 * <li><b><tt>left</tt></b> : <b>Default</b><div class="sub-desc">child items are aligned horizontally
136 * at the <b>left</b> side of the container</div></li>
137 * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are aligned horizontally at the
138 * <b>mid-width</b> of the container</div></li>
139 * <li><b><tt>stretch</tt></b> : <div class="sub-desc">child items are stretched horizontally to fill
140 * the width of the container</div></li>
141 * <li><b><tt>stretchmax</tt></b> : <div class="sub-desc">child items are stretched horizontally to
142 * the size of the largest item.</div></li>
145 align : 'left', // left, center, stretch, strechmax
147 <div id="cfg-Ext.layout.VBoxLayout-pack"></div>/**
149 * Controls how the child items of the container are packed together. Acceptable configuration values
150 * for this property are:
151 * <div class="mdetail-params"><ul>
152 * <li><b><tt>start</tt></b> : <b>Default</b><div class="sub-desc">child items are packed together at
153 * <b>top</b> side of container</div></li>
154 * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are packed together at
155 * <b>mid-height</b> of container</div></li>
156 * <li><b><tt>end</tt></b> : <div class="sub-desc">child items are packed together at <b>bottom</b>
157 * side of container</div></li>
160 <div id="cfg-Ext.layout.VBoxLayout-flex"></div>/**
162 * This configuation option is to be applied to <b>child <tt>items</tt></b> of the container managed
163 * by this layout. Each child item with a <tt>flex</tt> property will be flexed <b>vertically</b>
164 * according to each item's <b>relative</b> <tt>flex</tt> value compared to the sum of all items with
165 * a <tt>flex</tt> value specified. Any child items that have either a <tt>flex = 0</tt> or
166 * <tt>flex = undefined</tt> will not be 'flexed' (the initial size will not be changed).
170 onLayout : function(ct, target){
171 Ext.layout.VBoxLayout.superclass.onLayout.call(this, ct, target);
173 var cs = this.getRenderedItems(ct), csLen = cs.length,
174 c, i, cm, ch, margin, cl, diff, aw, availHeight,
175 size = this.getLayoutTargetSize(),
177 h = size.height - this.scrollOffset,
178 l = this.padding.left,
179 t = this.padding.top,
180 isStart = this.pack == 'start',
189 // Do only width calculations and apply those first, as they can affect height
190 for (i = 0 ; i < csLen; i++) {
193 margin = cm.top + cm.bottom;
194 // Max height for align
195 maxWidth = Math.max(maxWidth, c.getWidth() + cm.left + cm.right);
198 var innerCtWidth = maxWidth + this.padding.left + this.padding.right;
201 this.innerCt.setSize(w, h);
205 this.innerCt.setSize(innerCtWidth, h);
208 this.innerCt.setSize(w = Math.max(w, innerCtWidth), h);
212 var availableWidth = Math.max(0, w - this.padding.left - this.padding.right);
214 for (i = 0 ; i < csLen; i++) {
217 if(this.align == 'stretch'){
218 c.setWidth(((w - (this.padding.left + this.padding.right)) - (cm.left + cm.right)).constrain(
219 c.minWidth || 0, c.maxWidth || 1000000));
220 }else if(this.align == 'stretchmax'){
221 c.setWidth((maxWidth - (cm.left + cm.right)).constrain(
222 c.minWidth || 0, c.maxWidth || 1000000));
223 }else if(isStart && c.flex){
229 // Height calculations
230 for (i = 0 ; i < csLen; i++) {
232 // Total of all the flex values
233 totalFlex += c.flex || 0;
234 // Don't run height calculations on flexed items
236 // Render and layout sub-containers without a flex or height, once
237 if (!c.height && !c.hasLayout && c.doLayout) {
246 // Determine how much height is available to flex
247 extraHeight += ch + cm.top + cm.bottom;
249 // Final avail height calc
250 availHeight = Math.max(0, (h - extraHeight - this.padding.top - this.padding.bottom));
252 var leftOver = availHeight;
253 for (i = 0 ; i < csLen; i++) {
255 if(isStart && c.flex){
256 ch = Math.floor(availHeight * (c.flex / totalFlex));
261 if(this.pack == 'center'){
262 t += availHeight ? availHeight / 2 : 0;
263 }else if(this.pack == 'end'){
268 for (i = 0 ; i < csLen; i++) {
273 cl = l + cm.left // default left pos
275 // Adjust left pos for centering
276 if(this.align == 'center'){
277 if((diff = availableWidth - (c.getWidth() + cm.left + cm.right)) > 0){
283 c.setPosition(cl, t);
284 if(isStart && c.flex){
285 ch = Math.max(0, heights[idx++] + (leftOver-- > 0 ? 1 : 0));
292 // Putting a box layout into an overflowed container is NOT correct and will make a second layout pass necessary.
293 if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
294 var ts = this.getLayoutTargetSize();
295 if (ts.width != size.width || ts.height != size.height){
296 this.adjustmentPass = true;
297 this.onLayout(ct, target);
300 delete this.adjustmentPass;
304 Ext.Container.LAYOUTS.vbox = Ext.layout.VBoxLayout;
306 <div id="cls-Ext.layout.HBoxLayout"></div>/**
307 * @class Ext.layout.HBoxLayout
308 * @extends Ext.layout.BoxLayout
309 * <p>A layout that arranges items horizontally across a Container. This layout optionally divides available horizontal
310 * space between child items containing a numeric <code>flex</code> configuration.</p>
311 * This layout may also be used to set the heights of child items by configuring it with the {@link #align} option.
313 Ext.layout.HBoxLayout = Ext.extend(Ext.layout.BoxLayout, {
314 <div id="cfg-Ext.layout.HBoxLayout-align"></div>/**
315 * @cfg {String} align
316 * Controls how the child items of the container are aligned. Acceptable configuration values for this
318 * <div class="mdetail-params"><ul>
319 * <li><b><tt>top</tt></b> : <b>Default</b><div class="sub-desc">child items are aligned vertically
320 * at the <b>top</b> of the container</div></li>
321 * <li><b><tt>middle</tt></b> : <div class="sub-desc">child items are aligned vertically in the
322 * <b>middle</b> of the container</div></li>
323 * <li><b><tt>stretch</tt></b> : <div class="sub-desc">child items are stretched vertically to fill
324 * the height of the container</div></li>
325 * <li><b><tt>stretchmax</tt></b> : <div class="sub-desc">child items are stretched vertically to
326 * the height of the largest item.</div></li>
328 align : 'top', // top, middle, stretch, strechmax
330 <div id="cfg-Ext.layout.HBoxLayout-pack"></div>/**
332 * Controls how the child items of the container are packed together. Acceptable configuration values
333 * for this property are:
334 * <div class="mdetail-params"><ul>
335 * <li><b><tt>start</tt></b> : <b>Default</b><div class="sub-desc">child items are packed together at
336 * <b>left</b> side of container</div></li>
337 * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are packed together at
338 * <b>mid-width</b> of container</div></li>
339 * <li><b><tt>end</tt></b> : <div class="sub-desc">child items are packed together at <b>right</b>
340 * side of container</div></li>
343 <div id="cfg-Ext.layout.HBoxLayout-flex"></div>/**
345 * This configuation option is to be applied to <b>child <tt>items</tt></b> of the container managed
346 * by this layout. Each child item with a <tt>flex</tt> property will be flexed <b>horizontally</b>
347 * according to each item's <b>relative</b> <tt>flex</tt> value compared to the sum of all items with
348 * a <tt>flex</tt> value specified. Any child items that have either a <tt>flex = 0</tt> or
349 * <tt>flex = undefined</tt> will not be 'flexed' (the initial size will not be changed).
353 onLayout : function(ct, target){
354 Ext.layout.HBoxLayout.superclass.onLayout.call(this, ct, target);
356 var cs = this.getRenderedItems(ct), csLen = cs.length,
357 c, i, cm, cw, ch, diff, availWidth,
358 size = this.getLayoutTargetSize(),
359 w = size.width - this.scrollOffset,
361 l = this.padding.left,
362 t = this.padding.top,
363 isStart = this.pack == 'start',
364 isRestore = ['stretch', 'stretchmax'].indexOf(this.align) == -1,
370 for (i = 0 ; i < csLen; i++) {
372 // Total of all the flex values
373 totalFlex += c.flex || 0;
374 // Don't run width calculations on flexed items
376 // Render and layout sub-containers without a flex or width, once
377 if (!c.width && !c.hasLayout && c.doLayout) {
385 // Determine how much width is available to flex
386 extraWidth += cw + cm.left + cm.right;
387 // Max height for align
388 maxHeight = Math.max(maxHeight, c.getHeight() + cm.top + cm.bottom);
390 // Final avail width calc
391 availWidth = Math.max(0, (w - extraWidth - this.padding.left - this.padding.right));
393 var innerCtHeight = maxHeight + this.padding.top + this.padding.bottom;
396 this.innerCt.setSize(w, h);
400 this.innerCt.setSize(w, innerCtHeight);
403 this.innerCt.setSize(w, h = Math.max(h, innerCtHeight));
407 var leftOver = availWidth,
411 availableHeight = Math.max(0, h - this.padding.top - this.padding.bottom);
413 for (i = 0 ; i < csLen; i++) {
415 if(isStart && c.flex){
416 cw = Math.floor(availWidth * (c.flex / totalFlex));
422 if(this.pack == 'center'){
423 l += availWidth ? availWidth / 2 : 0;
424 }else if(this.pack == 'end'){
427 for (i = 0 ; i < csLen; i++) {
431 c.setPosition(l, t + cm.top);
432 if(isStart && c.flex){
433 cw = Math.max(0, widths[idx++] + (leftOver-- > 0 ? 1 : 0));
435 restore.push(c.getHeight());
437 c.setSize(cw, availableHeight);
445 for (i = 0 ; i < csLen; i++) {
449 if(isStart && c.flex){
452 if(this.align == 'stretch'){
453 c.setHeight(((h - (this.padding.top + this.padding.bottom)) - (cm.top + cm.bottom)).constrain(
454 c.minHeight || 0, c.maxHeight || 1000000));
455 }else if(this.align == 'stretchmax'){
456 c.setHeight((maxHeight - (cm.top + cm.bottom)).constrain(
457 c.minHeight || 0, c.maxHeight || 1000000));
459 if(this.align == 'middle'){
460 diff = availableHeight - (ch + cm.top + cm.bottom);
461 ch = t + cm.top + (diff/2);
463 c.setPosition(c.x, ch);
466 if(isStart && c.flex){
471 // Putting a box layout into an overflowed container is NOT correct and will make a second layout pass necessary.
472 if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
473 var ts = this.getLayoutTargetSize();
474 if (ts.width != size.width || ts.height != size.height){
475 this.adjustmentPass = true;
476 this.onLayout(ct, target);
479 delete this.adjustmentPass;
483 Ext.Container.LAYOUTS.hbox = Ext.layout.HBoxLayout;