3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * This is a base class for layouts that contain **a single item** that automatically expands to fill the layout's
17 * container. This class is intended to be extended or created via the `layout: 'fit'`
18 * {@link Ext.container.Container#layout} config, and should generally not need to be created directly via the new keyword.
20 * Fit layout does not have any direct config options (other than inherited ones). To fit a panel to a container using
21 * Fit layout, simply set `layout: 'fit'` on the container and add a single panel to it. If the container has multiple
22 * panels, only the first one will be displayed.
25 * Ext.create('Ext.panel.Panel', {
26 * title: 'Fit Layout',
31 * title: 'Inner Panel',
32 * html: 'This is the inner panel content',
36 * renderTo: Ext.getBody()
39 Ext.define('Ext.layout.container.Fit', {
41 /* Begin Definitions */
43 extend: 'Ext.layout.container.AbstractFit',
45 alternateClassName: 'Ext.layout.FitLayout',
46 requires: ['Ext.layout.container.Box'],
51 * @cfg {Object} defaultMargins
52 * <p>If the individual contained items do not have a <tt>margins</tt>
53 * property specified or margin specified via CSS, the default margins from this property will be
54 * applied to each item.</p>
55 * <br><p>This property may be specified as an object containing margins
56 * to apply in the format:</p><pre><code>
59 right: (right margin),
60 bottom: (bottom margin),
63 * <p>This property may also be specified as a string containing
64 * space-separated, numeric margin values. The order of the sides associated
65 * with each value matches the way CSS processes margin values:</p>
66 * <div class="mdetail-params"><ul>
67 * <li>If there is only one value, it applies to all sides.</li>
68 * <li>If there are two values, the top and bottom borders are set to the
69 * first value and the right and left are set to the second.</li>
70 * <li>If there are three values, the top is set to the first value, the left
71 * and right are set to the second, and the bottom is set to the third.</li>
72 * <li>If there are four values, they apply to the top, right, bottom, and
73 * left, respectively.</li>
75 * <p>Defaults to:</p><pre><code>
76 * {top:0, right:0, bottom:0, left:0}
87 onLayout : function() {
94 if (me.owner.items.length) {
95 item = me.owner.items.get(0);
96 margins = item.margins || me.defaultMargins;
97 size = me.getLayoutTargetSize();
98 size.width -= margins.width;
99 size.height -= margins.height;
100 me.setItemBox(item, size);
102 // If any margins were configure either through the margins config, or in the CSS style,
103 // Then positioning will be used.
104 if (margins.left || margins.top) {
105 item.setPosition(margins.left, margins.top);
110 getTargetBox : function() {
111 return this.getLayoutTargetSize();
114 setItemBox : function(item, box) {
116 if (item && box.height > 0) {
117 if (!me.owner.isFixedWidth()) {
118 box.width = undefined;
120 if (!me.owner.isFixedHeight()) {
121 box.height = undefined;
123 me.setItemSize(item, box.width, box.height);
127 configureItem: function(item) {
129 // Card layout only controls dimensions which IT has controlled.
130 // That calculation has to be determined at run time by examining the ownerCt's isFixedWidth()/isFixedHeight() methods
131 item.layoutManagedHeight = 0;
132 item.layoutManagedWidth = 0;
134 this.callParent(arguments);
137 // Use Box layout's renderItem which reads CSS margins, and adds them to any configured item margins
138 // (Defaulting to "0 0 0 0")
139 this.prototype.renderItem = Ext.layout.container.Box.prototype.renderItem;