3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 // We are adding these custom layouts to a namespace that does not
16 // exist by default in Ext, so we have to add the namespace first:
17 Ext.ns('Ext.ux.layout');
20 * @class Ext.ux.layout.RowLayout
21 * @extends Ext.layout.ContainerLayout
22 * <p>This is the layout style of choice for creating structural layouts in a multi-row format where the height of
23 * each row can be specified as a percentage or fixed height. Row widths can also be fixed, percentage or auto.
24 * This class is intended to be extended or created via the layout:'ux.row' {@link Ext.Container#layout} config,
25 * and should generally not need to be created directly via the new keyword.</p>
26 * <p>RowLayout does not have any direct config options (other than inherited ones), but it does support a
27 * specific config property of <b><tt>rowHeight</tt></b> that can be included in the config of any panel added to it. The
28 * layout will use the rowHeight (if present) or height of each panel during layout to determine how to size each panel.
29 * If height or rowHeight is not specified for a given panel, its height will default to the panel's height (or auto).</p>
30 * <p>The height property is always evaluated as pixels, and must be a number greater than or equal to 1.
31 * The rowHeight property is always evaluated as a percentage, and must be a decimal value greater than 0 and
32 * less than 1 (e.g., .25).</p>
33 * <p>The basic rules for specifying row heights are pretty simple. The logic makes two passes through the
34 * set of contained panels. During the first layout pass, all panels that either have a fixed height or none
35 * specified (auto) are skipped, but their heights are subtracted from the overall container height. During the second
36 * pass, all panels with rowHeights are assigned pixel heights in proportion to their percentages based on
37 * the total <b>remaining</b> container height. In other words, percentage height panels are designed to fill the space
38 * left over by all the fixed-height and/or auto-height panels. Because of this, while you can specify any number of rows
39 * with different percentages, the rowHeights must always add up to 1 (or 100%) when added together, otherwise your
40 * layout may not render as expected. Example usage:</p>
42 // All rows are percentages -- they must add up to 1
43 var p = new Ext.Panel({
44 title: 'Row Layout - Percentage Only',
58 // Mix of height and rowHeight -- all rowHeight values must add
59 // up to 1. The first row will take up exactly 120px, and the last two
60 // rows will fill the remaining container height.
61 var p = new Ext.Panel({
62 title: 'Row Layout - Mixed',
67 // standard panel widths are still supported too:
68 width: '50%' // or 200
80 Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, {
87 allowContainerRemove: false,
90 isValidParent : function(c, target){
91 return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
94 getLayoutTargetSize : function() {
95 var target = this.container.getLayoutTarget(), ret;
97 ret = target.getViewSize();
99 // IE in strict mode will return a height of 0 on the 1st pass of getViewSize.
100 // Use getStyleSize to verify the 0 height, the adjustment pass will then work properly
102 if (Ext.isIE && Ext.isStrict && ret.height == 0){
103 ret = target.getStyleSize();
106 ret.width -= target.getPadding('lr');
107 ret.height -= target.getPadding('tb');
112 renderAll : function(ct, target) {
114 // the innerCt prevents wrapping and shuffling while
115 // the container is resizing
116 this.innerCt = target.createChild({cls:'x-column-inner'});
117 this.innerCt.createChild({cls:'x-clear'});
119 Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
123 onLayout : function(ct, target){
124 var rs = ct.items.items,
131 this.renderAll(ct, target);
133 var size = this.getLayoutTargetSize();
135 if(size.width < 1 && size.height < 1){ // display none?
142 this.innerCt.setSize({height:h});
144 // some rows can be percentages while others are fixed
145 // so we need to make 2 passes
147 for(i = 0; i < len; i++){
149 m = r.getPositionEl().getMargins('tb');
152 ph -= (r.getHeight() + m);
156 ph = ph < 0 ? 0 : ph;
158 for(i = 0; i < len; i++){
162 r.setSize({height: Math.floor(r.rowHeight*ph) - m});
166 // Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
167 // spaces were accounted for properly. If not, re-layout.
169 if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
170 var ts = this.getLayoutTargetSize();
171 if (ts.width != size.width){
172 this.adjustmentPass = true;
173 this.onLayout(ct, target);
177 delete this.adjustmentPass;
180 <div id="prop-Ext.ux.layout.RowLayout-activeItem"></div>/**
181 * @property activeItem
186 Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout;