4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-layout-container-Fit'>/**
19 </span> * This is a base class for layouts that contain **a single item** that automatically expands to fill the layout's
20 * container. This class is intended to be extended or created via the `layout: 'fit'`
21 * {@link Ext.container.Container#layout} config, and should generally not need to be created directly via the new keyword.
23 * Fit layout does not have any direct config options (other than inherited ones). To fit a panel to a container using
24 * Fit layout, simply set `layout: 'fit'` on the container and add a single panel to it. If the container has multiple
25 * panels, only the first one will be displayed.
28 * Ext.create('Ext.panel.Panel', {
29 * title: 'Fit Layout',
34 * title: 'Inner Panel',
35 * html: 'This is the inner panel content',
39 * renderTo: Ext.getBody()
42 Ext.define('Ext.layout.container.Fit', {
44 /* Begin Definitions */
46 extend: 'Ext.layout.container.AbstractFit',
48 alternateClassName: 'Ext.layout.FitLayout',
49 requires: ['Ext.layout.container.Box'],
53 <span id='Ext-layout-container-Fit-cfg-defaultMargins'> /**
54 </span> * @cfg {Object} defaultMargins
55 * <p>If the individual contained items do not have a <tt>margins</tt>
56 * property specified or margin specified via CSS, the default margins from this property will be
57 * applied to each item.</p>
58 * <br><p>This property may be specified as an object containing margins
59 * to apply in the format:</p><pre><code>
62 right: (right margin),
63 bottom: (bottom margin),
65 }</code></pre>
66 * <p>This property may also be specified as a string containing
67 * space-separated, numeric margin values. The order of the sides associated
68 * with each value matches the way CSS processes margin values:</p>
69 * <div class="mdetail-params"><ul>
70 * <li>If there is only one value, it applies to all sides.</li>
71 * <li>If there are two values, the top and bottom borders are set to the
72 * first value and the right and left are set to the second.</li>
73 * <li>If there are three values, the top is set to the first value, the left
74 * and right are set to the second, and the bottom is set to the third.</li>
75 * <li>If there are four values, they apply to the top, right, bottom, and
76 * left, respectively.</li>
77 * </ul></div>
78 * <p>Defaults to:</p><pre><code>
79 * {top:0, right:0, bottom:0, left:0}
80 * </code></pre>
90 onLayout : function() {
97 if (me.owner.items.length) {
98 item = me.owner.items.get(0);
99 margins = item.margins || me.defaultMargins;
100 size = me.getLayoutTargetSize();
101 size.width -= margins.width;
102 size.height -= margins.height;
103 me.setItemBox(item, size);
105 // If any margins were configure either through the margins config, or in the CSS style,
106 // Then positioning will be used.
107 if (margins.left || margins.top) {
108 item.setPosition(margins.left, margins.top);
113 getTargetBox : function() {
114 return this.getLayoutTargetSize();
117 setItemBox : function(item, box) {
119 if (item && box.height > 0) {
120 if (!me.owner.isFixedWidth()) {
121 box.width = undefined;
123 if (!me.owner.isFixedHeight()) {
124 box.height = undefined;
126 me.setItemSize(item, box.width, box.height);
130 configureItem: function(item) {
132 // Card layout only controls dimensions which IT has controlled.
133 // That calculation has to be determined at run time by examining the ownerCt's isFixedWidth()/isFixedHeight() methods
134 item.layoutManagedHeight = 0;
135 item.layoutManagedWidth = 0;
137 this.callParent(arguments);
140 // Use Box layout's renderItem which reads CSS margins, and adds them to any configured item margins
141 // (Defaulting to "0 0 0 0")
142 this.prototype.renderItem = Ext.layout.container.Box.prototype.renderItem;