Ext架构分析(6)--最简单的layout:AnchorLayout

 AnchorLayout是最简单的布局管理其,它只是将元素按照配置的属性在元素容器中进行定位。
    让我们看一下它的render方法以理解如果进行布局:
None.gif
ExpandedBlockStart.gifContractedBlock.gif    onLayout : 
function (ct, target) dot.gif {
InBlock.gif    Ext.layout.AnchorLayout.superclass.onLayout.call(
this, ct, target);
InBlock.gif    
//获取元素的尺寸
InBlock.gif
    var size = this.getAnchorViewSize(ct, target);
InBlock.gif    
var w = size.width, h = size.height;
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if(w < 20 || h < 20)dot.gif{
InBlock.gif        
return;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
// 获取容器的尺寸
InBlock.gif
    var aw, ah;
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if(ct.anchorSize)dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if(typeof ct.anchorSize == 'number')dot.gif{
InBlock.gif          aw 
= ct.anchorSize;
ExpandedSubBlockStart.gifContractedSubBlock.gif        }
elsedot.gif{
InBlock.gif          aw 
= ct.anchorSize.width;
InBlock.gif          ah 
= ct.anchorSize.height;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif    }
elsedot.gif{
InBlock.gif    
//根据配置获取容器尺寸
InBlock.gif
        aw = ct.initialConfig.width;
InBlock.gif        ah 
= ct.initialConfig.height;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
//遍历元素,并调用元素的setSize方法,继承自boxComponent的setSize方法则触发resize事件从而触发layout方法。
InBlock.gif
    var cs = ct.items.items, len = cs.length, i, c, a, cw, ch;
ExpandedSubBlockStart.gifContractedSubBlock.gif    
for(i = 0; i < len; i++)dot.gif{
InBlock.gif        c 
= cs;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if(c.anchor)dot.gif{
InBlock.gif          a 
= c.anchorSpec;
ExpandedSubBlockStart.gifContractedSubBlock.gif          
if(!a)dot.gif// cache all anchor values
InBlock.gif
            var vs = c.anchor.split(' ');
ExpandedSubBlockStart.gifContractedSubBlock.gif            c.anchorSpec 
= a = dot.gif{
InBlock.gif                right: 
this.parseAnchor(vs[0], c.initialConfig.width, aw),
InBlock.gif                bottom: 
this.parseAnchor(vs[1], c.initialConfig.height, ah)
ExpandedSubBlockEnd.gif            }
;
ExpandedSubBlockEnd.gif          }

InBlock.gif          cw 
= a.right ? this.adjustWidthAnchor(a.right(w), c) : undefined;
InBlock.gif          ch 
= a.bottom ? this.adjustHeightAnchor(a.bottom(h), c) : undefined;
ExpandedSubBlockStart.gifContractedSubBlock.gif          
if(cw || ch)dot.gif{
InBlock.gif            c.setSize(cw 
|| undefined, ch || undefined);
ExpandedSubBlockEnd.gif          }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif  }
,
None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值