3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
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');
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>
35 // All rows are percentages -- they must add up to 1
36 var p = new Ext.Panel({
37 title: 'Row Layout - Percentage Only',
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',
60 // standard panel widths are still supported too:
61 width: '50%' // or 200
73 Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, {
78 isValidParent : function(c, target){
79 return c.getEl().dom.parentNode == this.innerCt.dom;
83 onLayout : function(ct, target){
84 var rs = ct.items.items, len = rs.length, r, i;
87 target.addClass('ux-row-layout-ct');
88 this.innerCt = target.createChild({cls:'x-row-inner'});
90 this.renderAll(ct, this.innerCt);
92 var size = target.getViewSize();
94 if(size.width < 1 && size.height < 1){ // display none?
98 var h = size.height - target.getPadding('tb'),
101 this.innerCt.setSize({height:h});
103 // some rows can be percentages while others are fixed
104 // so we need to make 2 passes
106 for(i = 0; i < len; i++){
109 ph -= (r.getSize().height + r.getEl().getMargins('tb'));
113 ph = ph < 0 ? 0 : ph;
115 for(i = 0; i < len; i++){
118 r.setSize({height: Math.floor(r.rowHeight*ph) - r.getEl().getMargins('tb')});
123 <div id="prop-Ext.ux.layout.RowLayout-activeItem"></div>/**
124 * @property activeItem
129 Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout;