OSDN Git Service

Version 0.6.138, working X.UI.ScrollBox!, fix Node.prev & Node.next.
[pettanr/clientJs.git] / 0.6.x / js / 20_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                 width       : [ '100%',         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                 height      : [ 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                 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
10                 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
11                 gapX        : [ 0,              X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH ]\r
12         },\r
13         \r
14         overrideAttrsForChild : {\r
15                 left   : false,\r
16                 right  : false,\r
17                 top    : true,\r
18                 bottom : true\r
19         },\r
20         \r
21         calculate : function( data, isNeedsDetection, x, y, w, h ){\r
22                 var ret     = isNeedsDetection,\r
23                         attrs   = data.attrObject || data.attrClass.prototype,\r
24                         uinodes = data.uinodes,\r
25                         l       = uinodes && uinodes.length,\r
26                         i,\r
27             contentW, contentH, autoW, autoH, detectionPhase, gapX,             \r
28                         childW, childH, _x, _y, _h, node, minFlag;\r
29 \r
30                 data.preMesure( w, h );\r
31                 \r
32                 contentW       = data.contentWidth;\r
33                 contentH       = data.contentHeight;\r
34                 autoW          = contentW === X.UI.Attr.AUTO;\r
35                 autoH          = contentH === X.UI.Attr.AUTO;\r
36                 detectionPhase = autoW || autoH;\r
37                 gapX           = XUI_AbstractUINode_calcValue( attrs[ data.supportAttrs.gapX.No ], contentW );\r
38                 childW         = XUI_AbstractUINode_calcValue( attrs[ data.supportAttrs.childWidth.No ], contentW );\r
39                 childH         = XUI_AbstractUINode_calcValue( attrs[ data.supportAttrs.childHeight.No ], contentH );\r
40                 _x             = data.contentL;\r
41                 _y             = data.contentT;         \r
42 \r
43                 if( !detectionPhase ) ret = false;\r
44 \r
45                 if( l ){\r
46                         _h = 0;\r
47                         for( i = 0; i < l; ++i ){\r
48                                 node = uinodes[ i ];\r
49                                 node.calculate( detectionPhase, _x, _y, childW, childH );\r
50                                 _x += node.boxWidth + gapX;\r
51                                 if( autoH ){\r
52                                         if( node.boxHeight !== X.UI.Attr.AUTO ){\r
53                                                 h = node.boxHeight;\r
54                                         } else\r
55                                         if( node.minBoxHeight !== X.UI.Attr.AUTO ){\r
56                                                 h = node.minBoxHeight;\r
57                                                 minFlag = true;\r
58                                         } else {\r
59                                                 h = 0;\r
60                                         };\r
61                                         if( _h < h ) _h = h;                            \r
62                                 };\r
63                         };\r
64                         _x -= gapX;\r
65                 } else {\r
66                         _h = data.minContentHeight !== X.UI.Attr.AUTO ? data.minContentHeight : 0;\r
67                 };\r
68 \r
69                 if( detectionPhase ){\r
70                         if( autoW ) data.contentWidth  = _x;\r
71                         if( autoH ) data.contentHeight = _h;\r
72                         _x = data.contentL;\r
73                         for( i = 0; i < l; ++i ){\r
74                                 node = uinodes[ i ];\r
75                                 node.calculate( false, _x, _y, data.contentWidth, data.contentHeight );\r
76                                 _x += node.boxWidth + gapX;\r
77                         };\r
78                         data.postMesure();\r
79                 };\r
80                 \r
81                 !isNeedsDetection && data.updateLayout( x + data.boxX, y + data.boxY );\r
82                 \r
83                 return !ret;\r
84         }\r
85 });\r
86 \r
87 X.UI.HBox = X.UI.Box.presets(\r
88         X.UI.Layout.Horizontal,\r
89         'HBox',\r
90         {\r
91                 gapX : '0.2em'\r
92         }\r
93 );\r