Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / RowLayout.html
1 <html>\r
2 <head>\r
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
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">// We are adding these custom layouts to a namespace that does not
9 // exist by default in Ext, so we have to add the namespace first:
10 Ext.ns('Ext.ux.layout');
11
12 <div id="cls-Ext.ux.layout.RowLayout"></div>/**
13  * @class Ext.ux.layout.RowLayout
14  * @extends Ext.layout.ContainerLayout
15  * <p>This is the layout style of choice for creating structural layouts in a multi-row format where the height of
16  * each row can be specified as a percentage or fixed height.  Row widths can also be fixed, percentage or auto.
17  * This class is intended to be extended or created via the layout:'ux.row' {@link Ext.Container#layout} config,
18  * and should generally not need to be created directly via the new keyword.</p>
19  * <p>RowLayout does not have any direct config options (other than inherited ones), but it does support a
20  * specific config property of <b><tt>rowHeight</tt></b> that can be included in the config of any panel added to it.  The
21  * layout will use the rowHeight (if present) or height of each panel during layout to determine how to size each panel.
22  * If height or rowHeight is not specified for a given panel, its height will default to the panel's height (or auto).</p>
23  * <p>The height property is always evaluated as pixels, and must be a number greater than or equal to 1.
24  * The rowHeight property is always evaluated as a percentage, and must be a decimal value greater than 0 and
25  * less than 1 (e.g., .25).</p>
26  * <p>The basic rules for specifying row heights are pretty simple.  The logic makes two passes through the
27  * set of contained panels.  During the first layout pass, all panels that either have a fixed height or none
28  * specified (auto) are skipped, but their heights are subtracted from the overall container height.  During the second
29  * pass, all panels with rowHeights are assigned pixel heights in proportion to their percentages based on
30  * the total <b>remaining</b> container height.  In other words, percentage height panels are designed to fill the space
31  * left over by all the fixed-height and/or auto-height panels.  Because of this, while you can specify any number of rows
32  * with different percentages, the rowHeights must always add up to 1 (or 100%) when added together, otherwise your
33  * layout may not render as expected.  Example usage:</p>
34  * <pre><code>
35 // All rows are percentages -- they must add up to 1
36 var p = new Ext.Panel({
37     title: 'Row Layout - Percentage Only',
38     layout:'ux.row',
39     items: [{
40         title: 'Row 1',
41         rowHeight: .25
42     },{
43         title: 'Row 2',
44         rowHeight: .6
45     },{
46         title: 'Row 3',
47         rowHeight: .15
48     }]
49 });
50
51 // Mix of height and rowHeight -- all rowHeight values must add
52 // up to 1. The first row will take up exactly 120px, and the last two
53 // rows will fill the remaining container height.
54 var p = new Ext.Panel({
55     title: 'Row Layout - Mixed',
56     layout:'ux.row',
57     items: [{
58         title: 'Row 1',
59         height: 120,
60         // standard panel widths are still supported too:
61         width: '50%' // or 200
62     },{
63         title: 'Row 2',
64         rowHeight: .8,
65         width: 300
66     },{
67         title: 'Row 3',
68         rowHeight: .2
69     }]
70 });
71 </code></pre>
72  */
73 Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, {
74     // private
75     monitorResize:true,
76
77     // private
78     isValidParent : function(c, target){
79         return c.getEl().dom.parentNode == this.innerCt.dom;
80     },
81
82     // private
83     onLayout : function(ct, target){
84         var rs = ct.items.items, len = rs.length, r, i;
85
86         if(!this.innerCt){
87             target.addClass('ux-row-layout-ct');
88             this.innerCt = target.createChild({cls:'x-row-inner'});
89         }
90         this.renderAll(ct, this.innerCt);
91
92         var size = target.getViewSize();
93
94         if(size.width < 1 && size.height < 1){ // display none?
95             return;
96         }
97
98         var h = size.height - target.getPadding('tb'),
99             ph = h;
100
101         this.innerCt.setSize({height:h});
102
103         // some rows can be percentages while others are fixed
104         // so we need to make 2 passes
105
106         for(i = 0; i < len; i++){
107             r = rs[i];
108             if(!r.rowHeight){
109                 ph -= (r.getSize().height + r.getEl().getMargins('tb'));
110             }
111         }
112
113         ph = ph < 0 ? 0 : ph;
114
115         for(i = 0; i < len; i++){
116             r = rs[i];
117             if(r.rowHeight){
118                 r.setSize({height: Math.floor(r.rowHeight*ph) - r.getEl().getMargins('tb')});
119             }
120         }
121     }
122
123     <div id="prop-Ext.ux.layout.RowLayout-activeItem"></div>/**
124      * @property activeItem
125      * @hide
126      */
127 });
128
129 Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout;
130 </pre>    \r
131 </body>\r
132 </html>