3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * @class Ext.layout.ColumnLayout
9 * @extends Ext.layout.ContainerLayout
10 * <p>This is the layout style of choice for creating structural layouts in a multi-column format where the width of
11 * each column can be specified as a percentage or fixed width, but the height is allowed to vary based on the content.
12 * This class is intended to be extended or created via the layout:'column' {@link Ext.Container#layout} config,
13 * and should generally not need to be created directly via the new keyword.</p>
14 * <p>ColumnLayout does not have any direct config options (other than inherited ones), but it does support a
15 * specific config property of <b><tt>columnWidth</tt></b> that can be included in the config of any panel added to it. The
16 * layout will use the columnWidth (if present) or width of each panel during layout to determine how to size each panel.
17 * If width or columnWidth is not specified for a given panel, its width will default to the panel's width (or auto).</p>
18 * <p>The width property is always evaluated as pixels, and must be a number greater than or equal to 1.
19 * The columnWidth property is always evaluated as a percentage, and must be a decimal value greater than 0 and
20 * less than 1 (e.g., .25).</p>
21 * <p>The basic rules for specifying column widths are pretty simple. The logic makes two passes through the
22 * set of contained panels. During the first layout pass, all panels that either have a fixed width or none
23 * specified (auto) are skipped, but their widths are subtracted from the overall container width. During the second
24 * pass, all panels with columnWidths are assigned pixel widths in proportion to their percentages based on
25 * the total <b>remaining</b> container width. In other words, percentage width panels are designed to fill the space
26 * left over by all the fixed-width and/or auto-width panels. Because of this, while you can specify any number of columns
27 * with different percentages, the columnWidths must always add up to 1 (or 100%) when added together, otherwise your
28 * layout may not render as expected. Example usage:</p>
30 // All columns are percentages -- they must add up to 1
31 var p = new Ext.Panel({
32 title: 'Column Layout - Percentage Only',
46 // Mix of width and columnWidth -- all columnWidth values must add up
47 // to 1. The first column will take up exactly 120px, and the last two
48 // columns will fill the remaining container width.
49 var p = new Ext.Panel({
50 title: 'Column Layout - Mixed',
65 Ext.layout.ColumnLayout = Ext.extend(Ext.layout.ContainerLayout, {
77 targetCls: 'x-column-layout-ct',
79 isValidParent : function(c, target){
80 return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
83 getLayoutTargetSize : function() {
84 var target = this.container.getLayoutTarget(), ret;
86 ret = target.getViewSize();
88 // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
89 // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
91 if (Ext.isIE && Ext.isStrict && ret.width == 0){
92 ret = target.getStyleSize();
95 ret.width -= target.getPadding('lr');
96 ret.height -= target.getPadding('tb');
101 renderAll : function(ct, target) {
103 // the innerCt prevents wrapping and shuffling while
104 // the container is resizing
105 this.innerCt = target.createChild({cls:'x-column-inner'});
106 this.innerCt.createChild({cls:'x-clear'});
108 Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
112 onLayout : function(ct, target){
113 var cs = ct.items.items,
120 this.renderAll(ct, target);
122 var size = this.getLayoutTargetSize();
124 if(size.width < 1 && size.height < 1){ // display none?
128 var w = size.width - this.scrollOffset,
132 this.innerCt.setWidth(w);
134 // some columns can be percentages while others are fixed
135 // so we need to make 2 passes
137 for(i = 0; i < len; i++){
139 m = c.getPositionEl().getMargins('lr');
142 pw -= (c.getWidth() + m);
146 pw = pw < 0 ? 0 : pw;
148 for(i = 0; i < len; i++){
152 c.setSize(Math.floor(c.columnWidth * pw) - m);
156 // Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
157 // spaces were accounted for properly. If not, re-layout.
159 if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
160 var ts = this.getLayoutTargetSize();
161 if (ts.width != size.width){
162 this.adjustmentPass = true;
163 this.onLayout(ct, target);
167 delete this.adjustmentPass;
171 * @property activeItem
176 Ext.Container.LAYOUTS['column'] = Ext.layout.ColumnLayout;