3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.layout.BoxLayout"></div>/**
\r
9 * @class Ext.layout.BoxLayout
\r
10 * @extends Ext.layout.ContainerLayout
\r
11 * <p>Base Class for HBoxLayout and VBoxLayout Classes. Generally it should not need to be used directly.</p>
\r
13 Ext.layout.BoxLayout = Ext.extend(Ext.layout.ContainerLayout, {
\r
14 <div id="cfg-Ext.layout.BoxLayout-defaultMargins"></div>/**
\r
15 * @cfg {Object} defaultMargins
\r
16 * <p>If the individual contained items do not have a <tt>margins</tt>
\r
17 * property specified, the default margins from this property will be
\r
18 * applied to each item.</p>
\r
19 * <br><p>This property may be specified as an object containing margins
\r
20 * to apply in the format:</p><pre><code>
\r
23 right: (right margin),
\r
24 bottom: (bottom margin),
\r
27 * <p>This property may also be specified as a string containing
\r
28 * space-separated, numeric margin values. The order of the sides associated
\r
29 * with each value matches the way CSS processes margin values:</p>
\r
30 * <div class="mdetail-params"><ul>
\r
31 * <li>If there is only one value, it applies to all sides.</li>
\r
32 * <li>If there are two values, the top and bottom borders are set to the
\r
33 * first value and the right and left are set to the second.</li>
\r
34 * <li>If there are three values, the top is set to the first value, the left
\r
35 * and right are set to the second, and the bottom is set to the third.</li>
\r
36 * <li>If there are four values, they apply to the top, right, bottom, and
\r
37 * left, respectively.</li>
\r
39 * <p>Defaults to:</p><pre><code>
\r
40 * {top:0, right:0, bottom:0, left:0}
\r
43 defaultMargins : {left:0,top:0,right:0,bottom:0},
\r
44 <div id="cfg-Ext.layout.BoxLayout-padding"></div>/**
\r
45 * @cfg {String} padding
\r
46 * Defaults to <tt>'0'</tt>. Sets the padding to be applied to all child items managed by this
\r
47 * container's layout.
\r
50 // documented in subclasses
\r
54 monitorResize : true,
\r
56 extraCls : 'x-box-item',
\r
57 ctCls : 'x-box-layout-ct',
\r
58 innerCls : 'x-box-inner',
\r
61 isValidParent : function(c, target){
\r
62 return c.getEl().dom.parentNode == this.innerCt.dom;
\r
66 onLayout : function(ct, target){
\r
67 var cs = ct.items.items, len = cs.length, c, i, last = len-1, cm;
\r
70 target.addClass(this.ctCls);
\r
72 // the innerCt prevents wrapping and shuffling while
\r
73 // the container is resizing
\r
74 this.innerCt = target.createChild({cls:this.innerCls});
\r
75 this.padding = this.parseMargins(this.padding);
\r
77 this.renderAll(ct, this.innerCt);
\r
81 renderItem : function(c){
\r
82 if(typeof c.margins == 'string'){
\r
83 c.margins = this.parseMargins(c.margins);
\r
84 }else if(!c.margins){
\r
85 c.margins = this.defaultMargins;
\r
87 Ext.layout.BoxLayout.superclass.renderItem.apply(this, arguments);
\r
90 getTargetSize : function(target){
91 return (Ext.isIE6 && Ext.isStrict && target.dom == document.body) ? target.getStyleSize() : target.getViewSize();
\r
94 getItems: function(ct){
\r
96 ct.items.each(function(c){
\r
104 <div id="prop-Ext.layout.BoxLayout-activeItem"></div>/**
\r
105 * @property activeItem
\r
110 <div id="cls-Ext.layout.VBoxLayout"></div>/**
\r
111 * @class Ext.layout.VBoxLayout
\r
112 * @extends Ext.layout.BoxLayout
\r
113 * A layout that arranges items vertically
\r
115 Ext.layout.VBoxLayout = Ext.extend(Ext.layout.BoxLayout, {
\r
116 <div id="cfg-Ext.layout.VBoxLayout-align"></div>/**
\r
117 * @cfg {String} align
\r
118 * Controls how the child items of the container are aligned. Acceptable configuration values for this
\r
120 * <div class="mdetail-params"><ul>
\r
121 * <li><b><tt>left</tt></b> : <b>Default</b><div class="sub-desc">child items are aligned horizontally
\r
122 * at the <b>left</b> side of the container</div></li>
\r
123 * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are aligned horizontally at the
\r
124 * <b>mid-width</b> of the container</div></li>
\r
125 * <li><b><tt>stretch</tt></b> : <div class="sub-desc">child items are stretched horizontally to fill
\r
126 * the width of the container</div></li>
\r
127 * <li><b><tt>stretchmax</tt></b> : <div class="sub-desc">child items are stretched horizontally to
\r
128 * the size of the largest item.</div></li>
\r
131 align : 'left', // left, center, stretch, strechmax
\r
132 <div id="cfg-Ext.layout.VBoxLayout-pack"></div>/**
\r
133 * @cfg {String} pack
\r
134 * Controls how the child items of the container are packed together. Acceptable configuration values
\r
135 * for this property are:
\r
136 * <div class="mdetail-params"><ul>
\r
137 * <li><b><tt>start</tt></b> : <b>Default</b><div class="sub-desc">child items are packed together at
\r
138 * <b>top</b> side of container</div></li>
\r
139 * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are packed together at
\r
140 * <b>mid-height</b> of container</div></li>
\r
141 * <li><b><tt>end</tt></b> : <div class="sub-desc">child items are packed together at <b>bottom</b>
\r
142 * side of container</div></li>
\r
145 <div id="cfg-Ext.layout.VBoxLayout-flex"></div>/**
\r
146 * @cfg {Number} flex
\r
147 * This configuation option is to be applied to <b>child <tt>items</tt></b> of the container managed
\r
148 * by this layout. Each child item with a <tt>flex</tt> property will be flexed <b>vertically</b>
\r
149 * according to each item's <b>relative</b> <tt>flex</tt> value compared to the sum of all items with
\r
150 * a <tt>flex</tt> value specified. Any child items that have either a <tt>flex = 0</tt> or
\r
151 * <tt>flex = undefined</tt> will not be 'flexed' (the initial size will not be changed).
\r
155 onLayout : function(ct, target){
\r
156 Ext.layout.VBoxLayout.superclass.onLayout.call(this, ct, target);
\r
159 var cs = this.getItems(ct), cm, ch, margin,
\r
160 size = this.getTargetSize(target),
\r
161 w = size.width - target.getPadding('lr') - this.scrollOffset,
\r
162 h = size.height - target.getPadding('tb'),
\r
163 l = this.padding.left, t = this.padding.top,
\r
164 isStart = this.pack == 'start',
\r
165 isRestore = ['stretch', 'stretchmax'].indexOf(this.align) == -1,
\r
166 stretchWidth = w - (this.padding.left + this.padding.right),
\r
173 Ext.each(cs, function(c){
\r
175 totalFlex += c.flex || 0;
\r
176 ch = c.getHeight();
\r
177 margin = cm.top + cm.bottom;
\r
178 extraHeight += ch + margin;
\r
179 flexHeight += margin + (c.flex ? 0 : ch);
\r
180 maxWidth = Math.max(maxWidth, c.getWidth() + cm.left + cm.right);
\r
182 extraHeight = h - extraHeight - this.padding.top - this.padding.bottom;
\r
184 var innerCtWidth = maxWidth + this.padding.left + this.padding.right;
\r
185 switch(this.align){
\r
187 this.innerCt.setSize(w, h);
\r
191 this.innerCt.setSize(innerCtWidth, h);
\r
194 this.innerCt.setSize(w = Math.max(w, innerCtWidth), h);
\r
198 var availHeight = Math.max(0, h - this.padding.top - this.padding.bottom - flexHeight),
\r
199 leftOver = availHeight,
\r
203 availableWidth = Math.max(0, w - this.padding.left - this.padding.right);
\r
206 Ext.each(cs, function(c){
\r
207 if(isStart && c.flex){
\r
208 ch = Math.floor(availHeight * (c.flex / totalFlex));
\r
214 if(this.pack == 'center'){
\r
215 t += extraHeight ? extraHeight / 2 : 0;
\r
216 }else if(this.pack == 'end'){
\r
219 Ext.each(cs, function(c){
\r
222 c.setPosition(l + cm.left, t);
\r
223 if(isStart && c.flex){
\r
224 ch = Math.max(0, heights[idx++] + (leftOver-- > 0 ? 1 : 0));
\r
226 restore.push(c.getWidth());
\r
228 c.setSize(availableWidth, ch);
\r
230 ch = c.getHeight();
\r
232 t += ch + cm.bottom;
\r
236 Ext.each(cs, function(c){
\r
238 if(this.align == 'stretch'){
\r
239 c.setWidth((stretchWidth - (cm.left + cm.right)).constrain(
\r
240 c.minWidth || 0, c.maxWidth || 1000000));
\r
241 }else if(this.align == 'stretchmax'){
\r
242 c.setWidth((maxWidth - (cm.left + cm.right)).constrain(
\r
243 c.minWidth || 0, c.maxWidth || 1000000));
\r
245 if(this.align == 'center'){
\r
246 var diff = availableWidth - (c.getWidth() + cm.left + cm.right);
\r
248 c.setPosition(l + cm.left + (diff/2), c.y);
\r
251 if(isStart && c.flex){
\r
252 c.setWidth(restore[idx++]);
\r
257 <div id="prop-Ext.layout.VBoxLayout-activeItem"></div>/**
\r
258 * @property activeItem
\r
263 Ext.Container.LAYOUTS.vbox = Ext.layout.VBoxLayout;
\r
265 <div id="cls-Ext.layout.HBoxLayout"></div>/**
\r
266 * @class Ext.layout.HBoxLayout
\r
267 * @extends Ext.layout.BoxLayout
\r
268 * A layout that arranges items horizontally
\r
270 Ext.layout.HBoxLayout = Ext.extend(Ext.layout.BoxLayout, {
\r
271 <div id="cfg-Ext.layout.HBoxLayout-align"></div>/**
\r
272 * @cfg {String} align
\r
273 * Controls how the child items of the container are aligned. Acceptable configuration values for this
\r
275 * <div class="mdetail-params"><ul>
\r
276 * <li><b><tt>top</tt></b> : <b>Default</b><div class="sub-desc">child items are aligned vertically
\r
277 * at the <b>left</b> side of the container</div></li>
\r
278 * <li><b><tt>middle</tt></b> : <div class="sub-desc">child items are aligned vertically at the
\r
279 * <b>mid-height</b> of the container</div></li>
\r
280 * <li><b><tt>stretch</tt></b> : <div class="sub-desc">child items are stretched vertically to fill
\r
281 * the height of the container</div></li>
\r
282 * <li><b><tt>stretchmax</tt></b> : <div class="sub-desc">child items are stretched vertically to
\r
283 * the size of the largest item.</div></li>
\r
285 align : 'top', // top, middle, stretch, strechmax
\r
286 <div id="cfg-Ext.layout.HBoxLayout-pack"></div>/**
\r
287 * @cfg {String} pack
\r
288 * Controls how the child items of the container are packed together. Acceptable configuration values
\r
289 * for this property are:
\r
290 * <div class="mdetail-params"><ul>
\r
291 * <li><b><tt>start</tt></b> : <b>Default</b><div class="sub-desc">child items are packed together at
\r
292 * <b>left</b> side of container</div></li>
\r
293 * <li><b><tt>center</tt></b> : <div class="sub-desc">child items are packed together at
\r
294 * <b>mid-width</b> of container</div></li>
\r
295 * <li><b><tt>end</tt></b> : <div class="sub-desc">child items are packed together at <b>right</b>
\r
296 * side of container</div></li>
\r
299 <div id="cfg-Ext.layout.HBoxLayout-flex"></div>/**
\r
300 * @cfg {Number} flex
\r
301 * This configuation option is to be applied to <b>child <tt>items</tt></b> of the container managed
\r
302 * by this layout. Each child item with a <tt>flex</tt> property will be flexed <b>horizontally</b>
\r
303 * according to each item's <b>relative</b> <tt>flex</tt> value compared to the sum of all items with
\r
304 * a <tt>flex</tt> value specified. Any child items that have either a <tt>flex = 0</tt> or
\r
305 * <tt>flex = undefined</tt> will not be 'flexed' (the initial size will not be changed).
\r
309 onLayout : function(ct, target){
\r
310 Ext.layout.HBoxLayout.superclass.onLayout.call(this, ct, target);
\r
312 var cs = this.getItems(ct), cm, cw, margin,
\r
313 size = this.getTargetSize(target),
\r
314 w = size.width - target.getPadding('lr') - this.scrollOffset,
\r
315 h = size.height - target.getPadding('tb'),
\r
316 l = this.padding.left, t = this.padding.top,
\r
317 isStart = this.pack == 'start',
\r
318 isRestore = ['stretch', 'stretchmax'].indexOf(this.align) == -1,
\r
319 stretchHeight = h - (this.padding.top + this.padding.bottom),
\r
326 Ext.each(cs, function(c){
\r
328 totalFlex += c.flex || 0;
\r
330 margin = cm.left + cm.right;
\r
331 extraWidth += cw + margin;
\r
332 flexWidth += margin + (c.flex ? 0 : cw);
\r
333 maxHeight = Math.max(maxHeight, c.getHeight() + cm.top + cm.bottom);
\r
335 extraWidth = w - extraWidth - this.padding.left - this.padding.right;
\r
337 var innerCtHeight = maxHeight + this.padding.top + this.padding.bottom;
\r
338 switch(this.align){
\r
340 this.innerCt.setSize(w, h);
\r
344 this.innerCt.setSize(w, innerCtHeight);
\r
347 this.innerCt.setSize(w, h = Math.max(h, innerCtHeight));
\r
352 var availWidth = Math.max(0, w - this.padding.left - this.padding.right - flexWidth),
\r
353 leftOver = availWidth,
\r
357 availableHeight = Math.max(0, h - this.padding.top - this.padding.bottom);
\r
360 Ext.each(cs, function(c){
\r
361 if(isStart && c.flex){
\r
362 cw = Math.floor(availWidth * (c.flex / totalFlex));
\r
368 if(this.pack == 'center'){
\r
369 l += extraWidth ? extraWidth / 2 : 0;
\r
370 }else if(this.pack == 'end'){
\r
373 Ext.each(cs, function(c){
\r
376 c.setPosition(l, t + cm.top);
\r
377 if(isStart && c.flex){
\r
378 cw = Math.max(0, widths[idx++] + (leftOver-- > 0 ? 1 : 0));
\r
380 restore.push(c.getHeight());
\r
382 c.setSize(cw, availableHeight);
\r
386 l += cw + cm.right;
\r
390 Ext.each(cs, function(c){
\r
391 var cm = c.margins;
\r
392 if(this.align == 'stretch'){
\r
393 c.setHeight((stretchHeight - (cm.top + cm.bottom)).constrain(
\r
394 c.minHeight || 0, c.maxHeight || 1000000));
\r
395 }else if(this.align == 'stretchmax'){
\r
396 c.setHeight((maxHeight - (cm.top + cm.bottom)).constrain(
\r
397 c.minHeight || 0, c.maxHeight || 1000000));
\r
399 if(this.align == 'middle'){
\r
400 var diff = availableHeight - (c.getHeight() + cm.top + cm.bottom);
\r
402 c.setPosition(c.x, t + cm.top + (diff/2));
\r
405 if(isStart && c.flex){
\r
406 c.setHeight(restore[idx++]);
\r
412 <div id="prop-Ext.layout.HBoxLayout-activeItem"></div>/**
\r
413 * @property activeItem
\r
418 Ext.Container.LAYOUTS.hbox = Ext.layout.HBoxLayout;