OSDN Git Service

14febc5b92d83e764138cc3cff07d362fae5597c
[pettanr/clientJs.git] / 0.6.x / js / 10_ui / 11_VBox.js
1 X.UI.Layout.Vertical = X.UI.Layout.create( {\r
2         \r
3         name : 'VerticalLayout',\r
4         \r
5         overrideAttrsForSelf : {\r
6                 selectable  : false,\r
7                 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
8                 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
9                 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
10                 gapY        : [ 0,              X.UI.Dirty.LAYOUT, X.UI.Attr.USER.LAYOUT, X.UI.Attr.Type.LENGTH ]\r
11         },\r
12         \r
13         overrideAttrsForChild : {\r
14                 left   : true,\r
15                 right  : true,\r
16                 top    : false,\r
17                 bottom : false\r
18         },\r
19         \r
20         calculate : function( data, isNeedsDetection, x, y, w, h ){\r
21                 var ret     = isNeedsDetection,\r
22                         attrs   = data.attrObject || data.attrClass.prototype,\r
23                         uinodes = data.uinodes,\r
24                         l       = uinodes && uinodes.length,\r
25                         minFlag = false,\r
26                         childW, childH, gapY,\r
27                         i, _x, _y, _w, node,\r
28             contentW, contentH, autoW, autoH, detectionPhase;\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                 gapY           = X.UI._AbstractUINode.calcValue( attrs[ data.supportAttrs.gapY.No ], contentH );\r
38                 childW         = X.UI._AbstractUINode.calcValue( attrs[ data.supportAttrs.childWidth.No ], contentW );\r
39                 childH         = X.UI._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                         _w = 0;\r
47                         for( i = 0; i < l; ++i ){\r
48                                 node = uinodes[ i ];\r
49                                 node.calculate( detectionPhase, _x, _y, contentW, childH );\r
50                                 _y += node.boxHeight + gapY;\r
51                                 // 概算のみ\r
52                                 if( autoW ){\r
53                                         if( node.boxWidth !== X.UI.Attr.AUTO ){\r
54                                                 w = node.boxWidth;\r
55                                         } else\r
56                                         if( node.minBoxWidth !== X.UI.Attr.AUTO ){\r
57                                                 w = node.minBoxWidth;\r
58                                                 minFlag = true;\r
59                                         } else {\r
60                                                 w = 0;\r
61                                         };\r
62                                         if( _w < w ) _w = w;                            \r
63                                 };      \r
64                         };\r
65                         _y -= gapY;\r
66                 } else {\r
67                         _y = data.minContentHeight !== X.UI.Attr.AUTO ? data.minContentHeight : 0;\r
68                 };\r
69 \r
70                 if( detectionPhase ){\r
71                         if( autoW ) data.contentWidth  = _w;\r
72                         if( autoH ) data.contentHeight = _y;\r
73                         _y = data.contentT;\r
74                         for( i = 0; i < l; ++i ){\r
75                                 node = uinodes[ i ];\r
76                                 node.calculate( false, _x, _y, data.contentWidth, data.contentHeight );\r
77                                 _y += node.boxHeight + gapY;\r
78                         };\r
79                         data.postMesure();\r
80                 };\r
81                 \r
82                 !isNeedsDetection && data.updateLayout( x + data.boxX, y + data.boxY );\r
83                 \r
84                 return !ret;\r
85         }\r
86 });\r
87 \r
88 X.UI.VBox = X.UI.Box.presets(\r
89         X.UI.Layout.Vertical,\r
90         'VBox',\r
91         {\r
92                 gapY       : '0.2em',\r
93                 childWidth : '100%'\r
94         }\r
95 );\r