OSDN Git Service

fa9dbd22fe4f40540353cb381a99e7544a1873b8
[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             contentW, contentH, autoW, autoH, detectionPhase;\r
26 \r
27                 data.preMesure( w, h );\r
28                 \r
29                 contentW       = data.contentWidth;\r
30                 contentH       = data.contentHeight;\r
31                 autoW          = contentW === X.UI.Attr.AUTO;\r
32                 autoH          = contentH === X.UI.Attr.AUTO;\r
33                 detectionPhase = autoW || autoH;\r
34                 _x             = data.contentL;\r
35                 _y             = data.contentT;\r
36                 childW         = _AbstractUINode.calcValue( attrs[ data.supportAttrs.childWidth.No ], contentW );\r
37                 childH         = _AbstractUINode.calcValue( attrs[ data.supportAttrs.childHeight.No ], contentH );\r
38                 gapX           = _AbstractUINode.calcValue( attrs[ data.supportAttrs.gapX.No ], contentW );\r
39 \r
40                 if( l ){\r
41                         _h = 0;\r
42                         for( i = 0; i < l; ++i ){\r
43                                 node = uinodes[ i ];\r
44                                 node.calculate( detectionPhase, _x, _y, childW, childH );\r
45                                 _x += node.boxWidth + gapX;\r
46                                 if( autoH ){\r
47                                         h = node.boxHeight !== X.UI.Attr.AUTO ?\r
48                                                         node.boxHeight :\r
49                                                 node.minBoxHeight !== X.UI.Attr.AUTO ?\r
50                                                         node.minBoxHeight : 0;\r
51                                         if( _h < h ) _h = h;                            \r
52                                 };\r
53                         };\r
54                         _x -= gapX;\r
55                 } else {\r
56                         _h = data.minContentHeight !== X.UI.Attr.AUTO ? data.minContentHeight : 0;\r
57                 };\r
58 \r
59                 if( detectionPhase ){\r
60                         if( autoW ) data.contentWidth  = _x;\r
61                         if( autoH ) data.contentHeight = _h;\r
62                         data.postMesure();\r
63                 } else {\r
64                         //data.postMesure();\r
65                 };\r
66                 \r
67                 !isNeedsDetection && data.updateLayout( x, y );\r
68         }\r
69 });\r
70 \r
71 var HBox = Box.presets(\r
72         X.UI.Layout.Horizontal,\r
73         'HBox',\r
74         {\r
75                 gapX : '0.2em'\r
76         }\r
77 );\r