1 | /* |
---|
2 | * Ext JS Library 2.2.1 |
---|
3 | * Copyright(c) 2006-2009, Ext JS, LLC. |
---|
4 | * licensing@extjs.com |
---|
5 | * |
---|
6 | * http://extjs.com/license |
---|
7 | */ |
---|
8 | |
---|
9 | |
---|
10 | // We are adding these custom layouts to a namespace that does not |
---|
11 | // exist by default in Ext, so we have to add the namespace first: |
---|
12 | Ext.ns('Ext.ux.layout'); |
---|
13 | |
---|
14 | /* |
---|
15 | * ================ CenterLayout ======================= |
---|
16 | */ |
---|
17 | /** |
---|
18 | * @class Ext.ux.layout.CenterLayout |
---|
19 | * @extends Ext.layout.FitLayout |
---|
20 | * <p>This is a very simple layout style used to center contents within a container. This layout works within |
---|
21 | * nested containers and can also be used as expected as a Viewport layout to center the page layout.</p> |
---|
22 | * <p>As a subclass of FitLayout, CenterLayout expects to have a single child panel of the container that uses |
---|
23 | * the layout. The layout does not require any config options, although the child panel contained within the |
---|
24 | * layout must provide a fixed or percentage width. The child panel's height will fit to the container by |
---|
25 | * default, but you can specify <tt>autoHeight:true</tt> to allow it to autosize based on its content height. |
---|
26 | * Example usage:</p> |
---|
27 | * <pre><code> |
---|
28 | // The content panel is centered in the container |
---|
29 | var p = new Ext.Panel({ |
---|
30 | title: 'Center Layout', |
---|
31 | layout: 'ux.center', |
---|
32 | items: [{ |
---|
33 | title: 'Centered Content', |
---|
34 | width: '75%', |
---|
35 | html: 'Some content' |
---|
36 | }] |
---|
37 | }); |
---|
38 | |
---|
39 | // If you leave the title blank and specify no border |
---|
40 | // you'll create a non-visual, structural panel just |
---|
41 | // for centering the contents in the main container. |
---|
42 | var p = new Ext.Panel({ |
---|
43 | layout: 'ux.center', |
---|
44 | border: false, |
---|
45 | items: [{ |
---|
46 | title: 'Centered Content', |
---|
47 | width: 300, |
---|
48 | autoHeight: true, |
---|
49 | html: 'Some content' |
---|
50 | }] |
---|
51 | }); |
---|
52 | </code></pre> |
---|
53 | */ |
---|
54 | Ext.ux.layout.CenterLayout = Ext.extend(Ext.layout.FitLayout, { |
---|
55 | // private |
---|
56 | setItemSize : function(item, size){ |
---|
57 | this.container.addClass('ux-layout-center'); |
---|
58 | item.addClass('ux-layout-center-item'); |
---|
59 | if(item && size.height > 0){ |
---|
60 | if(item.width){ |
---|
61 | size.width = item.width; |
---|
62 | } |
---|
63 | item.setSize(size); |
---|
64 | } |
---|
65 | } |
---|
66 | }); |
---|
67 | Ext.Container.LAYOUTS['ux.center'] = Ext.ux.layout.CenterLayout; |
---|
68 | |
---|
69 | /* |
---|
70 | * CenterLayout demo panel |
---|
71 | */ |
---|
72 | var centerLayout = { |
---|
73 | id: 'center-panel', |
---|
74 | layout:'ux.center', |
---|
75 | items: { |
---|
76 | title: 'Centered Panel: 75% of container width and fit height', |
---|
77 | layout: 'ux.center', |
---|
78 | autoScroll: true, |
---|
79 | width: '75%', |
---|
80 | bodyStyle: 'padding:20px 0;', |
---|
81 | items: [{ |
---|
82 | title: 'Inner Centered Panel', |
---|
83 | html: 'Fixed 300px wide and auto height. The container panel will also autoscroll if narrower than 300px.', |
---|
84 | width: 300, |
---|
85 | frame: true, |
---|
86 | autoHeight: true, |
---|
87 | bodyStyle: 'padding:10px 20px;' |
---|
88 | }] |
---|
89 | } |
---|
90 | }; |
---|
91 | |
---|
92 | /* |
---|
93 | * ================ RowLayout ======================= |
---|
94 | */ |
---|
95 | /** |
---|
96 | * @class Ext.ux.layout.RowLayout |
---|
97 | * @extends Ext.layout.ContainerLayout |
---|
98 | * <p>This is the layout style of choice for creating structural layouts in a multi-row format where the height of |
---|
99 | * each row can be specified as a percentage or fixed height. Row widths can also be fixed, percentage or auto. |
---|
100 | * This class is intended to be extended or created via the layout:'ux.row' {@link Ext.Container#layout} config, |
---|
101 | * and should generally not need to be created directly via the new keyword.</p> |
---|
102 | * <p>RowLayout does not have any direct config options (other than inherited ones), but it does support a |
---|
103 | * specific config property of <b><tt>rowHeight</tt></b> that can be included in the config of any panel added to it. The |
---|
104 | * layout will use the rowHeight (if present) or height of each panel during layout to determine how to size each panel. |
---|
105 | * If height or rowHeight is not specified for a given panel, its height will default to the panel's height (or auto).</p> |
---|
106 | * <p>The height property is always evaluated as pixels, and must be a number greater than or equal to 1. |
---|
107 | * The rowHeight property is always evaluated as a percentage, and must be a decimal value greater than 0 and |
---|
108 | * less than 1 (e.g., .25).</p> |
---|
109 | * <p>The basic rules for specifying row heights are pretty simple. The logic makes two passes through the |
---|
110 | * set of contained panels. During the first layout pass, all panels that either have a fixed height or none |
---|
111 | * specified (auto) are skipped, but their heights are subtracted from the overall container height. During the second |
---|
112 | * pass, all panels with rowHeights are assigned pixel heights in proportion to their percentages based on |
---|
113 | * the total <b>remaining</b> container height. In other words, percentage height panels are designed to fill the space |
---|
114 | * left over by all the fixed-height and/or auto-height panels. Because of this, while you can specify any number of rows |
---|
115 | * with different percentages, the rowHeights must always add up to 1 (or 100%) when added together, otherwise your |
---|
116 | * layout may not render as expected. Example usage:</p> |
---|
117 | * <pre><code> |
---|
118 | // All rows are percentages -- they must add up to 1 |
---|
119 | var p = new Ext.Panel({ |
---|
120 | title: 'Row Layout - Percentage Only', |
---|
121 | layout:'ux.row', |
---|
122 | items: [{ |
---|
123 | title: 'Row 1', |
---|
124 | rowHeight: .25 |
---|
125 | },{ |
---|
126 | title: 'Row 2', |
---|
127 | rowHeight: .6 |
---|
128 | },{ |
---|
129 | title: 'Row 3', |
---|
130 | rowHeight: .15 |
---|
131 | }] |
---|
132 | }); |
---|
133 | |
---|
134 | // Mix of height and rowHeight -- all rowHeight values must add |
---|
135 | // up to 1. The first row will take up exactly 120px, and the last two |
---|
136 | // rows will fill the remaining container height. |
---|
137 | var p = new Ext.Panel({ |
---|
138 | title: 'Row Layout - Mixed', |
---|
139 | layout:'ux.row', |
---|
140 | items: [{ |
---|
141 | title: 'Row 1', |
---|
142 | height: 120, |
---|
143 | // standard panel widths are still supported too: |
---|
144 | width: '50%' // or 200 |
---|
145 | },{ |
---|
146 | title: 'Row 2', |
---|
147 | rowHeight: .8, |
---|
148 | width: 300 |
---|
149 | },{ |
---|
150 | title: 'Row 3', |
---|
151 | rowHeight: .2 |
---|
152 | }] |
---|
153 | }); |
---|
154 | </code></pre> |
---|
155 | */ |
---|
156 | Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, { |
---|
157 | // private |
---|
158 | monitorResize:true, |
---|
159 | |
---|
160 | // private |
---|
161 | isValidParent : function(c, target){ |
---|
162 | return c.getEl().dom.parentNode == this.innerCt.dom; |
---|
163 | }, |
---|
164 | |
---|
165 | // private |
---|
166 | onLayout : function(ct, target){ |
---|
167 | var rs = ct.items.items, len = rs.length, r, i; |
---|
168 | |
---|
169 | if(!this.innerCt){ |
---|
170 | target.addClass('ux-row-layout-ct'); |
---|
171 | this.innerCt = target.createChild({cls:'x-row-inner'}); |
---|
172 | } |
---|
173 | this.renderAll(ct, this.innerCt); |
---|
174 | |
---|
175 | var size = target.getViewSize(); |
---|
176 | |
---|
177 | if(size.width < 1 && size.height < 1){ // display none? |
---|
178 | return; |
---|
179 | } |
---|
180 | |
---|
181 | var h = size.height - target.getPadding('tb'), |
---|
182 | ph = h; |
---|
183 | |
---|
184 | this.innerCt.setSize({height:h}); |
---|
185 | |
---|
186 | // some rows can be percentages while others are fixed |
---|
187 | // so we need to make 2 passes |
---|
188 | |
---|
189 | for(i = 0; i < len; i++){ |
---|
190 | r = rs[i]; |
---|
191 | if(!r.rowHeight){ |
---|
192 | ph -= (r.getSize().height + r.getEl().getMargins('tb')); |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | ph = ph < 0 ? 0 : ph; |
---|
197 | |
---|
198 | for(i = 0; i < len; i++){ |
---|
199 | r = rs[i]; |
---|
200 | if(r.rowHeight){ |
---|
201 | r.setSize({height: Math.floor(r.rowHeight*ph) - r.getEl().getMargins('tb')}); |
---|
202 | } |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | /** |
---|
207 | * @property activeItem |
---|
208 | * @hide |
---|
209 | */ |
---|
210 | }); |
---|
211 | Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout; |
---|
212 | |
---|
213 | /* |
---|
214 | * RowLayout demo panel |
---|
215 | */ |
---|
216 | var rowLayout = { |
---|
217 | id: 'row-panel', |
---|
218 | bodyStyle: 'padding:5px', |
---|
219 | layout: 'ux.row', |
---|
220 | title: 'Row Layout', |
---|
221 | items: [{ |
---|
222 | title: 'Height = 25%, Width = 50%', |
---|
223 | rowHeight: .25, |
---|
224 | width: '50%' |
---|
225 | },{ |
---|
226 | title: 'Height = 100px, Width = 300px', |
---|
227 | height: 100, |
---|
228 | width: 300 |
---|
229 | },{ |
---|
230 | title: 'Height = 75%, Width = fit', |
---|
231 | rowHeight: .75 |
---|
232 | }] |
---|
233 | }; |
---|
234 | |
---|