1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-layout.container.Anchor'>/**
2 </span> * @class Ext.layout.container.Anchor
3 * @extends Ext.layout.container.Container
5 * This is a layout that enables anchoring of contained elements relative to the container's dimensions.
6 * If the container is resized, all anchored items are automatically rerendered according to their
7 * <b><tt>{@link #anchor}</tt></b> rules.
9 * This class is intended to be extended or created via the layout: 'anchor' {@link Ext.layout.container.AbstractContainer#layout}
10 * config, and should generally not need to be created directly via the new keyword.</p>
12 * AnchorLayout does not have any direct config options (other than inherited ones). By default,
13 * AnchorLayout will calculate anchor measurements based on the size of the container itself. However, the
14 * container using the AnchorLayout can supply an anchoring-specific config property of <b>anchorSize</b>.
15 * If anchorSize is specifed, the layout will use it as a virtual container for the purposes of calculating
16 * anchor measurements based on it instead, allowing the container to be sized independently of the anchoring
19 * {@img Ext.layout.container.Anchor/Ext.layout.container.Anchor.png Ext.layout.container.Anchor container layout}
22 * Ext.create('Ext.Panel', {
25 * title: "AnchorLayout Panel",
27 * renderTo: Ext.getBody(),
30 * title: '75% Width and 20% Height',
34 * title: 'Offset -300 Width & -200 Height',
38 * title: 'Mixed Offset and Percent',
44 Ext.define('Ext.layout.container.Anchor', {
46 /* Begin Definitions */
48 alias: 'layout.anchor',
49 extend: 'Ext.layout.container.Container',
50 alternateClassName: 'Ext.layout.AnchorLayout',
54 <span id='Ext-layout.container.Anchor-cfg-anchor'> /**
55 </span> * @cfg {String} anchor
56 * <p>This configuation option is to be applied to <b>child <tt>items</tt></b> of a container managed by
57 * this layout (ie. configured with <tt>layout:'anchor'</tt>).</p><br/>
59 * <p>This value is what tells the layout how an item should be anchored to the container. <tt>items</tt>
60 * added to an AnchorLayout accept an anchoring-specific config property of <b>anchor</b> which is a string
61 * containing two values: the horizontal anchor value and the vertical anchor value (for example, '100% 50%').
62 * The following types of anchor values are supported:<div class="mdetail-params"><ul>
64 * <li><b>Percentage</b> : Any value between 1 and 100, expressed as a percentage.<div class="sub-desc">
65 * The first anchor is the percentage width that the item should take up within the container, and the
66 * second is the percentage height. For example:<pre><code>
67 // two values specified
68 anchor: '100% 50%' // render item complete width of the container and
69 // 1/2 height of the container
70 // one value specified
71 anchor: '100%' // the width value; the height will default to auto
72 * </code></pre></div></li>
74 * <li><b>Offsets</b> : Any positive or negative integer value.<div class="sub-desc">
75 * This is a raw adjustment where the first anchor is the offset from the right edge of the container,
76 * and the second is the offset from the bottom edge. For example:<pre><code>
77 // two values specified
78 anchor: '-50 -100' // render item the complete width of the container
79 // minus 50 pixels and
80 // the complete height minus 100 pixels.
81 // one value specified
82 anchor: '-50' // anchor value is assumed to be the right offset value
83 // bottom offset will default to 0
84 * </code></pre></div></li>
86 * <li><b>Sides</b> : Valid values are <tt>'right'</tt> (or <tt>'r'</tt>) and <tt>'bottom'</tt>
87 * (or <tt>'b'</tt>).<div class="sub-desc">
88 * Either the container must have a fixed size or an anchorSize config value defined at render time in
89 * order for these to have any effect.</div></li>
91 * <li><b>Mixed</b> : <div class="sub-desc">
92 * Anchor values can also be mixed as needed. For example, to render the width offset from the container
93 * right edge by 50 pixels and 75% of the container's height use:
94 * <pre><code>
96 * </code></pre></div></li>
99 * </ul></div>
104 <span id='Ext-layout.container.Anchor-cfg-defaultAnchor'> /**
105 </span> * @cfg {String} defaultAnchor
107 * default anchor for all child container items applied if no anchor or specific width is set on the child item. Defaults to '100%'.
110 defaultAnchor: '100%',
112 parseAnchorRE: /^(r|right|b|bottom)$/i,
115 onLayout: function() {
116 this.callParent(arguments);
119 size = me.getLayoutTargetSize(),
121 target = me.getTarget(),
122 ownerWidth = size.width,
123 ownerHeight = size.height,
124 overflow = target.getStyle('overflow'),
125 components = me.getVisibleItems(owner),
126 len = components.length,
128 box, newTargetSize, anchorWidth, anchorHeight, component, anchorSpec, calcWidth, calcHeight,
129 anchorsArray, anchor, i, el;
131 if (ownerWidth < 20 && ownerHeight < 20) {
135 // Anchor layout uses natural HTML flow to arrange the child items.
136 // To ensure that all browsers (I'm looking at you IE!) add the bottom margin of the last child to the
137 // containing element height, we create a zero-sized element with style clear:both to force a "new line"
139 me.clearEl = target.createChild({
140 cls: Ext.baseCSSPrefix + 'clear',
145 // find the container anchoring size
146 if (owner.anchorSize) {
147 if (typeof owner.anchorSize == 'number') {
148 anchorWidth = owner.anchorSize;
151 anchorWidth = owner.anchorSize.width;
152 anchorHeight = owner.anchorSize.height;
156 anchorWidth = owner.initialConfig.width;
157 anchorHeight = owner.initialConfig.height;
160 // Work around WebKit RightMargin bug. We're going to inline-block all the children only ONCE and remove it when we're done
161 if (!Ext.supports.RightMargin) {
162 target.addCls(Ext.baseCSSPrefix + 'inline-children');
165 for (i = 0; i < len; i++) {
166 component = components[i];
168 anchor = component.anchor;
170 if (!component.anchor && component.items && !Ext.isNumber(component.width) && !(Ext.isIE6 && Ext.isStrict)) {
171 component.anchor = anchor = me.defaultAnchor;
175 anchorSpec = component.anchorSpec;
176 // cache all anchor values
178 anchorsArray = anchor.split(' ');
179 component.anchorSpec = anchorSpec = {
180 right: me.parseAnchor(anchorsArray[0], component.initialConfig.width, anchorWidth),
181 bottom: me.parseAnchor(anchorsArray[1], component.initialConfig.height, anchorHeight)
184 calcWidth = anchorSpec.right ? me.adjustWidthAnchor(anchorSpec.right(ownerWidth) - el.getMargin('lr'), component) : undefined;
185 calcHeight = anchorSpec.bottom ? me.adjustHeightAnchor(anchorSpec.bottom(ownerHeight) - el.getMargin('tb'), component) : undefined;
188 component: component,
190 width: calcWidth || undefined,
191 height: calcHeight || undefined
195 component: component,
201 // Work around WebKit RightMargin bug. We're going to inline-block all the children only ONCE and remove it when we're done
202 if (!Ext.supports.RightMargin) {
203 target.removeCls(Ext.baseCSSPrefix + 'inline-children');
206 for (i = 0; i < len; i++) {
208 me.setItemSize(box.component, box.width, box.height);
211 if (overflow && overflow != 'hidden' && !me.adjustmentPass) {
212 newTargetSize = me.getLayoutTargetSize();
213 if (newTargetSize.width != size.width || newTargetSize.height != size.height) {
214 me.adjustmentPass = true;
219 delete me.adjustmentPass;
223 parseAnchor: function(a, start, cstart) {
224 if (a && a != 'none') {
227 if (this.parseAnchorRE.test(a)) {
228 var diff = cstart - start;
234 else if (a.indexOf('%') != -1) {
235 ratio = parseFloat(a.replace('%', '')) * 0.01;
237 return Math.floor(v * ratio);
240 // simple offset adjustment
254 adjustWidthAnchor: function(value, comp) {
259 adjustHeightAnchor: function(value, comp) {
263 });</pre></pre></body></html>