Upgrade to ExtJS 3.2.1 - Released 04/27/2010
[extjs.git] / src / widgets / layout / FitLayout.js
1 /*!
2  * Ext JS Library 3.2.1
3  * Copyright(c) 2006-2010 Ext JS, Inc.
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**
8  * @class Ext.layout.FitLayout
9  * @extends Ext.layout.ContainerLayout
10  * <p>This is a base class for layouts that contain <b>a single item</b> that automatically expands to fill the layout's
11  * container.  This class is intended to be extended or created via the <tt>layout:'fit'</tt> {@link Ext.Container#layout}
12  * config, and should generally not need to be created directly via the new keyword.</p>
13  * <p>FitLayout does not have any direct config options (other than inherited ones).  To fit a panel to a container
14  * using FitLayout, simply set layout:'fit' on the container and add a single panel to it.  If the container has
15  * multiple panels, only the first one will be displayed.  Example usage:</p>
16  * <pre><code>
17 var p = new Ext.Panel({
18     title: 'Fit Layout',
19     layout:'fit',
20     items: {
21         title: 'Inner Panel',
22         html: '&lt;p&gt;This is the inner panel content&lt;/p&gt;',
23         border: false
24     }
25 });
26 </code></pre>
27  */
28 Ext.layout.FitLayout = Ext.extend(Ext.layout.ContainerLayout, {
29     // private
30     monitorResize:true,
31
32     type: 'fit',
33
34     getLayoutTargetSize : function() {
35         var target = this.container.getLayoutTarget();
36         if (!target) {
37             return {};
38         }
39         // Style Sized (scrollbars not included)
40         return target.getStyleSize();
41     },
42
43     // private
44     onLayout : function(ct, target){
45         Ext.layout.FitLayout.superclass.onLayout.call(this, ct, target);
46         if(!ct.collapsed){
47             this.setItemSize(this.activeItem || ct.items.itemAt(0), this.getLayoutTargetSize());
48         }
49     },
50
51     // private
52     setItemSize : function(item, size){
53         if(item && size.height > 0){ // display none?
54             item.setSize(size);
55         }
56     }
57 });
58 Ext.Container.LAYOUTS['fit'] = Ext.layout.FitLayout;