OSDN Git Service

c29b0842fd9a9f79678257e478544ee347c6e631
[pettanr/clientJs.git] / 0.6.x / js / ui / 12_HBox.js
1 X.UI.Layout.Horizontal = X.UI.Layout.create( {  \r
2         name : 'HorizontalLayout',\r
3         \r
4         overrideAttrsForSelf : {\r
5                 selectable  : false,\r
6                 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
7                 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
8                 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
9                 gapX        : [ 0,              X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH ]\r
10         },\r
11         \r
12         overrideAttrsForChild : {\r
13                 left   : false,\r
14                 right  : false,\r
15                 top    : true,\r
16                 bottom : true\r
17         },\r
18         \r
19         calculate : function( data, isNeedsDetection, x, y, w, h ){\r
20                 var attrs   = data.attrObject || data.attrClass.prototype,\r
21                         uinodes = data.uinodes,\r
22                         l       = uinodes && uinodes.length,            \r
23                         childW, childH, gapX,\r
24                         i, _x, _y, _h, node;\r
25 \r
26                 data.preMesure( w, h );\r
27                 \r
28                 contentW       = data.contentWidth;\r
29                 contentH       = data.contentHeight;\r
30                 autoW          = contentW === X.UI.Attr.AUTO;\r
31                 autoH          = contentH === X.UI.Attr.AUTO;\r
32                 detectionPhase = autoW || autoH;\r
33                 _x             = data.contentL;\r
34                 _y             = data.contentT;\r
35                 childW         = _AbstractUINode.calcValue( attrs[ data.supportAttrs.childWidth.No ], contentW );\r
36                 childH         = _AbstractUINode.calcValue( attrs[ data.supportAttrs.childHeight.No ], contentH );\r
37                 gapX           = _AbstractUINode.calcValue( attrs[ data.supportAttrs.gapX.No ], contentW );\r
38 \r
39                 if( l ){\r
40                         _h = 0;\r
41                         for( i = 0; i < l; ++i ){\r
42                                 node = uinodes[ i ];\r
43                                 node.calculate( detectionPhase, _x, _y, childW, childH );\r
44                                 _x += node.boxWidth + gapX;\r
45                                 if( autoH ){\r
46                                         h = node.boxHeight !== X.UI.Attr.AUTO ?\r
47                                                         node.boxHeight :\r
48                                                 node.minBoxHeight !== X.UI.Attr.AUTO ?\r
49                                                         node.minBoxHeight : 0;\r
50                                         if( _h < h ) _h = h;                            \r
51                                 };\r
52                         };\r
53                         _x -= gapX;\r
54                 } else {\r
55                         _h = data.minContentHeight !== X.UI.Attr.AUTO ? data.minContentHeight : 0;\r
56                 };\r
57 \r
58                 if( detectionPhase ){\r
59                         if( autoW ) data.contentWidth  = _x;\r
60                         if( autoH ) data.contentHeight = _h;\r
61                         data.postMesure();\r
62                 } else {\r
63                         //data.postMesure();\r
64                 };\r
65                 \r
66                 !isNeedsDetection && data.updateLayout( x, y );\r
67         }\r
68 });\r
69 \r
70 var HBox = Box.presets(\r
71         X.UI.Layout.Horizontal,\r
72         'HBox',\r
73         {\r
74                 gapX : '0.2em'\r
75         }\r
76 );\r