2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.layout.AnchorLayout
\r
11 * @extends Ext.layout.ContainerLayout
\r
12 * <p>This is a layout that enables anchoring of contained elements relative to the container's dimensions. If
\r
13 * the container is resized, all anchored items are automatically rerendered according to their anchor rules.
\r
14 * This class is intended to be extended or created via the layout:'anchor' {@link Ext.Container#layout} config,
\r
15 * and should generally not need to be created directly via the new keyword.</p>
\r
16 * <p>AnchorLayout does not have any direct config options (other than inherited ones). However, the container
\r
17 * using the AnchorLayout can supply an anchoring-specific config property of <b>anchorSize</b>. By default,
\r
18 * AnchorLayout will calculate anchor measurements based on the size of the container itself. However, if
\r
19 * anchorSize is specifed, the layout will use it as a virtual container for the purposes of calculating anchor
\r
20 * measurements based on it instead, allowing the container to be sized independently of the anchoring logic if necessary.</p>
\r
21 * <p>The items added to an AnchorLayout can also supply an anchoring-specific config property of <b>anchor</b> which
\r
22 * is a string containing two values: the horizontal anchor value and the vertical anchor value (for example, '100% 50%').
\r
23 * This value is what tells the layout how the item should be anchored to the container. The following types of
\r
24 * anchor values are supported:
\r
26 * <li><b>Percentage</b>: Any value between 1 and 100, expressed as a percentage. The first anchor is the percentage
\r
27 * width that the item should take up within the container, and the second is the percentage height. Example: '100% 50%'
\r
28 * would render an item the complete width of the container and 1/2 its height. If only one anchor value is supplied
\r
29 * it is assumed to be the width value and the height will default to auto.</li>
\r
30 * <li><b>Offsets</b>: Any positive or negative integer value. The first anchor is the offset from the right edge of
\r
31 * the container, and the second is the offset from the bottom edge. Example: '-50 -100' would render an item the
\r
32 * complete width of the container minus 50 pixels and the complete height minus 100 pixels. If only one anchor value
\r
33 * is supplied it is assumed to be the right offset value and the bottom offset will default to 0.</li>
\r
34 * <li><b>Sides</b>: Valid values are 'right' (or 'r') and 'bottom' (or 'b'). Either the container must have a fixed
\r
35 * size or an anchorSize config value defined at render time in order for these to have any effect.</li>
\r
37 * <p>Anchor values can also be mixed as needed. For example, '-50 75%' would render the width offset from the
\r
38 * container right edge by 50 pixels and 75% of the container's height.</p>
\r
40 Ext.layout.AnchorLayout = Ext.extend(Ext.layout.ContainerLayout, {
\r
45 getAnchorViewSize : function(ct, target){
\r
46 return target.dom == document.body ?
\r
47 target.getViewSize() : target.getStyleSize();
\r
51 onLayout : function(ct, target){
\r
52 Ext.layout.AnchorLayout.superclass.onLayout.call(this, ct, target);
\r
54 var size = this.getAnchorViewSize(ct, target);
\r
56 var w = size.width, h = size.height;
\r
58 if(w < 20 || h < 20){
\r
62 // find the container anchoring size
\r
65 if(typeof ct.anchorSize == 'number'){
\r
68 aw = ct.anchorSize.width;
\r
69 ah = ct.anchorSize.height;
\r
72 aw = ct.initialConfig.width;
\r
73 ah = ct.initialConfig.height;
\r
76 var cs = ct.items.items, len = cs.length, i, c, a, cw, ch;
\r
77 for(i = 0; i < len; i++){
\r
81 if(!a){ // cache all anchor values
\r
82 var vs = c.anchor.split(' ');
\r
83 c.anchorSpec = a = {
\r
84 right: this.parseAnchor(vs[0], c.initialConfig.width, aw),
\r
85 bottom: this.parseAnchor(vs[1], c.initialConfig.height, ah)
\r
88 cw = a.right ? this.adjustWidthAnchor(a.right(w), c) : undefined;
\r
89 ch = a.bottom ? this.adjustHeightAnchor(a.bottom(h), c) : undefined;
\r
92 c.setSize(cw || undefined, ch || undefined);
\r
99 parseAnchor : function(a, start, cstart){
\r
100 if(a && a != 'none'){
\r
102 if(/^(r|right|b|bottom)$/i.test(a)){ // standard anchor
\r
103 var diff = cstart - start;
\r
104 return function(v){
\r
110 }else if(a.indexOf('%') != -1){
\r
111 var ratio = parseFloat(a.replace('%', ''))*.01; // percentage
\r
112 return function(v){
\r
115 return Math.floor(v*ratio);
\r
119 a = parseInt(a, 10);
\r
120 if(!isNaN(a)){ // simple offset adjustment
\r
121 return function(v){
\r
134 adjustWidthAnchor : function(value, comp){
\r
139 adjustHeightAnchor : function(value, comp){
\r
144 * @property activeItem
\r
148 Ext.Container.LAYOUTS['anchor'] = Ext.layout.AnchorLayout;