4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-layout-container-Column'>/**
19 </span> * This is the layout style of choice for creating structural layouts in a multi-column format where the width of each
20 * column can be specified as a percentage or fixed width, but the height is allowed to vary based on the content. This
21 * class is intended to be extended or created via the layout:'column' {@link Ext.container.Container#layout} config,
22 * and should generally not need to be created directly via the new keyword.
24 * ColumnLayout does not have any direct config options (other than inherited ones), but it does support a specific
25 * config property of `columnWidth` that can be included in the config of any panel added to it. The layout will use
26 * the columnWidth (if present) or width of each panel during layout to determine how to size each panel. If width or
27 * columnWidth is not specified for a given panel, its width will default to the panel's width (or auto).
29 * The width property is always evaluated as pixels, and must be a number greater than or equal to 1. The columnWidth
30 * property is always evaluated as a percentage, and must be a decimal value greater than 0 and less than 1 (e.g., .25).
32 * The basic rules for specifying column widths are pretty simple. The logic makes two passes through the set of
33 * contained panels. During the first layout pass, all panels that either have a fixed width or none specified (auto)
34 * are skipped, but their widths are subtracted from the overall container width.
36 * During the second pass, all panels with columnWidths are assigned pixel widths in proportion to their percentages
37 * based on the total **remaining** container width. In other words, percentage width panels are designed to fill
38 * the space left over by all the fixed-width and/or auto-width panels. Because of this, while you can specify any
39 * number of columns with different percentages, the columnWidths must always add up to 1 (or 100%) when added
40 * together, otherwise your layout may not render as expected.
43 * // All columns are percentages -- they must add up to 1
44 * Ext.create('Ext.panel.Panel', {
45 * title: 'Column Layout - Percentage Only',
59 * renderTo: Ext.getBody()
62 * // Mix of width and columnWidth -- all columnWidth values must add up
63 * // to 1. The first column will take up exactly 120px, and the last two
64 * // columns will fill the remaining container width.
66 * Ext.create('Ext.Panel', {
67 * title: 'Column Layout - Mixed',
81 * renderTo: Ext.getBody()
84 Ext.define('Ext.layout.container.Column', {
86 extend: 'Ext.layout.container.Auto',
87 alias: ['layout.column'],
88 alternateClassName: 'Ext.layout.ColumnLayout',
92 itemCls: Ext.baseCSSPrefix + 'column',
94 targetCls: Ext.baseCSSPrefix + 'column-layout-ct',
98 bindToOwnerCtComponent: false,
100 getRenderTarget : function() {
103 // the innerCt prevents wrapping and shuffling while
104 // the container is resizing
105 this.innerCt = this.getTarget().createChild({
106 cls: Ext.baseCSSPrefix + 'column-inner'
109 // Column layout uses natural HTML flow to arrange the child items.
110 // To ensure that all browsers (I'm looking at you IE!) add the bottom margin of the last child to the
111 // containing element height, we create a zero-sized element with style clear:both to force a "new line"
112 this.clearEl = this.innerCt.createChild({
113 cls: Ext.baseCSSPrefix + 'clear',
121 onLayout : function() {
123 target = me.getTarget(),
124 items = me.getLayoutItems(),
128 parallelMargins = [],
134 size = me.getLayoutTargetSize();
135 if (size.width < len * 10) { // Don't lay out in impossibly small target (probably display:none, or initial, unsized Container)
139 // On the first pass, for all except IE6-7, we lay out the items with no scrollbars visible using style overflow: hidden.
140 // If, after the layout, it is detected that there is vertical overflow,
141 // we will recurse back through here. Do not adjust overflow style at that time.
142 if (me.adjustmentPass) {
143 if (Ext.isIE6 || Ext.isIE7 || Ext.isIEQuirks) {
144 size.width = me.adjustedWidth;
147 i = target.getStyle('overflow');
148 if (i && i != 'hidden') {
149 me.autoScroll = true;
150 if (!(Ext.isIE6 || Ext.isIE7 || Ext.isIEQuirks)) {
151 target.setStyle('overflow', 'hidden');
152 size = me.getLayoutTargetSize();
157 availableWidth = size.width - me.scrollOffset;
158 me.innerCt.setWidth(availableWidth);
160 // some columns can be percentages while others are fixed
161 // so we need to make 2 passes
162 for (i = 0; i < len; i++) {
164 itemParallelMargins = parallelMargins[i] = item.getEl().getMargin('lr');
165 if (!item.columnWidth) {
166 availableWidth -= (item.getWidth() + itemParallelMargins);
170 availableWidth = availableWidth < 0 ? 0 : availableWidth;
171 for (i = 0; i < len; i++) {
173 if (item.columnWidth) {
174 columnWidth = Math.floor(item.columnWidth * availableWidth) - parallelMargins[i];
175 me.setItemSize(item, columnWidth, item.height);
181 // After the first pass on an autoScroll layout, restore the overflow settings if it had been changed (only changed for non-IE6)
182 if (!me.adjustmentPass && me.autoScroll) {
184 // If there's a vertical overflow, relay with scrollbars
185 target.setStyle('overflow', 'auto');
186 me.adjustmentPass = (target.dom.scrollHeight > size.height);
187 if (Ext.isIE6 || Ext.isIE7 || Ext.isIEQuirks) {
188 me.adjustedWidth = size.width - Ext.getScrollBarWidth();
190 target.setStyle('overflow', 'auto');
193 // If the layout caused height overflow, recurse back and recalculate (with overflow setting restored on non-IE6)
194 if (me.adjustmentPass) {
198 delete me.adjustmentPass;
201 configureItem: function(item) {
202 this.callParent(arguments);
204 if (item.columnWidth) {
205 item.layoutManagedWidth = 1;