OSDN Git Service

Version 0.6.58, X.UI.HBox is working.
[pettanr/clientJs.git] / 0.6.x / js / ui / 12_HBox.js
index 07056ee..0fea3ea 100644 (file)
@@ -1,74 +1,91 @@
-var HorizontalLayoutManager = ( new LayoutManagerBase() ).define( {\r
-       allowForSelf : {\r
-               childX  : false,\r
-               childY  : false,\r
-               childW  : true,\r
-               childH  : true,\r
-               gapX    : true,\r
-               gapY    : false,\r
-               padding : true\r
+X.UI.Layout.Horizontal = X.UI.Layout.create( { \r
+       name : 'HorizontalLayout',\r
+       \r
+       overrideAttrsForSelf : {\r
+               selectable  : false,\r
+               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' ],\r
+               childWidth  : [ X.UI.Attr.AUTO, X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH | X.UI.Attr.Type.PERCENT | X.UI.Attr.Type.AUTO ],\r
+               childHeight : [ X.UI.Attr.AUTO, X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH | X.UI.Attr.Type.PERCENT | X.UI.Attr.Type.AUTO ],\r
+               gapX        : [ 0,              X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH ]\r
        },\r
-       allowForChild : {\r
-               x  : false,\r
-               y  : false,\r
-               w  : true,\r
-               h  : true\r
+       \r
+       overrideAttrsForChild : {\r
+               left   : false,\r
+               right  : false,\r
+               top    : true,\r
+               bottom : true\r
        },\r
-       calculate : function( data, x, y, w, h ){\r
-               var nodes     = data.nodes,\r
-                       styleData = data.styleData,\r
-                       cssObj    = styleData._cssObj,\r
-                       childW    = cssObj.childW,\r
-                       childH    = cssObj.childH,\r
-                       gapX      = cssObj.gapX || 0,\r
-                       gapY      = cssObj.gapY || 0,\r
-                       padding   = cssObj.padding || 0,\r
-                       _x        = padding,\r
-                       _y        = padding,\r
-                       i = 0, l = nodes.length, node;\r
+       \r
+       calculate : function( data, isNeedsDetection, x, y, w, h ){\r
+               var ret     = isNeedsDetection,\r
+                       attrs   = data.attrObject || data.attrClass.prototype,\r
+                       uinodes = data.uinodes,\r
+                       l       = uinodes && uinodes.length,\r
+                       i,\r
+            contentW, contentH, autoW, autoH, detectionPhase, gapX,            \r
+                       childW, childH, _x, _y, _h, node, minFlag;\r
 \r
-               if( childW || childW === 0 ){\r
-                       for( ; i < l; ++i ){\r
-                               node = nodes[ i ];\r
-                               if( node.instanceOf( _AbstractDisplayContainer ) ){\r
-                                       node.calculate( _x, NaN, childW, childH );\r
-                               } else {\r
-                                       node.styleData.layout( _x, NaN, childW, childH );\r
+               data.preMesure( w, h );\r
+               \r
+               contentW       = data.contentWidth;\r
+               contentH       = data.contentHeight;\r
+               autoW          = contentW === X.UI.Attr.AUTO;\r
+               autoH          = contentH === X.UI.Attr.AUTO;\r
+               detectionPhase = autoW || autoH;\r
+               gapX           = X.UI._AbstractUINode.calcValue( attrs[ data.supportAttrs.gapX.No ], contentW );\r
+               childW         = X.UI._AbstractUINode.calcValue( attrs[ data.supportAttrs.childWidth.No ], contentW );\r
+               childH         = X.UI._AbstractUINode.calcValue( attrs[ data.supportAttrs.childHeight.No ], contentH );\r
+               _x             = data.contentL;\r
+               _y             = data.contentT;         \r
+\r
+               if( !detectionPhase ) ret = false;\r
+\r
+               if( l ){\r
+                       _h = 0;\r
+                       for( i = 0; i < l; ++i ){\r
+                               node = uinodes[ i ];\r
+                               node.calculate( detectionPhase, _x, _y, childW, childH );\r
+                               _x += node.boxWidth + gapX;\r
+                               if( autoH ){\r
+                                       if( node.boxHeight !== X.UI.Attr.AUTO ){\r
+                                               h = node.boxHeight;\r
+                                       } else\r
+                                       if( node.minBoxHeight !== X.UI.Attr.AUTO ){\r
+                                               h = node.minBoxHeight;\r
+                                               minFlag = true;\r
+                                       } else {\r
+                                               h = 0;\r
+                                       };\r
+                                       if( _h < h ) _h = h;                            \r
                                };\r
-                               _x += childW + gapX;\r
                        };\r
+                       _x -= gapX;\r
                } else {\r
-                       for( ; i < l; ++i ){\r
-                               node = nodes[ i ];\r
-                               if( node.instanceOf( _AbstractDisplayContainer ) ){\r
-                                       node.calculate( _x, NaN, NaN, childH );\r
-                               } else {\r
-                                       node.styleData.layout( _x, NaN, NaN, childH );\r
-                               };\r
-                               //_x += node.rawElement.offsetWidth + gapX;\r
-                               _x += node.rawElement.width() + gapX;\r
+                       _h = data.minContentHeight !== X.UI.Attr.AUTO ? data.minContentHeight : 0;\r
+               };\r
+\r
+               if( detectionPhase ){\r
+                       if( autoW ) data.contentWidth  = _x;\r
+                       if( autoH ) data.contentHeight = _h;\r
+                       _x = data.contentL;\r
+                       for( i = 0; i < l; ++i ){\r
+                               node = uinodes[ i ];\r
+                               node.calculate( false, _x, _y, data.contentWidth, data.contentHeight );\r
+                               _x += node.boxWidth + gapX;\r
                        };\r
+                       data.postMesure();\r
                };\r
-               data.styleData.layout( x, y, w, h );\r
+               \r
+               !isNeedsDetection && data.updateLayout( x + data.boxX, y + data.boxY );\r
+               \r
+               return !ret;\r
        }\r
 });\r
 \r
-/*\r
-var HBox = function(){\r
-       var arg = arguments;\r
-       arg[ arg.length ] = HorizontalLayoutManager;\r
-       ++arg.length;\r
-       return Box.apply( null, arg );\r
-}; */\r
-\r
-\r
-var HBox = AbstractDisplayContainer.inherits(\r
+X.UI.HBox = X.UI.Box.presets(\r
+       X.UI.Layout.Horizontal,\r
        'HBox',\r
-       X.Class.SUPER_ACCESS,\r
        {\r
-               Constructor : function(){\r
-                       this.style = DisplayNodeStyle( this, X.Class._newPrivate( this,  HorizontalLayoutManager, arguments ) );\r
-                       this.style.addName( 'HBox' );\r
-               }\r
+               gapX : '0.2em'\r
        }\r
-);
\ No newline at end of file
+);\r