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