Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / layout / container / HBox.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.layout.container.HBox
17  * @extends Ext.layout.container.Box
18  * <p>A layout that arranges items horizontally across a Container. This layout optionally divides available horizontal
19  * space between child items containing a numeric <code>flex</code> configuration.</p>
20  * This layout may also be used to set the heights of child items by configuring it with the {@link #align} option.
21  * {@img Ext.layout.container.HBox/Ext.layout.container.HBox.png Ext.layout.container.HBox container layout}
22  * Example usage:
23     Ext.create('Ext.Panel', {
24         width: 500,
25         height: 300,
26         title: "HBoxLayout Panel",
27         layout: {
28             type: 'hbox',
29             align: 'stretch'
30         },
31         renderTo: document.body,
32         items: [{
33             xtype: 'panel',
34             title: 'Inner Panel One',
35             flex: 2
36         },{
37             xtype: 'panel',
38             title: 'Inner Panel Two',
39             flex: 1
40         },{
41             xtype: 'panel',
42             title: 'Inner Panel Three',
43             flex: 1
44         }]
45     });
46  */
47 Ext.define('Ext.layout.container.HBox', {
48
49     /* Begin Definitions */
50
51     alias: ['layout.hbox'],
52     extend: 'Ext.layout.container.Box',
53     alternateClassName: 'Ext.layout.HBoxLayout',
54     
55     /* End Definitions */
56
57     /**
58      * @cfg {String} align
59      * Controls how the child items of the container are aligned. Acceptable configuration values for this
60      * property are:
61      * <div class="mdetail-params"><ul>
62      * <li><b><tt>top</tt></b> : <b>Default</b><div class="sub-desc">child items are aligned vertically
63      * at the <b>top</b> of the container</div></li>
64      * <li><b><tt>middle</tt></b> : <div class="sub-desc">child items are aligned vertically in the
65      * <b>middle</b> of the container</div></li>
66      * <li><b><tt>stretch</tt></b> : <div class="sub-desc">child items are stretched vertically to fill
67      * the height of the container</div></li>
68      * <li><b><tt>stretchmax</tt></b> : <div class="sub-desc">child items are stretched vertically to
69      * the height of the largest item.</div></li>
70      * </ul></div>
71      */
72     align: 'top', // top, middle, stretch, strechmax
73
74     //@private
75     alignCenteringString: 'middle',
76
77     type : 'hbox',
78
79     direction: 'horizontal',
80
81     // When creating an argument list to setSize, use this order
82     parallelSizeIndex: 0,
83     perpendicularSizeIndex: 1,
84
85     parallelPrefix: 'width',
86     parallelPrefixCap: 'Width',
87     parallelLT: 'l',
88     parallelRB: 'r',
89     parallelBefore: 'left',
90     parallelBeforeCap: 'Left',
91     parallelAfter: 'right',
92     parallelPosition: 'x',
93
94     perpendicularPrefix: 'height',
95     perpendicularPrefixCap: 'Height',
96     perpendicularLT: 't',
97     perpendicularRB: 'b',
98     perpendicularLeftTop: 'top',
99     perpendicularRightBottom: 'bottom',
100     perpendicularPosition: 'y',
101     configureItem: function(item) {
102         if (item.flex) {
103             item.layoutManagedWidth = 1;
104         } else {
105             item.layoutManagedWidth = 2;
106         }
107
108         if (this.align === 'stretch' || this.align === 'stretchmax') {
109             item.layoutManagedHeight = 1;
110         } else {
111             item.layoutManagedHeight = 2;
112         }
113         this.callParent(arguments);
114     }
115 });