2
* Ext JS Library 3.0 RC2
3
* Copyright(c) 2006-2009, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.layout.AnchorLayout
11
* @extends Ext.layout.ContainerLayout
12
* <p>This is a layout that enables anchoring of contained elements relative to the container's dimensions.
13
* If the container is resized, all anchored items are automatically rerendered according to their
14
* <b><tt>{@link #anchor}</tt></b> rules.</p>
15
* <p>This class is intended to be extended or created via the layout:'anchor' {@link Ext.Container#layout}
16
* config, and should generally not need to be created directly via the new keyword.</p>
17
* <p>AnchorLayout does not have any direct config options (other than inherited ones). By default,
18
* AnchorLayout will calculate anchor measurements based on the size of the container itself. However, the
19
* container using the AnchorLayout can supply an anchoring-specific config property of <b>anchorSize</b>.
20
* If anchorSize is specifed, the layout will use it as a virtual container for the purposes of calculating
21
* anchor measurements based on it instead, allowing the container to be sized independently of the anchoring
22
* logic if necessary. For example:</p>
24
var viewport = new Ext.Viewport({
26
anchorSize: {width:800, height:600},
46
Ext.layout.AnchorLayout = Ext.extend(Ext.layout.ContainerLayout, {
48
* @cfg {String} anchor
49
* <p>This configuation option is to be applied to <b>child <tt>items</tt></b> of a container managed by
50
* this layout (ie. configured with <tt>layout:'anchor'</tt>).</p><br/>
52
* <p>This value is what tells the layout how an item should be anchored to the container. <tt>items</tt>
53
* added to an AnchorLayout accept an anchoring-specific config property of <b>anchor</b> which is a string
54
* containing two values: the horizontal anchor value and the vertical anchor value (for example, '100% 50%').
55
* The following types of anchor values are supported:<div class="mdetail-params"><ul>
57
* <li><b>Percentage</b> : Any value between 1 and 100, expressed as a percentage.<div class="sub-desc">
58
* The first anchor is the percentage width that the item should take up within the container, and the
59
* second is the percentage height. For example:<pre><code>
60
// two values specified
61
anchor: '100% 50%' // render item complete width of the container and 1/2 its height.
62
// one value specified
63
anchor: '100%' // the width value; the height will default to auto
64
* </code></pre></div></li>
66
* <li><b>Offsets</b> : Any positive or negative integer value.<div class="sub-desc">
67
* This is a raw adjustment where the first anchor is the offset from the right edge of the container,
68
* and the second is the offset from the bottom edge. For example:<pre><code>
69
// two values specified
70
anchor: '-50 -100' // render item the complete width of the container minus 50 pixels and
71
// the complete height minus 100 pixels.
72
// one value specified
73
anchor: '-50' // anchor value is assumed to be the right offset value
74
// bottom offset will default to 0
75
* </code></pre></div></li>
77
* <li><b>Sides</b> : Valid values are <tt>'right'</tt> (or <tt>'r'</tt>) and <tt>'bottom'</tt>
78
* (or <tt>'b'</tt>).<div class="sub-desc">
79
* Either the container must have a fixed size or an anchorSize config value defined at render time in
80
* order for these to have any effect.</div></li>
82
* <li><b>Mixed</b> : <div class="sub-desc">
83
* Anchor values can also be mixed as needed. For example, to render the width offset from the container
84
* right edge by 50 pixels and 75% of the container's height use:
87
* </code></pre></div></li>
97
getAnchorViewSize : function(ct, target){
98
return target.dom == document.body ?
99
target.getViewSize() : target.getStyleSize();
103
onLayout : function(ct, target){
104
Ext.layout.AnchorLayout.superclass.onLayout.call(this, ct, target);
106
var size = this.getAnchorViewSize(ct, target);
108
var w = size.width, h = size.height;
110
if(w < 20 && h < 20){
114
// find the container anchoring size
117
if(typeof ct.anchorSize == 'number'){
120
aw = ct.anchorSize.width;
121
ah = ct.anchorSize.height;
124
aw = ct.initialConfig.width;
125
ah = ct.initialConfig.height;
128
var cs = ct.items.items, len = cs.length, i, c, a, cw, ch;
129
for(i = 0; i < len; i++){
133
if(!a){ // cache all anchor values
134
var vs = c.anchor.split(' ');
136
right: this.parseAnchor(vs[0], c.initialConfig.width, aw),
137
bottom: this.parseAnchor(vs[1], c.initialConfig.height, ah)
140
cw = a.right ? this.adjustWidthAnchor(a.right(w), c) : undefined;
141
ch = a.bottom ? this.adjustHeightAnchor(a.bottom(h), c) : undefined;
144
c.setSize(cw || undefined, ch || undefined);
151
parseAnchor : function(a, start, cstart){
152
if(a && a != 'none'){
154
if(/^(r|right|b|bottom)$/i.test(a)){ // standard anchor
155
var diff = cstart - start;
162
}else if(a.indexOf('%') != -1){
163
var ratio = parseFloat(a.replace('%', ''))*.01; // percentage
167
return Math.floor(v*ratio);
172
if(!isNaN(a)){ // simple offset adjustment
186
adjustWidthAnchor : function(value, comp){
191
adjustHeightAnchor : function(value, comp){
196
* @property activeItem
200
Ext.Container.LAYOUTS['anchor'] = Ext.layout.AnchorLayout;
b'\\ No newline at end of file'