3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.layout.container.Column
17 * @extends Ext.layout.container.Auto
18 * <p>This is the layout style of choice for creating structural layouts in a multi-column format where the width of
19 * each column can be specified as a percentage or fixed width, but the height is allowed to vary based on the content.
20 * This class is intended to be extended or created via the layout:'column' {@link Ext.container.Container#layout} config,
21 * and should generally not need to be created directly via the new keyword.</p>
22 * <p>ColumnLayout does not have any direct config options (other than inherited ones), but it does support a
23 * specific config property of <b><tt>columnWidth</tt></b> that can be included in the config of any panel added to it. The
24 * layout will use the columnWidth (if present) or width of each panel during layout to determine how to size each panel.
25 * If width or columnWidth is not specified for a given panel, its width will default to the panel's width (or auto).</p>
26 * <p>The width property is always evaluated as pixels, and must be a number greater than or equal to 1.
27 * The columnWidth property is always evaluated as a percentage, and must be a decimal value greater than 0 and
28 * less than 1 (e.g., .25).</p>
29 * <p>The basic rules for specifying column widths are pretty simple. The logic makes two passes through the
30 * set of contained panels. During the first layout pass, all panels that either have a fixed width or none
31 * specified (auto) are skipped, but their widths are subtracted from the overall container width. During the second
32 * pass, all panels with columnWidths are assigned pixel widths in proportion to their percentages based on
33 * the total <b>remaining</b> container width. In other words, percentage width panels are designed to fill the space
34 * left over by all the fixed-width and/or auto-width panels. Because of this, while you can specify any number of columns
35 * with different percentages, the columnWidths must always add up to 1 (or 100%) when added together, otherwise your
36 * layout may not render as expected.
37 * {@img Ext.layout.container.Column/Ext.layout.container.Column1.png Ext.layout.container.Column container layout}
40 // All columns are percentages -- they must add up to 1
41 Ext.create('Ext.panel.Panel', {
42 title: 'Column Layout - Percentage Only',
56 renderTo: Ext.getBody()
59 // {@img Ext.layout.container.Column/Ext.layout.container.Column2.png Ext.layout.container.Column container layout}
60 // Mix of width and columnWidth -- all columnWidth values must add up
61 // to 1. The first column will take up exactly 120px, and the last two
62 // columns will fill the remaining container width.
64 Ext.create('Ext.Panel', {
65 title: 'Column Layout - Mixed',
79 renderTo: Ext.getBody()
83 Ext.define('Ext.layout.container.Column', {
85 extend: 'Ext.layout.container.Auto',
86 alias: ['layout.column'],
87 alternateClassName: 'Ext.layout.ColumnLayout',
91 itemCls: Ext.baseCSSPrefix + 'column',
93 targetCls: Ext.baseCSSPrefix + 'column-layout-ct',
97 bindToOwnerCtComponent: false,
99 getRenderTarget : function() {
102 // the innerCt prevents wrapping and shuffling while
103 // the container is resizing
104 this.innerCt = this.getTarget().createChild({
105 cls: Ext.baseCSSPrefix + 'column-inner'
108 // Column layout uses natural HTML flow to arrange the child items.
109 // To ensure that all browsers (I'm looking at you IE!) add the bottom margin of the last child to the
110 // containing element height, we create a zero-sized element with style clear:both to force a "new line"
111 this.clearEl = this.innerCt.createChild({
112 cls: Ext.baseCSSPrefix + 'clear',
120 onLayout : function() {
122 target = me.getTarget(),
123 items = me.getLayoutItems(),
127 parallelMargins = [],
133 size = me.getLayoutTargetSize();
134 if (size.width < len * 10) { // Don't lay out in impossibly small target (probably display:none, or initial, unsized Container)
138 // On the first pass, for all except IE6-7, we lay out the items with no scrollbars visible using style overflow: hidden.
139 // If, after the layout, it is detected that there is vertical overflow,
140 // we will recurse back through here. Do not adjust overflow style at that time.
141 if (me.adjustmentPass) {
142 if (Ext.isIE6 || Ext.isIE7 || Ext.isIEQuirks) {
143 size.width = me.adjustedWidth;
146 i = target.getStyle('overflow');
147 if (i && i != 'hidden') {
148 me.autoScroll = true;
149 if (!(Ext.isIE6 || Ext.isIE7 || Ext.isIEQuirks)) {
150 target.setStyle('overflow', 'hidden');
151 size = me.getLayoutTargetSize();
156 availableWidth = size.width - me.scrollOffset;
157 me.innerCt.setWidth(availableWidth);
159 // some columns can be percentages while others are fixed
160 // so we need to make 2 passes
161 for (i = 0; i < len; i++) {
163 itemParallelMargins = parallelMargins[i] = item.getEl().getMargin('lr');
164 if (!item.columnWidth) {
165 availableWidth -= (item.getWidth() + itemParallelMargins);
169 availableWidth = availableWidth < 0 ? 0 : availableWidth;
170 for (i = 0; i < len; i++) {
172 if (item.columnWidth) {
173 columnWidth = Math.floor(item.columnWidth * availableWidth) - parallelMargins[i];
174 if (item.getWidth() != columnWidth) {
175 me.setItemSize(item, columnWidth, item.height);
180 // After the first pass on an autoScroll layout, restore the overflow settings if it had been changed (only changed for non-IE6)
181 if (!me.adjustmentPass && me.autoScroll) {
183 // If there's a vertical overflow, relay with scrollbars
184 target.setStyle('overflow', 'auto');
185 me.adjustmentPass = (target.dom.scrollHeight > size.height);
186 if (Ext.isIE6 || Ext.isIE7 || Ext.isIEQuirks) {
187 me.adjustedWidth = size.width - Ext.getScrollBarWidth();
189 target.setStyle('overflow', 'auto');
192 // If the layout caused height overflow, recurse back and recalculate (with overflow setting restored on non-IE6)
193 if (me.adjustmentPass) {
197 delete me.adjustmentPass;
200 configureItem: function(item) {
201 if (item.columnWidth) {
202 item.layoutManagedWidth = 1;
204 item.layoutManagedWidth = 2;
206 item.layoutManagedHeight = 2;
207 this.callParent(arguments);