Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / docs / source / ColumnLayout.html
1 <html>\r
2 <head>\r
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
7 </head>\r
8 <body  onload="prettyPrint();">\r
9     <pre class="prettyprint lang-js"><div id="cls-Ext.layout.ColumnLayout"></div>/**\r
10  * @class Ext.layout.ColumnLayout\r
11  * @extends Ext.layout.ContainerLayout\r
12  * <p>This is the layout style of choice for creating structural layouts in a multi-column format where the width of\r
13  * each column can be specified as a percentage or fixed width, but the height is allowed to vary based on the content.\r
14  * This class is intended to be extended or created via the layout:'column' {@link Ext.Container#layout} config,\r
15  * and should generally not need to be created directly via the new keyword.</p>\r
16  * <p>ColumnLayout does not have any direct config options (other than inherited ones), but it does support a\r
17  * specific config property of <b><tt>columnWidth</tt></b> that can be included in the config of any panel added to it.  The\r
18  * layout will use the columnWidth (if present) or width of each panel during layout to determine how to size each panel.\r
19  * If width or columnWidth is not specified for a given panel, its width will default to the panel's width (or auto).</p>\r
20  * <p>The width property is always evaluated as pixels, and must be a number greater than or equal to 1.\r
21  * The columnWidth property is always evaluated as a percentage, and must be a decimal value greater than 0 and\r
22  * less than 1 (e.g., .25).</p>\r
23  * <p>The basic rules for specifying column widths are pretty simple.  The logic makes two passes through the\r
24  * set of contained panels.  During the first layout pass, all panels that either have a fixed width or none\r
25  * specified (auto) are skipped, but their widths are subtracted from the overall container width.  During the second\r
26  * pass, all panels with columnWidths are assigned pixel widths in proportion to their percentages based on\r
27  * the total <b>remaining</b> container width.  In other words, percentage width panels are designed to fill the space\r
28  * left over by all the fixed-width and/or auto-width panels.  Because of this, while you can specify any number of columns\r
29  * with different percentages, the columnWidths must always add up to 1 (or 100%) when added together, otherwise your\r
30  * layout may not render as expected.  Example usage:</p>\r
31  * <pre><code>\r
32 // All columns are percentages -- they must add up to 1\r
33 var p = new Ext.Panel({\r
34     title: 'Column Layout - Percentage Only',\r
35     layout:'column',\r
36     items: [{\r
37         title: 'Column 1',\r
38         columnWidth: .25\r
39     },{\r
40         title: 'Column 2',\r
41         columnWidth: .6\r
42     },{\r
43         title: 'Column 3',\r
44         columnWidth: .15\r
45     }]\r
46 });\r
47 \r
48 // Mix of width and columnWidth -- all columnWidth values must add up\r
49 // to 1. The first column will take up exactly 120px, and the last two\r
50 // columns will fill the remaining container width.\r
51 var p = new Ext.Panel({\r
52     title: 'Column Layout - Mixed',\r
53     layout:'column',\r
54     items: [{\r
55         title: 'Column 1',\r
56         width: 120\r
57     },{\r
58         title: 'Column 2',\r
59         columnWidth: .8\r
60     },{\r
61         title: 'Column 3',\r
62         columnWidth: .2\r
63     }]\r
64 });\r
65 </code></pre>\r
66  */\r
67 Ext.layout.ColumnLayout = Ext.extend(Ext.layout.ContainerLayout, {\r
68     // private\r
69     monitorResize:true,\r
70 \r
71     type: 'column',\r
72 \r
73     extraCls: 'x-column',\r
74 \r
75     scrollOffset : 0,\r
76 \r
77     // private\r
78 \r
79     targetCls: 'x-column-layout-ct',\r
80 \r
81     isValidParent : function(c, target){\r
82         return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;\r
83     },\r
84 \r
85     getLayoutTargetSize : function() {\r
86         var target = this.container.getLayoutTarget(), ret;\r
87         if (target) {\r
88             ret = target.getViewSize();\r
89             ret.width -= target.getPadding('lr');\r
90             ret.height -= target.getPadding('tb');\r
91         }\r
92         return ret;\r
93     },\r
94 \r
95     renderAll : function(ct, target) {\r
96         if(!this.innerCt){\r
97             // the innerCt prevents wrapping and shuffling while\r
98             // the container is resizing\r
99             this.innerCt = target.createChild({cls:'x-column-inner'});\r
100             this.innerCt.createChild({cls:'x-clear'});\r
101         }\r
102         Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);\r
103     },\r
104 \r
105     // private\r
106     onLayout : function(ct, target){\r
107         var cs = ct.items.items, len = cs.length, c, i;\r
108 \r
109         this.renderAll(ct, target);\r
110 \r
111         var size = this.getLayoutTargetSize();\r
112 \r
113         if(size.width < 1 && size.height < 1){ // display none?\r
114             return;\r
115         }\r
116 \r
117         var w = size.width - this.scrollOffset,\r
118             h = size.height,\r
119             pw = w;\r
120 \r
121         this.innerCt.setWidth(w);\r
122 \r
123         // some columns can be percentages while others are fixed\r
124         // so we need to make 2 passes\r
125 \r
126         for(i = 0; i < len; i++){\r
127             c = cs[i];\r
128             if(!c.columnWidth){\r
129                 pw -= (c.getWidth() + c.getPositionEl().getMargins('lr'));\r
130             }\r
131         }\r
132 \r
133         pw = pw < 0 ? 0 : pw;\r
134 \r
135         for(i = 0; i < len; i++){\r
136             c = cs[i];\r
137             if(c.columnWidth){\r
138                 c.setSize(Math.floor(c.columnWidth * pw) - c.getPositionEl().getMargins('lr'));\r
139             }\r
140         }\r
141 \r
142         // Browsers differ as to when they account for scrollbars.  We need to re-measure to see if the scrollbar\r
143         // spaces were accounted for properly.  If not, re-layout.\r
144         if (Ext.isIE) {\r
145             if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {\r
146                 var ts = this.getLayoutTargetSize();\r
147                 if (ts.width != size.width){\r
148                     this.adjustmentPass = true;\r
149                     this.onLayout(ct, target);\r
150                 }\r
151             }\r
152         }\r
153         delete this.adjustmentPass;\r
154     }\r
155 \r
156     <div id="prop-Ext.layout.ColumnLayout-activeItem"></div>/**\r
157      * @property activeItem\r
158      * @hide\r
159      */\r
160 });\r
161 \r
162 Ext.Container.LAYOUTS['column'] = Ext.layout.ColumnLayout;</pre>    \r
163 </body>\r
164 </html>