2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 // We are adding these custom layouts to a namespace that does not
\r
11 // exist by default in Ext, so we have to add the namespace first:
\r
12 Ext.ns('Ext.ux.layout');
\r
15 * ================ CenterLayout =======================
\r
18 * @class Ext.ux.layout.CenterLayout
\r
19 * @extends Ext.layout.FitLayout
\r
20 * <p>This is a very simple layout style used to center contents within a container. This layout works within
\r
21 * nested containers and can also be used as expected as a Viewport layout to center the page layout.</p>
\r
22 * <p>As a subclass of FitLayout, CenterLayout expects to have a single child panel of the container that uses
\r
23 * the layout. The layout does not require any config options, although the child panel contained within the
\r
24 * layout must provide a fixed or percentage width. The child panel's height will fit to the container by
\r
25 * default, but you can specify <tt>autoHeight:true</tt> to allow it to autosize based on its content height.
\r
26 * Example usage:</p>
\r
28 // The content panel is centered in the container
\r
29 var p = new Ext.Panel({
\r
30 title: 'Center Layout',
\r
31 layout: 'ux.center',
\r
33 title: 'Centered Content',
\r
35 html: 'Some content'
\r
39 // If you leave the title blank and specify no border
\r
40 // you'll create a non-visual, structural panel just
\r
41 // for centering the contents in the main container.
\r
42 var p = new Ext.Panel({
\r
43 layout: 'ux.center',
\r
46 title: 'Centered Content',
\r
49 html: 'Some content'
\r
54 Ext.ux.layout.CenterLayout = Ext.extend(Ext.layout.FitLayout, {
\r
56 setItemSize : function(item, size){
\r
57 this.container.addClass('ux-layout-center');
\r
58 item.addClass('ux-layout-center-item');
\r
59 if(item && size.height > 0){
\r
61 size.width = item.width;
\r
67 Ext.Container.LAYOUTS['ux.center'] = Ext.ux.layout.CenterLayout;
\r
70 * CenterLayout demo panel
\r
72 var centerLayout = {
\r
76 title: 'Centered Panel: 75% of container width and fit height',
\r
77 layout: 'ux.center',
\r
80 bodyStyle: 'padding:20px 0;',
\r
82 title: 'Inner Centered Panel',
\r
83 html: 'Fixed 300px wide and auto height. The container panel will also autoscroll if narrower than 300px.',
\r
87 bodyStyle: 'padding:10px 20px;'
\r
93 * ================ RowLayout =======================
\r
96 * @class Ext.ux.layout.RowLayout
\r
97 * @extends Ext.layout.ContainerLayout
\r
98 * <p>This is the layout style of choice for creating structural layouts in a multi-row format where the height of
\r
99 * each row can be specified as a percentage or fixed height. Row widths can also be fixed, percentage or auto.
\r
100 * This class is intended to be extended or created via the layout:'ux.row' {@link Ext.Container#layout} config,
\r
101 * and should generally not need to be created directly via the new keyword.</p>
\r
102 * <p>RowLayout does not have any direct config options (other than inherited ones), but it does support a
\r
103 * specific config property of <b><tt>rowHeight</tt></b> that can be included in the config of any panel added to it. The
\r
104 * layout will use the rowHeight (if present) or height of each panel during layout to determine how to size each panel.
\r
105 * If height or rowHeight is not specified for a given panel, its height will default to the panel's height (or auto).</p>
\r
106 * <p>The height property is always evaluated as pixels, and must be a number greater than or equal to 1.
\r
107 * The rowHeight property is always evaluated as a percentage, and must be a decimal value greater than 0 and
\r
108 * less than 1 (e.g., .25).</p>
\r
109 * <p>The basic rules for specifying row heights are pretty simple. The logic makes two passes through the
\r
110 * set of contained panels. During the first layout pass, all panels that either have a fixed height or none
\r
111 * specified (auto) are skipped, but their heights are subtracted from the overall container height. During the second
\r
112 * pass, all panels with rowHeights are assigned pixel heights in proportion to their percentages based on
\r
113 * the total <b>remaining</b> container height. In other words, percentage height panels are designed to fill the space
\r
114 * left over by all the fixed-height and/or auto-height panels. Because of this, while you can specify any number of rows
\r
115 * with different percentages, the rowHeights must always add up to 1 (or 100%) when added together, otherwise your
\r
116 * layout may not render as expected. Example usage:</p>
\r
118 // All rows are percentages -- they must add up to 1
\r
119 var p = new Ext.Panel({
\r
120 title: 'Row Layout - Percentage Only',
\r
134 // Mix of height and rowHeight -- all rowHeight values must add
\r
135 // up to 1. The first row will take up exactly 120px, and the last two
\r
136 // rows will fill the remaining container height.
\r
137 var p = new Ext.Panel({
\r
138 title: 'Row Layout - Mixed',
\r
143 // standard panel widths are still supported too:
\r
144 width: '50%' // or 200
\r
156 Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, {
\r
158 monitorResize:true,
\r
161 isValidParent : function(c, target){
\r
162 return c.getEl().dom.parentNode == this.innerCt.dom;
\r
166 onLayout : function(ct, target){
\r
167 var rs = ct.items.items, len = rs.length, r, i;
\r
170 target.addClass('ux-row-layout-ct');
\r
171 this.innerCt = target.createChild({cls:'x-row-inner'});
\r
173 this.renderAll(ct, this.innerCt);
\r
175 var size = target.getViewSize();
\r
177 if(size.width < 1 && size.height < 1){ // display none?
\r
181 var h = size.height - target.getPadding('tb'),
\r
184 this.innerCt.setSize({height:h});
\r
186 // some rows can be percentages while others are fixed
\r
187 // so we need to make 2 passes
\r
189 for(i = 0; i < len; i++){
\r
192 ph -= (r.getSize().height + r.getEl().getMargins('tb'));
\r
196 ph = ph < 0 ? 0 : ph;
\r
198 for(i = 0; i < len; i++){
\r
201 r.setSize({height: Math.floor(r.rowHeight*ph) - r.getEl().getMargins('tb')});
\r
207 * @property activeItem
\r
211 Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout;
\r
214 * RowLayout demo panel
\r
218 bodyStyle: 'padding:5px',
\r
220 title: 'Row Layout',
\r
222 title: 'Height = 25%, Width = 50%',
\r
226 title: 'Height = 100px, Width = 300px',
\r
230 title: 'Height = 75%, Width = fit',
\r