X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2Fui%2F13_TileBox.js;fp=0.6.x%2Fjs%2Fui%2F13_TileBox.js;h=0283fe98540460afc6f0277478a28caaf9225240;hb=d4a9a51a78712817a3a4bbfd9a09e9ddccc9aaf0;hp=9887b26c14738baad3f134fa6fce9cc70c734b34;hpb=d3e186b4a3ed6c6fd23c121d8fafae494c05799d;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/ui/13_TileBox.js b/0.6.x/js/ui/13_TileBox.js index 9887b26..0283fe9 100644 --- a/0.6.x/js/ui/13_TileBox.js +++ b/0.6.x/js/ui/13_TileBox.js @@ -1,56 +1,85 @@ -var TileLayoutManager = ( new LayoutManagerBase() ).define( { - allowForSelf : { - childW : true, - childH : true, - gapX : true, - gapY : true, - padding : true +X.UI.Layout.Tile = X.UI.Layout.create( { + name : 'TileLayout', + + overrideAttrsForSelf : { + selectable : false, + role : [ 0, X.UI.Dirty.CLEAN, X.UI.Attr.USER.UINODE, X.UI.Attr.Type.INIT_ONLY | X.UI.Attr.Type.LIST, 'none,chrome,container' ], + childWidth : [ '8em', X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH | X.UI.Attr.Type.PERCENT ], + childHeight : [ '8em', X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH | X.UI.Attr.Type.PERCENT ], + gapX : [ 0, X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH ], + gapY : [ 0, X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH ], + hCenter : [ true, X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.BOOLEAN ], + vCenter : [ true, X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.BOOLEAN ] }, - allowForChild : { - x : false, - y : false, - w : false, - h : false + + overrideAttrsForChild : { + left : false, + right : false, + top : false, + bottom : false, + width : false, + height : false }, - calculate : function( data, x, y, w, h ){ - var nodes = data.nodes, - styleData = data.styleData, - cssObj = styleData._cssObj, - childW = cssObj.childW, - childH = cssObj.childH, - gapX = cssObj.gapX, - gapY = cssObj.gapY, - padding = cssObj.padding, - _x = padding, - _y = padding, - i = 0, l = nodes.length, node; - if( l === 0 ){ - styleData.layout( x, y, w, 0 ); - return; - }; - for( ; i < l; ++i ){ - node = nodes[ i ]; - if( node.instanceOf( _Box ) ){ - node.calculate( _x, _y, childW, childH ); - } else { - node.styleData.layout( _x, _y, childW, childH ); - }; - _x += childW + gapX; - if( w < _x ){ - _y += childH + gapY; + + calculate : function( data, isNeedsDetection, x, y, w, h ){ + var attrs = data.attrObject || data.attrClass.prototype, + gapX, gapY, childW, childH, + uinodes, l, i, node, + _x, _y, _w, _h, numH, numV, n, startX, __x, __y; + + data.preMesure( w, h ); + + if( isNeedsDetection && ( data.boxWidth === X.UI.Attr.AUTO || data.boxHeight === X.UI.Attr.AUTO ) ) return; + + if( ( uinodes = data.uinodes ) && ( l = uinodes.length ) ){ + _x = data.contentL; + _y = data.contentT; + _w = data.contentWidth; + gapX = _AbstractUINode.calcValue( attrs[ data.supportAttrs.gapX.No ], contentW ); + gapY = _AbstractUINode.calcValue( attrs[ data.supportAttrs.gapY.No ], contentH ); + childW = _AbstractUINode.calcValue( attrs[ data.supportAttrs.childWidth.No ], contentW ); + childH = _AbstractUINode.calcValue( attrs[ data.supportAttrs.childHeight.No ], contentH ); + numH = X.UI.Attr.FLOOR( ( _w + gapX ) / ( childW + gapX ) ); + numV = l % numH ? X.UI.Attr.FLOOR( l / numH ) + 1 : l / numH; + _h = _y + data.contentB + ( childH + gapY ) * numH - gapY; + + startX = attrs[ data.supportAttrs.hCenter.No ] ? + ( _w - ( childW + gapX ) * numH - gapX ) / 2 : _x; + __x = startX; + __y = attrs[ data.supportAttrs.vCenter.No ] && _h <= h ? + ( h - _h ) / 2 + _y : _y; + + for( i = 0; i < l; ++i ){ + node = uinodes[ i ]; + node.calculate( false, __x, __y, childW, childH ); + + if( i % numH === numH - 1 ){ + __x = startX; + __y += childH + gapY; + } else { + __x += childW + gapX; + }; }; + + data.contentHeight = _h; + + } else + if( data.contentHeight === X.UI.Attr.AUTO ){ + data.contentHeight = data.minContentHeight !== X.UI.Attr.AUTO ? data.minContentHeight : 0; }; - styleData.layout( x, y, w, _y + childH + padding ); + + data.postMesure(); + data.updateLayout( x, y ); } }); -var TileBox = Box.inherits( +var TileBox = Box.presets( 'TileBox', - X.Class.SUPER_ACCESS, + X.UI.Layout.Tile, { - Constructor : function(){ - this.style = DisplayNodeStyle( this, X.Class._newPrivate( this, TileLayoutManager, arguments ) ); - this.style.addName( 'TileBox' ); - } + gapX : '0.2em', + gapY : '0.2em', + hCenter : true, + vCenter : true } -); \ No newline at end of file +);