OSDN Git Service

Version 0.6.156, add X.UI.Repeater.
[pettanr/clientJs.git] / 0.6.x / js / 20_ui / 15_ScrollBox.js
index 73f62b6..47915ff 100644 (file)
@@ -1,32 +1,5 @@
 \r
 \r
-function X_UI_ScrollBox_momentum( current, start, time, lowerMargin, wrapperSize, deceleration ){\r
-       var distance = current - start,\r
-               speed    = Math.abs( distance ) / time,\r
-               destination,\r
-               duration;\r
-\r
-       deceleration = deceleration === undefined ? 0.0006 : deceleration;\r
-\r
-       destination  = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );\r
-       duration     = speed / deceleration;\r
-\r
-       if( destination < lowerMargin ){\r
-               destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;\r
-               distance    = Math.abs( destination - current );\r
-               duration    = distance / speed;\r
-       } else\r
-       if ( destination > 0 ) {\r
-               destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;\r
-               distance    = Math.abs( current ) + destination;\r
-               duration    = distance / speed;\r
-       };\r
-\r
-       return {\r
-               destination : Math.round( destination ),\r
-               duration    : duration\r
-       };\r
-};\r
 \r
 var X_UI_ScrollBox_SUPPORT_ATTRS = {\r
                // スクロール開始するために必要な移動距離、縦か横、どちらか制限する場合、より重要\r
@@ -35,7 +8,7 @@ var X_UI_ScrollBox_SUPPORT_ATTRS = {
                scrollYEnabled         : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
                scrollEnabled          : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
                bounceEnabled          : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
-               bounceTime             : [    600, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.TIME ],\r
+               bounceTime             : [    300, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.TIME ],\r
                useWheel               : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
                useKey                 : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
                hasScrollShadow        : [   true, XUI_Dirty.CLEAN, XUI_Attr_USER.UINODE, XUI_Attr_Type.BOOLEAN ],\r
@@ -46,6 +19,8 @@ var XUI_ScrollBox = XUI_ChromeBox.inherits(
        '_ScrollBox',\r
        X_Class.NONE,\r
        {\r
+               layout                 : XUI_Layout_Canvas,\r
+               \r
                directionLockThreshold : 10,\r
                scrollXEnabled         : true,\r
                scrollYEnabled         : true,\r
@@ -58,8 +33,6 @@ var XUI_ScrollBox = XUI_ChromeBox.inherits(
                hasScrollShadow        : true,\r
                scrollShadowColor      : '#000',\r
                \r
-               supportAttrs    : XUI_Attr_createAttrDef( XUI_Attr_Support, X_UI_ScrollBox_SUPPORT_ATTRS ),\r
-               \r
                scrolling       : false,\r
                \r
                initiated       : '',\r
@@ -172,12 +145,12 @@ function X_UI_ScrollBox_onLayoutBefore( e ){
 function X_UI_ScrollBox_onLayoutComplete( e ){\r
        // scroll の停止、GPU の解除\r
        var font = this.fontSize = this.xnodeSlider.call( 'fontSize' );\r
-       \r
-       this.scrollXMax = ( this.boxWidth  - this._containerNode.boxWidth )  * font;\r
-       this.scrollYMax = ( this.boxHeight - this._containerNode.boxHeight ) * font;\r
 \r
-       this.hasHScroll = this.scrollXEnabled && this.scrollXMax < 0;\r
-       this.hasVScroll = this.scrollYEnabled && this.scrollYMax < 0;\r
+       this.scrollXMax = ( this.boxWidth  - this._containerNode.boxWidth )  * font | 0;\r
+       this.scrollYMax = ( this.boxHeight - this._containerNode.boxHeight ) * font | 0;\r
+\r
+       this.hasHScroll = this.scrollXEnabled && ( this.scrollXMax < -1 ); // < 0 だと \r
+       this.hasVScroll = this.scrollYEnabled && ( this.scrollYMax < -1 );\r
 \r
        if( !this.hasHScroll ){\r
                this.scrollXMax  = 0;\r
@@ -508,12 +481,48 @@ function X_UI_ScrollBox_onAnimeEnd( e ){
        return X_Callback_NONE;\r
 };\r
 \r
+function X_UI_ScrollBox_momentum( current, start, time, lowerMargin, wrapperSize, deceleration ){\r
+       var distance = current - start,\r
+               speed    = Math.abs( distance ) / time,\r
+               destination,\r
+               duration;\r
+\r
+       deceleration = deceleration === undefined ? 0.0006 : deceleration;\r
+\r
+       destination  = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );\r
+       duration     = speed / deceleration;\r
+\r
+       if( destination < lowerMargin ){\r
+               destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;\r
+               distance    = Math.abs( destination - current );\r
+               duration    = distance / speed;\r
+       } else\r
+       if ( destination > 0 ) {\r
+               destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;\r
+               distance    = Math.abs( current ) + destination;\r
+               duration    = distance / speed;\r
+       };\r
+\r
+       return {\r
+               destination : Math.round( destination ),\r
+               duration    : duration\r
+       };\r
+};\r
+\r
 // TODO Box の継承に!\r
 X.UI.ScrollBox = X.UI.ChromeBox.inherits(\r
        'ScrollBox',\r
        X_Class.NONE,\r
        {\r
                Constructor : function(){\r
+                       var supports, slider;\r
+                       \r
+                       if( XUI_ScrollBox.prototype.usableAttrs === XUI_ChromeBox.prototype.usableAttrs ){\r
+                               XUI_ScrollBox.prototype.usableAttrs = supports = XUI_Attr_createAttrDef( XUI_Attr_Support, X_UI_ScrollBox_SUPPORT_ATTRS );\r
+               \r
+                               XUI_ScrollBox.prototype.attrClass    = XUI_Attr_preset( XUI_Box.prototype.attrClass, supports, { width  : '100%', height : '100%', bgColor : 0x111111 } );\r
+                       };\r
+                       \r
                        var args = [\r
                                                XUI_Layout_Vertical,                    \r
                                                {\r
@@ -526,18 +535,19 @@ X.UI.ScrollBox = X.UI.ChromeBox.inherits(
                                                }\r
                                        ],\r
                                i    = arguments.length,\r
-                               arg, layout, attr;\r
+                               arg, attr;\r
                        \r
                        for( ; i; ){\r
                                arg = arguments[ --i ];\r
                                if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( XUI_LayoutBase ) ){\r
-                                       layout = arg;\r
+                                       args[ 0 ] = arg;\r
                                } else\r
                                if( arg[ 'instanceOf' ] && arg[ 'instanceOf' ]( X.UI.AbstractUINode ) ){\r
                                        args[ args.length ] = arg;\r
                                } else\r
                                if( X_Type_isObject( arg ) ){\r
-                                       attr = arg;\r
+                                       args[ args.length ] = attr = arg;\r
+                                       slider = attr.scrollSlider;\r
                                };\r
                        };\r
                        \r
@@ -545,18 +555,14 @@ X.UI.ScrollBox = X.UI.ChromeBox.inherits(
                                this,\r
                                XUI_ScrollBox(\r
                                        this,\r
-                                       XUI_Layout_Canvas,\r
+                                       null,\r
                                        [\r
-                                               {\r
-                                                       width  : '100%',\r
-                                                       height : '100%'\r
-                                               },\r
-                                               X.UI.VBox.apply( 0, args )\r
+                                               slider || X.UI.VBox.apply( 0, args )\r
                                        ]\r
                                )\r
                        );\r
                        \r
-                       attr && this.attr( attr );\r
+                       //attr && this.attr( attr );\r
                },\r
                scrollX  : function(){\r
                        \r