From: Richard Huang Date: Thu, 21 Jan 2016 11:56:43 +0000 (+0000) Subject: JavaScript binding for ScrollView X-Git-Tag: dali_1.1.19~9^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=e47d25c5332ac9ac9e3e90041a4b9012667255ad;ds=sidebyside JavaScript binding for ScrollView This patch includes: 1. ScrollView API binding 2. Documentation for ScrollView JavaScript API 3. JavaScript example for ScrollView 4. Changed the type of built-in animation alpha function from string to enumeration Change-Id: I6482ffd6a0201a1d71258fbb6a53184a4a07e615 --- diff --git a/docs/content/images/scroll-view/scroll-view.png b/docs/content/images/scroll-view/scroll-view.png new file mode 100755 index 0000000..fe2d409 Binary files /dev/null and b/docs/content/images/scroll-view/scroll-view.png differ diff --git a/node-addon/binding.gyp b/node-addon/binding.gyp index 142cc74..ac3b428 100644 --- a/node-addon/binding.gyp +++ b/node-addon/binding.gyp @@ -21,6 +21,7 @@ '<(DALI_JS_DIR)/controls/control-wrapper.cpp', '<(DALI_JS_DIR)/controls/item-factory-wrapper.cpp', '<(DALI_JS_DIR)/controls/item-view-api.cpp', + '<(DALI_JS_DIR)/controls/scroll-view-api.cpp', '<(DALI_JS_DIR)/animation/animation-api.cpp', '<(DALI_JS_DIR)/animation/animation-wrapper.cpp', '<(DALI_JS_DIR)/animation/constrainer-api.cpp', diff --git a/node-addon/build/tizen/CMakeLists.txt b/node-addon/build/tizen/CMakeLists.txt index d418eca..d29846dd 100644 --- a/node-addon/build/tizen/CMakeLists.txt +++ b/node-addon/build/tizen/CMakeLists.txt @@ -59,6 +59,7 @@ add_library(dali_addon SHARED ${PLUGING_SRC_DIR}/controls/control-wrapper.cpp ${PLUGING_SRC_DIR}/controls/item-factory-wrapper.cpp ${PLUGING_SRC_DIR}/controls/item-view-api.cpp + ${PLUGING_SRC_DIR}/controls/scroll-view-api.cpp ${PLUGING_SRC_DIR}/constants/constants-wrapper.cpp ${PLUGING_SRC_DIR}/animation/animation-api.cpp ${PLUGING_SRC_DIR}/animation/animation-wrapper.cpp diff --git a/node-addon/examples/scroll-view.js b/node-addon/examples/scroll-view.js new file mode 100644 index 0000000..d0cf3e5 --- /dev/null +++ b/node-addon/examples/scroll-view.js @@ -0,0 +1,130 @@ + var window= { + x:0, + y:0, + width:1920, + height:1080, + transparent: false, + name:'scrollview-example' + }; + + var viewMode={ + 'stereoscopic-mode':'mono', // stereo-horizontal, stereo-vertical, stereo-interlaced, + 'stereoBase': 65 // Distance in millimeters between left/right cameras typically between (50-70mm) + }; + + var options= { + 'window': window, + 'viewMode': viewMode, + } + +//desktop +//var dali = require('../build/Release/dali')( options ); + +//target +var dali = require('dali')( options ); + +var stageSize; +var scrollView; +var scrollBar; + +var imageDir = "./images/"; + +var daliApp = {}; + +daliApp.createScrollView = function() { + + // Create a scroll view + scrollView = new dali.Control("ScrollView"); + stageSize = dali.stage.getSize(); + scrollView.size = [stageSize.x, stageSize.y, 0.0]; + scrollView.parentOrigin = dali.CENTER; + scrollView.anchorPoint = dali.CENTER; + + dali.stage.add( scrollView ); + + // Add actors to a scroll view with 4 pages + var pageRows = 1; + var pageColumns = 3; + for(var pageRow = 0; pageRow < pageRows; pageRow++) + { + for(var pageColumn = 0; pageColumn < pageColumns; pageColumn++) + { + var pageActor = new dali.Control(); + pageActor.widthResizePolicy = "FILL_TO_PARENT"; + pageActor.heightResizePolicy = "FILL_TO_PARENT"; + pageActor.parentOrigin = dali.CENTER; + pageActor.anchorPoint = dali.CENTER; + pageActor.position = [pageColumn * stageSize.x, pageRow * stageSize.y, 0.0]; + pageActor.name = "pageActor" + pageColumn; + + // Add images in a 5x4 grid layout for each page + var imageRows = 4; + var imageColumns = 5; + var margin = 10.0; + var imageSize = [(stageSize.x / imageColumns) - margin, (stageSize.y / imageRows) - margin, 0.0]; + + for(var row = 0; row < imageRows; row++) + { + for(var column = 0; column < imageColumns;column++) + { + var imageView = new dali.Control("ImageView"); + var imageId = (row * imageColumns + column) % 2 + 1; + imageView.image = imageDir + "image-" + imageId + ".jpg"; + imageView.parentOrigin = dali.CENTER; + imageView.anchorPoint = dali.CENTER; + imageView.size = imageSize; + imageView.position = [ margin * 0.5 + (imageSize[0] + margin) * column - stageSize.x * 0.5 + imageSize[0] * 0.5, + margin * 0.5 + (imageSize[1] + margin) * row - stageSize.y * 0.5 + imageSize[1] * 0.5, + 0.0 ]; + pageActor.add(imageView); + var position = imageView.position; + } + } + + scrollView.add( pageActor ); + } + } + + // Set scroll view to have 3 pages in X axis and allow page snapping, + // and also disable scrolling in Y axis. + var scrollMode = { + xAxisScrollEnabled : true, + xAxisSnapToInterval : stageSize.x, // Define the snap points + xAxisScrollBoundary : stageSize.x * pageColumns, // i.e. Define 3 pages + yAxisScrollEnabled : false + } + + scrollView.setScrollMode(scrollMode); + + // Create a horizontal scroll bar in the bottom of scroll view (optional) + scrollBar = new dali.Control("ScrollBar"); + scrollBar.parentOrigin = dali.BOTTOM_LEFT; + scrollBar.anchorPoint = dali.TOP_LEFT; + scrollBar.widthResizePolicy = "FIT_TO_CHILDREN"; + scrollBar.heightResizePolicy = "FILL_TO_PARENT"; + scrollBar.orientation = [0, 0, 270]; + scrollBar.scrollDirection = "Horizontal"; + scrollView.add(scrollBar); + + // Connect to the onRelayout signal + scrollView.on("onRelayout", daliApp.onScrollViewRelayout); +} + +daliApp.onScrollViewRelayout = function( button ) { + + // Set the correct scroll bar size after size negotiation of scroll view is done + scrollBar.size = [0.0, scrollView.getRelayoutSize(dali.DIMENSION_WIDTH), 0.0 ]; +} + +function startup() +{ + daliApp.init(); +} + +daliApp.init = function() +{ + daliApp.createScrollView(); +} + +startup(); + diff --git a/plugins/dali-script-v8/docs/content/animation.js b/plugins/dali-script-v8/docs/content/animation.js index 54ba7c3..43d0f02 100644 --- a/plugins/dali-script-v8/docs/content/animation.js +++ b/plugins/dali-script-v8/docs/content/animation.js @@ -78,7 +78,7 @@ function createAnimation() { var anim = new dali.Animation(1); // default duration is increased if length of all animations is greater than it. var animOptions = { - alpha: "linear", + alpha: dali.ALPHA_FUNCTION_LINEAR, delay: 0.5, // used to delay the start of the animation duration: 3, // duration of the animation }; @@ -89,16 +89,16 @@ function createAnimation() { // rotate back to correct orientation var endRotation = new dali.Rotation(0,0,0); - animOptions.alpha = "easeInOutSine"; + animOptions.alpha = dali.ALPHA_FUNCTION_EASE_IN_OUT_SINE; anim.animateTo(myActor1, "orientation", endRotation, animOptions); // Delay the myActor2 by a second animOptions.delay = 0.0; - animOptions.alpha = "linear"; + animOptions.alpha = dali.ALPHA_FUNCTION_LINEAR; anim.animateTo(myActor2, "positionZ", 0, animOptions); // rotate back to correct orientation - animOptions.alpha = "easeInOutSine"; + animOptions.alpha = dali.ALPHA_FUNCTION_EASE_IN_OUT_SINE; anim.animateTo(myActor2, "orientation", endRotation, animOptions); return anim; @@ -171,7 +171,7 @@ createShaderAnimation = function( imageView, color, zoom, duration, delay ) var shaderAnim = new dali.Animation(duration+delay); var animOptions = { - alpha: "doubleEaseInOutSine60", + alpha: dali.ALPHA_FUNCTION_EASE_IN_OUT_SINE, delay: delay, duration: duration, }; @@ -214,7 +214,7 @@ var shaderAnim = createShaderAnimation( imageView, color,zoom, duration, delay); // also rotate the imageView 90 degrees at the same time. var rotation = new dali.Rotation(90,0,0,1); -shaderAnim.animateTo(imageView, "orientation", rotation, { alpha:"linear", duration:duration, delay:delay }); +shaderAnim.animateTo(imageView, "orientation", rotation, { alpha:dali.ALPHA_FUNCTION_LINEAR, duration:duration, delay:delay }); shaderAnim.play(); @@ -224,36 +224,22 @@ shaderAnim.play(); ### Animation alpha functions -| Name | Description | -|--------------------|--------------| -|default |Linear | -|linear |Linear | -|square |Square (x^2) | -|reverse |Reverse linear | -|easeIn |Speeds up and comes to a sudden stop | -|easeOut |Sudden start and slows to a gradual stop| -|easeInOut |Speeds up and slows to a gradual stop| -|easeInSine |Speeds up and comes to a sudden stop| -|easeOutSine |Sudden start and slows to a gradual stop| -|easeInOutSine |Speeds up and slows to a gradual stop | -|easeInSine33 |Speeds up and comes to a sudden stop | -|easeOutSine33 |Sudden start and slows to a gradual stop | -|easeInOutSine33 |Speeds up and slows to a gradual stop | -|easeInOutSine50 |Speeds up and slows to a gradual stop | -|easeInOutSine60 |Speeds up and slows to a gradual stop | -|easeInOutSine70 |Speeds up and slows to a gradual stop | -|easeInOutSine80 |Speeds up and slows to a gradual stop | -|easeInOutSine90 |Speeds up and slows to a gradual stop | -|doubleEaseInOutSine6|Speeds up and slows to a gradual stop, then speeds up again and slows to a gradual stop | -|easeOutQuint50 |Sudden start and slows to a gradual stop | -|easeOutQuint80 |Sudden start and slows to a gradual stop | -|bounce |Sudden start, loses momentum and ** Returns to start position ** | -|bounceBack |Sudden start, loses momentum and returns to exceed start position ** Returns to start position ** | -|easeInBack |Slow start, exceed start position and quickly reach destination | -|easeOutBack |Sudden start, exceed end position and return to a gradual stop| -|easeInOutBack |Slow start, exceed start position, fast middle, exceed end position and return to a gradual stop| -|sin |full 360 revolution ** Returns to start position ** | -|sin2x |full 720 revolution ** Returns to start position ** | +| Name | Description | +|----------------------------------|----------------| +|ALPHA_FUNCTION_DEFAULT |Linear | +|ALPHA_FUNCTION_LINEAR |Linear | +|ALPHA_FUNCTION_REVERSE |Reverse linear | +|ALPHA_FUNCTION_EASE_IN_SQUARE |Speeds up and comes to a sudden stop (Square) | +|ALPHA_FUNCTION_EASE_OUT_SQUARE |Sudden start and slows to a gradual stop (Square) | +|ALPHA_FUNCTION_EASE_IN |Speeds up and comes to a sudden stop | +|ALPHA_FUNCTION_EASE_OUT |Sudden start and slows to a gradual stop| +|ALPHA_FUNCTION_EASE_IN_OUT |Speeds up and slows to a gradual stop| +|ALPHA_FUNCTION_EASE_IN_SINE |Speeds up and comes to a sudden stop| +|ALPHA_FUNCTION_EASE_OUT_SINE |Sudden start and slows to a gradual stop| +|ALPHA_FUNCTION_EASE_IN_OUT_SINE |Speeds up and slows to a gradual stop | +|ALPHA_FUNCTION_BOUNCE |Sudden start, loses momentum and ** Returns to start position ** | +|ALPHA_FUNCTION_SIN |full 360 revolution ** Returns to start position ** | +|ALPHA_FUNCTION_EASE_OUT_BACK |Sudden start, exceed end position and return to a gradual stop| diff --git a/plugins/dali-script-v8/docs/content/constants.js b/plugins/dali-script-v8/docs/content/constants.js index a09ed33..bd41150 100644 --- a/plugins/dali-script-v8/docs/content/constants.js +++ b/plugins/dali-script-v8/docs/content/constants.js @@ -188,9 +188,34 @@ Constants accessible under the dali global object. |PROPERTY_READ_WRITE | integer value | |PROPERTY_ANIMATABLE | integer value | +|**Layout dimensions ** | | +|DIMENSION_WIDTH | integer value | +|DIMENSION_HEIGHT | integer value | + |**Item layout type ** | | |ITEM_LAYOUT_LIST | integer value | |ITEM_LAYOUT_GRID | integer value | +|**Scroll direction bias ** | | +|DIRECTION_BIAS_NONE | integer value | +|DIRECTION_BIAS_LEFT | integer value | +|DIRECTION_BIAS_RIGHT | integer value | + +|**Animation alpha function ** | | +|ALPHA_FUNCTION_DEFAULT | integer value | +|ALPHA_FUNCTION_LINEAR | integer value | +|ALPHA_FUNCTION_REVERSE | integer value | +|ALPHA_FUNCTION_EASE_IN_SQUARE | integer value | +|ALPHA_FUNCTION_EASE_OUT_SQUARE | integer value | +|ALPHA_FUNCTION_EASE_IN | integer value | +|ALPHA_FUNCTION_EASE_OUT | integer value | +|ALPHA_FUNCTION_EASE_IN_OUT | integer value | +|ALPHA_FUNCTION_EASE_IN_SINE | integer value | +|ALPHA_FUNCTION_EASE_OUT_SINE | integer value | +|ALPHA_FUNCTION_EASE_IN_OUT_SINE | integer value | +|ALPHA_FUNCTION_BOUNCE | integer value | +|ALPHA_FUNCTION_SIN | integer value | +|ALPHA_FUNCTION_EASE_OUT_BACK | integer value | + * @class Constants */ diff --git a/plugins/dali-script-v8/docs/content/item-factory.js b/plugins/dali-script-v8/docs/content/item-factory.js index b7ae5ab..8f01154 100644 --- a/plugins/dali-script-v8/docs/content/item-factory.js +++ b/plugins/dali-script-v8/docs/content/item-factory.js @@ -169,7 +169,7 @@ JSON_TEMPLATE_FILE * "title_text" : "Item 1" } * ]; * - * itemFactory.data = itemViewData; // ItemFactory will look for the template from this JSON file + * itemFactory.data = itemViewData; // ItemFactory will create items from this data * * @type Array * @property data diff --git a/plugins/dali-script-v8/docs/content/path-animation.js b/plugins/dali-script-v8/docs/content/path-animation.js index 7847fc1..45b7fb6 100644 --- a/plugins/dali-script-v8/docs/content/path-animation.js +++ b/plugins/dali-script-v8/docs/content/path-animation.js @@ -30,7 +30,7 @@ function begin() dali.stage.add( imageView ); var animation = new dali.Animation(2.0); - var animOptions = { alpha:"easeInOutSine", delay:0.5, duration:1.5 }; + var animOptions = { alpha:dali.ALPHA_FUNCTION_EASE_IN_OUT_SINE, delay:0.5, duration:1.5 }; var forward = new dali.Vector3(1,0,0); animation.animate( imageView, myPath, forward, animOptions ); diff --git a/plugins/dali-script-v8/docs/content/scroll-view.js b/plugins/dali-script-v8/docs/content/scroll-view.js new file mode 100644 index 0000000..bff2fc3 --- /dev/null +++ b/plugins/dali-script-v8/docs/content/scroll-view.js @@ -0,0 +1,89 @@ +/** + * +## ScrollView API + +ScrollView is a container where the actors inside it can be scrolled manually +(via touch or pan gesture) or automatically. + +By default, ScrollView can scroll to any position both horizontally and +vertically and no snapping is enabled. + +Scroll mode can be specified to define how ScrollView should handle scrolling +in X and Y axes respectively (i.e. whether scrolling is enabled horizontally +or vertically, how scrolling is snapped, and the boundary to prevent ScrollView +to scroll beyond a certain position in the axes). + +![ ](../assets/img/scroll-view/scroll-view.png) + +### Example of creating a ScrollView + +``` + // Create a scroll view + var scrollView = new dali.Control("ScrollView"); + var stageSize = dali.stage.getSize(); + scrollView.size = [stageSize.x, stageSize.y, 0.0]; + scrollView.parentOrigin = dali.CENTER; + scrollView.anchorPoint = dali.CENTER; + + dali.stage.add( scrollView ); + + // Add actors to a scroll view with 3 pages + var pageRows = 1; + var pageColumns = 3; + for(var pageRow = 0; pageRow < pageRows; pageRow++) + { + for(var pageColumn = 0; pageColumn < pageColumns; pageColumn++) + { + var pageActor = new dali.Control(); + pageActor.widthResizePolicy = "FILL_TO_PARENT"; + pageActor.heightResizePolicy = "FILL_TO_PARENT"; + pageActor.parentOrigin = dali.CENTER; + pageActor.anchorPoint = dali.CENTER; + pageActor.position = [pageColumn * stageSize.x, pageRow * stageSize.y, 0.0]; + pageActor.name = "pageActor" + pageColumn; + + // Add images in a 3x4 grid layout for each page + var imageRows = 4; + var imageColumns = 3; + var margin = 10.0; + var imageSize = [(stageSize.x / imageColumns) - margin, (stageSize.y / imageRows) - margin, 0.0]; + + for(var row = 0; row < imageRows; row++) + { + for(var column = 0; column < imageColumns;column++) + { + var imageView = new dali.Control("ImageView"); + var imageId = row * imageColumns + column; + imageView.image = "./image-" + imageId + ".jpg"; + imageView.parentOrigin = dali.CENTER; + imageView.anchorPoint = dali.CENTER; + imageView.size = imageSize; + imageView.position = [ margin * 0.5 + (imageSize[0] + margin) * column - stageSize.x * 0.5 + imageSize[0] * 0.5, + margin * 0.5 + (imageSize[1] + margin) * row - stageSize.y * 0.5 + imageSize[1] * 0.5, + 0.0 ]; + pageActor.add(imageView); + var position = imageView.position; + } + } + + scrollView.add( pageActor ); + } + } + + // Set scroll view to have 3 pages in X axis and allow page snapping, + // and also disable scrolling in Y axis. + var scrollMode = { + xAxisScrollEnabled : true, + xAxisSnapToInterval : stageSize.x, // Define the snap points + xAxisScrollBoundary : stageSize.x * pageColumns, // i.e. Define 3 pages + yAxisScrollEnabled : false + } + + scrollView.setScrollMode(scrollMode); + +``` + + @class ScrollView + @extends Actor + +*/ diff --git a/plugins/dali-script-v8/file.list b/plugins/dali-script-v8/file.list index 598d90e..d648d9b 100644 --- a/plugins/dali-script-v8/file.list +++ b/plugins/dali-script-v8/file.list @@ -16,6 +16,7 @@ script_v8_plugin_src_files = \ $(v8_plugin_dir)/controls/control-wrapper.cpp \ $(v8_plugin_dir)/controls/item-factory-wrapper.cpp \ $(v8_plugin_dir)/controls/item-view-api.cpp \ + $(v8_plugin_dir)/controls/scroll-view-api.cpp \ $(v8_plugin_dir)/constants/constants-wrapper.cpp \ $(v8_plugin_dir)/animation/animation-api.cpp \ $(v8_plugin_dir)/animation/animation-wrapper.cpp \ diff --git a/plugins/dali-script-v8/src/actors/actor-api.cpp b/plugins/dali-script-v8/src/actors/actor-api.cpp index 371639d..e47285b 100644 --- a/plugins/dali-script-v8/src/actors/actor-api.cpp +++ b/plugins/dali-script-v8/src/actors/actor-api.cpp @@ -518,6 +518,31 @@ void ActorApi::GetNaturalSize( const v8::FunctionCallbackInfo& args ) } /** + * Return the value of negotiated dimension for the given dimension + * + * @for Actor + * @method getRelayoutSize + * @param {Integer} dimension The dimension of layout to retrieve (either dali.DIMENSION_WIDTH or dali.DIMENSION_HEIGHT) + * @return {Number} The value of the negotiated dimension + */ +void ActorApi::GetRelayoutSize( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + Actor actor = GetActor( isolate, args ); + + bool found; + int dimension = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "missing dimension parameter"); + return; + } + + args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetRelayoutSize( static_cast(dimension) ) ) ); +} + +/** * Calculate the width of the actor given a height * * The natural size is used for default calculation. diff --git a/plugins/dali-script-v8/src/actors/actor-api.h b/plugins/dali-script-v8/src/actors/actor-api.h index bcd600e..2963400 100644 --- a/plugins/dali-script-v8/src/actors/actor-api.h +++ b/plugins/dali-script-v8/src/actors/actor-api.h @@ -57,6 +57,7 @@ namespace ActorApi void SetKeyboardFocusable( const v8::FunctionCallbackInfo< v8::Value >& args ); void IsKeyboardFocusable( const v8::FunctionCallbackInfo< v8::Value >& args ); void GetNaturalSize( const v8::FunctionCallbackInfo< v8::Value >& args ); + void GetRelayoutSize( const v8::FunctionCallbackInfo< v8::Value >& args ); void GetWidthForHeight( const v8::FunctionCallbackInfo& args ); void GetHeightForWidth( const v8::FunctionCallbackInfo& args ); void TranslateBy( const v8::FunctionCallbackInfo< v8::Value >& args ); diff --git a/plugins/dali-script-v8/src/actors/actor-wrapper.cpp b/plugins/dali-script-v8/src/actors/actor-wrapper.cpp index a1c0f78..c9d3e1d 100644 --- a/plugins/dali-script-v8/src/actors/actor-wrapper.cpp +++ b/plugins/dali-script-v8/src/actors/actor-wrapper.cpp @@ -179,6 +179,7 @@ const ActorFunctions ActorFunctionTable[]= // ignore. SetSize() use Actor.size // ignore. GetCurrentSize() use Actor.size { "GetNaturalSize", ActorApi::GetNaturalSize, ACTOR_API }, + { "GetRelayoutSize", ActorApi::GetRelayoutSize, ACTOR_API }, { "GetWidthForHeight",ActorApi::GetWidthForHeight, ACTOR_API }, { "GetHeightForWidth",ActorApi::GetHeightForWidth, ACTOR_API }, // ignore. SetPosition(....) use Actor.position diff --git a/plugins/dali-script-v8/src/animation/animation-api.cpp b/plugins/dali-script-v8/src/animation/animation-api.cpp index 0db4482..e20e656 100644 --- a/plugins/dali-script-v8/src/animation/animation-api.cpp +++ b/plugins/dali-script-v8/src/animation/animation-api.cpp @@ -20,7 +20,6 @@ #include "path-wrapper.h" // EXTERNAL INCLUDES -#include // for strcmp #include @@ -38,85 +37,11 @@ namespace V8Plugin namespace // un named namespace { -// @todo think about alternative ways of passing around -struct AlphaFuncStruct -{ - const char* const name; - AlphaFunction alphaFunc; -}; -/** - * Contains a list of alpha functions that can be used. - */ -const AlphaFuncStruct AlphaFunctionTable[]= -{ - - {"default" , AlphaFunction::DEFAULT }, - {"linear" , AlphaFunction::LINEAR }, - {"reverse" , AlphaFunction::REVERSE }, - - {"easeInSquare" , AlphaFunction::EASE_IN_SQUARE }, - {"easeOutSquare" , AlphaFunction::EASE_OUT_SQUARE }, - - {"easeIn" , AlphaFunction::EASE_IN }, - {"easeOut" , AlphaFunction::EASE_OUT }, - {"easeInOut" , AlphaFunction::EASE_IN_OUT }, - - {"easeInSine" , AlphaFunction::EASE_IN_SINE }, - {"easeOutSine" , AlphaFunction::EASE_OUT_SINE }, - {"easeInOutSine" , AlphaFunction::EASE_IN_OUT_SINE }, - - {"bounce" , AlphaFunction::BOUNCE }, - {"sin" , AlphaFunction::SIN }, - {"easeOutBack" , AlphaFunction::EASE_OUT_BACK }, - -}; -const unsigned int AlphaFunctionTableCount = sizeof(AlphaFunctionTable)/sizeof(AlphaFunctionTable[0]); -const char* const DEFAULT_ALPHA_NAME = "default"; -static AlphaFunction DEFAULT_ALPHA_FUNCTION = AlphaFunction::DEFAULT; - - - -AlphaFunction GetAlphaFunction( const std::string& alphaFuncName ) -{ - // This will normally get called just a few times during the application, so no point in doing anything clever - for( unsigned int i = 0; i < AlphaFunctionTableCount; i++) - { - const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] ); - - if( std::strcmp( alphaStruct.name , alphaFuncName.c_str() ) == 0 ) - { - return alphaStruct.alphaFunc; - } - } - - DALI_LOG_ERROR("Failed to find alpha func |%s| \n", alphaFuncName.c_str() ); - return DEFAULT_ALPHA_FUNCTION; -} - -const char* const GetAlphaFunctionName( AlphaFunction alphaFunc ) -{ - // This may get called 3 times during the application, so no point - // in doing anything clever - - for( unsigned int i = 0; i < AlphaFunctionTableCount; i++) - { - const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] ); - - - if( alphaStruct.alphaFunc.GetBuiltinFunction() == alphaFunc.GetBuiltinFunction() ) - { - return alphaStruct.name; - } - } - return "default"; -} - - struct AnimationParameters { AnimationParameters( const Animation& anim) : propertyIndex( Property::INVALID_INDEX ), - alphaFunction( DEFAULT_ALPHA_FUNCTION), + alphaFunction( AlphaFunction::DEFAULT), delay( 0.f ), duration(anim.GetDuration()), optionsFound( false ) @@ -150,11 +75,10 @@ void GetAnimationOptions( v8::Isolate* isolate, { v8::Local obj = options->ToObject(); v8::Local alphaValue = obj->Get( v8::String::NewFromUtf8( isolate, "alpha" ) ); - if( alphaValue->IsString() ) + if( alphaValue->IsUint32() ) { animParams.optionsFound = true; - std::string alphaName = V8Utils::v8StringToStdString( alphaValue ); - animParams.alphaFunction = GetAlphaFunction( alphaName ); + animParams.alphaFunction = static_cast(alphaValue->ToUint32()->Value()); } v8::Local delayValue = obj->Get( v8::String::NewFromUtf8( isolate, "delay" ) ); @@ -225,10 +149,9 @@ KeyFrames GetKeyFrames( v8::Isolate* isolate, v8::Local keyFrameArra // get keyframe.alpha v8::Handle alphaValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "alpha")); - if( alphaValue->IsString() ) + if( alphaValue->IsUint32() ) { - std::string alphaName = V8Utils::v8StringToStdString( alphaValue ); - AlphaFunction alphaFunction = GetAlphaFunction( alphaName ); + AlphaFunction alphaFunction = static_cast(alphaValue->ToUint32()->Value()); keyframes.Add( progress->NumberValue(), value, alphaFunction ); } else @@ -529,7 +452,7 @@ void AnimationApi::GetDisconnectAction( const v8::FunctionCallbackInfo< v8::Valu * Set the default alpha function for an animation. * @method setDefaultAlphaFunction * @for Animation - * @param {string} alpha function + * @param {Integer} alpha function */ void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args ) { @@ -539,23 +462,22 @@ void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8:: Animation anim = GetAnimation( isolate, args ); bool found( false ); - std::string alphaFunc = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args ); + int alphaFunc = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); if( !found ) { DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" ); } else { - AlphaFunction func = GetAlphaFunction( alphaFunc ); + AlphaFunction func = static_cast(alphaFunc); anim.SetDefaultAlphaFunction( func ); } - } /** * Get the default alpha function for an animation. * @method getDefaultAlphaFunction * @for Animation - * @return {string} alpha function + * @return {Integer} alpha function */ void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo& args ) { @@ -564,10 +486,10 @@ void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo& args, Acto targetPropertyIndex = targetActor.GetPropertyIndex( propertyName ); if( targetPropertyIndex == Property::INVALID_INDEX ) { - targetPropertyIndex = targetActor.GetPropertyIndex( propertyName ); - - if( targetPropertyIndex == Property::INVALID_INDEX ) - { - DALI_SCRIPT_EXCEPTION( isolate, "Target property not found" ); - return false; - } + DALI_SCRIPT_EXCEPTION( isolate, "Target property not found" ); + return false; } } else @@ -139,14 +134,9 @@ bool GetApplyParameters( const v8::FunctionCallbackInfo< v8::Value >& args, Acto sourcePropertyIndex = targetActor.GetPropertyIndex( propertyName ); if( sourcePropertyIndex == Property::INVALID_INDEX ) { - sourcePropertyIndex = targetActor.GetPropertyIndex( propertyName ); - - if( sourcePropertyIndex == Property::INVALID_INDEX ) - { - DALI_SCRIPT_EXCEPTION( isolate, "Source property not found" ); - return false; + DALI_SCRIPT_EXCEPTION( isolate, "Source property not found" ); + return false; } - } } else { diff --git a/plugins/dali-script-v8/src/constants/constants-wrapper.cpp b/plugins/dali-script-v8/src/constants/constants-wrapper.cpp index edbd62b..a3a3dd7 100644 --- a/plugins/dali-script-v8/src/constants/constants-wrapper.cpp +++ b/plugins/dali-script-v8/src/constants/constants-wrapper.cpp @@ -36,6 +36,7 @@ #include #include #include +#include namespace Dali { @@ -248,9 +249,31 @@ const IntegerPair EnumTable[] = { "PROPERTY_READ_WRITE", Property::READ_WRITE }, { "PROPERTY_ANIMATABLE", Property::ANIMATABLE }, + { "DIMENSION_WIDTH", Dimension::WIDTH }, + { "DIMENSION_HEIGHT", Dimension::HEIGHT }, + { "ITEM_LAYOUT_LIST", Toolkit::DefaultItemLayout::LIST }, { "ITEM_LAYOUT_GRID", Toolkit::DefaultItemLayout::GRID }, + { "DIRECTION_BIAS_NONE", Toolkit::DirectionBiasNone }, + { "DIRECTION_BIAS_LEFT", Toolkit::DirectionBiasLeft }, + { "DIRECTION_BIAS_RIGHT", Toolkit::DirectionBiasRight }, + + { "ALPHA_FUNCTION_DEFAULT", AlphaFunction::DEFAULT }, + { "ALPHA_FUNCTION_LINEAR", AlphaFunction::LINEAR }, + { "ALPHA_FUNCTION_REVERSE", AlphaFunction::REVERSE }, + { "ALPHA_FUNCTION_EASE_IN_SQUARE", AlphaFunction::EASE_IN_SQUARE }, + { "ALPHA_FUNCTION_EASE_OUT_SQUARE", AlphaFunction::EASE_OUT_SQUARE }, + { "ALPHA_FUNCTION_EASE_IN", AlphaFunction::EASE_IN }, + { "ALPHA_FUNCTION_EASE_OUT", AlphaFunction::EASE_OUT }, + { "ALPHA_FUNCTION_EASE_IN_OUT", AlphaFunction::EASE_IN_OUT }, + { "ALPHA_FUNCTION_EASE_IN_SINE", AlphaFunction::EASE_IN_SINE }, + { "ALPHA_FUNCTION_EASE_OUT_SINE", AlphaFunction::EASE_OUT_SINE }, + { "ALPHA_FUNCTION_EASE_IN_OUT_SINE", AlphaFunction::EASE_IN_OUT_SINE }, + { "ALPHA_FUNCTION_BOUNCE", AlphaFunction::BOUNCE }, + { "ALPHA_FUNCTION_SIN", AlphaFunction::SIN }, + { "ALPHA_FUNCTION_EASE_OUT_BACK", AlphaFunction::EASE_OUT_BACK }, + }; const unsigned int EnumTableCount = sizeof(EnumTable)/sizeof(EnumTable[0]); diff --git a/plugins/dali-script-v8/src/controls/control-wrapper.cpp b/plugins/dali-script-v8/src/controls/control-wrapper.cpp index 09093a2..b3cc3dc 100644 --- a/plugins/dali-script-v8/src/controls/control-wrapper.cpp +++ b/plugins/dali-script-v8/src/controls/control-wrapper.cpp @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include +#include #include #include @@ -35,6 +36,7 @@ namespace V8Plugin v8::Persistent ControlWrapper::mControlTemplate; v8::Persistent ControlWrapper::mItemViewTemplate; +v8::Persistent ControlWrapper::mScrollViewTemplate; Vector< void* > ControlWrapper::mControlGarbageContainer; @@ -56,7 +58,8 @@ struct ControlTemplate const ControlTemplate ControlTemplateLookup[]= { { &ControlWrapper::mControlTemplate }, // CONTROL - { &ControlWrapper::mItemViewTemplate } // ITEMVIEW + { &ControlWrapper::mItemViewTemplate }, // ITEMVIEW + { &ControlWrapper::mScrollViewTemplate } // SCROLLVIEW }; /** @@ -65,7 +68,8 @@ const ControlTemplate ControlTemplateLookup[]= enum ControlApiBitMask { CONTROL_API = 1 << 0, - ITEMVIEW_API = 1 << 1 + ITEMVIEW_API = 1 << 1, + SCROLLVIEW_API = 1 << 2 }; /** @@ -87,6 +91,7 @@ const ControlApiStruct ControlApiLookup[]= { {"Control", ControlWrapper::CONTROL, NULL, CONTROL_API }, {"ItemView", ControlWrapper::ITEMVIEW, ItemViewApi::New, CONTROL_API | ITEMVIEW_API }, + {"ScrollView", ControlWrapper::SCROLLVIEW, ScrollViewApi::New, CONTROL_API | SCROLLVIEW_API } }; const unsigned int ControlApiLookupCount = sizeof(ControlApiLookup)/sizeof(ControlApiLookup[0]); @@ -171,6 +176,19 @@ const ControlFunctions ControlFunctionTable[]= { "GetItemId", ItemViewApi::GetItemId, ITEMVIEW_API }, { "GetItemsRange", ItemViewApi::GetItemsRange, ITEMVIEW_API }, + /************************************** + * ScrollView API + **************************************/ + { "SetScrollMode", ScrollViewApi::SetScrollMode, SCROLLVIEW_API }, + { "GetCurrentPage", ScrollViewApi::GetCurrentPage, SCROLLVIEW_API }, + { "ScrollToPosition", ScrollViewApi::ScrollToPosition, SCROLLVIEW_API }, + { "ScrollToPage", ScrollViewApi::ScrollToPage, SCROLLVIEW_API }, + { "ScrollToActor", ScrollViewApi::ScrollToActor, SCROLLVIEW_API }, + { "ScrollToSnapInterval", ScrollViewApi::ScrollToSnapInterval, SCROLLVIEW_API }, + { "SetScrollFlickAlphaFunction", ScrollViewApi::SetScrollFlickAlphaFunction, SCROLLVIEW_API }, + { "SetScrollSnapAlphaFunction", ScrollViewApi::SetScrollSnapAlphaFunction, SCROLLVIEW_API }, + { "SetSnapOvershootAlphaFunction", ScrollViewApi::SetSnapOvershootAlphaFunction, SCROLLVIEW_API }, + }; const unsigned int ControlFunctionTableCount = sizeof(ControlFunctionTable)/sizeof(ControlFunctionTable[0]); diff --git a/plugins/dali-script-v8/src/controls/control-wrapper.h b/plugins/dali-script-v8/src/controls/control-wrapper.h index dc4b636..8147d56 100644 --- a/plugins/dali-script-v8/src/controls/control-wrapper.h +++ b/plugins/dali-script-v8/src/controls/control-wrapper.h @@ -50,7 +50,8 @@ public: { UNKNOWN_CONTROL = -1, CONTROL = 0, - ITEMVIEW = 1 + ITEMVIEW = 1, + SCROLLVIEW = 2 }; /** diff --git a/plugins/dali-script-v8/src/controls/scroll-view-api.cpp b/plugins/dali-script-v8/src/controls/scroll-view-api.cpp new file mode 100644 index 0000000..969fbf7 --- /dev/null +++ b/plugins/dali-script-v8/src/controls/scroll-view-api.cpp @@ -0,0 +1,477 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include "scroll-view-api.h" + +// EXTERNAL INCLUDES + +// INTERNAL INCLUDES +#include +#include +#include + +namespace Dali +{ + +namespace V8Plugin +{ + +namespace // unanmed namespace +{ + +Toolkit::ScrollView GetScrollView( v8::Isolate* isolate, const v8::FunctionCallbackInfo& args ) +{ + HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() ); + return Toolkit::ScrollView::DownCast( handleWrapper->mHandle ); +} + +} //unanmed namespace + +/*************************************** + * SCROLLVIEW API FUNCTIONS + ***************************************/ + +/** + * Constructor + * + * @for ScrollView + * @constructor + * @method ScrollView + * @return {Object} scrollView + */ +Toolkit::Control ScrollViewApi::New( const v8::FunctionCallbackInfo< v8::Value >& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Toolkit::ScrollView scrollView = Toolkit::ScrollView::New(); + return scrollView; +} + +/** + * Set the scroll mode of ScrollView. + * + * This defines whether scrolling is enabled horizontally or vertically, how + * scrolling is snapped, and the boundary in which the scroll view can pan. + * + * When no specific scroll mode is set, scroll view can scroll to any position + * both horizontally and vertically and no snapping is enabled. + * + * Example of setting the scroll boundary of scroll view in the X axis to + * three pages (page size equals to the width of scroll view) and allowing + * snapping between pages, and disabling scrolling in the Y axis. + * + * ``` + * var scrollMode = { + * xAxisScrollEnabled : true, + * xAxisSnapToInterval : scrollView.sizeWidth, + * xAxisScrollBoundary : scrollView.sizeWidth * 3, + * yAxisScrollEnabled : false + * } + * + * scrollView.setScrollMode(scrollMode); + * ``` + * + * @for ScrollView + * @method setScrollMode + * @param {Object} scrollMode + * @param {Boolean} scrollMode.xAxisScrollEnabled True if the content can be scrolled in X axis or false if not. + * @param {Float} [scrollMode.xAxisSnapToInterval] When set, causes scroll view to snap to multiples of the value of the interval in the X axis while flicking. (by default no snapping) + * @param {Float} [scrollMode.xAxisScrollBoundary] When set, causes scroll view unable to scroll beyond the value of the boundary in the X axis (by default no boundary) + * @param {Boolean} scrollMode.yAxisScrollEnabled True if the content can be scrolled in Y axis or false if not. + * @param {Float} [scrollMode.yAxisSnapToInterval] When set, causes scroll view to snap to multiples of the value of the interval in the Y axis while flicking. (by default no snapping) + * @param {Float} [scrollMode.yAxisScrollBoundary] When set, causes scroll view unable to scroll beyond the value of the boundary in the Y axis (by default no boundary) + */ +void ScrollViewApi::SetScrollMode( const v8::FunctionCallbackInfo< v8::Value >& args) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Toolkit::ScrollView scrollView = GetScrollView( isolate, args ); + + v8::Local scrollMode( args[0] ); + if( !scrollMode->IsObject() ) + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid scroll mode parameter" ); + return; + } + + v8::Local scrollModeObj = scrollMode->ToObject(); + + Toolkit::RulerPtr rulerX, rulerY; + + // Check the scroll mode in the X axis + bool xAxisScrollEnabled = true; + v8::Local xAxisScrollEnabledValue= scrollModeObj->Get( v8::String::NewFromUtf8( isolate, "xAxisScrollEnabled" ) ); + if( xAxisScrollEnabledValue->IsBoolean() ) + { + xAxisScrollEnabled = xAxisScrollEnabledValue->ToBoolean()->Value(); + } + else + { + DALI_SCRIPT_EXCEPTION( isolate, "Missing xAxisScrollEnabled"); + return; + } + + if(!xAxisScrollEnabled) + { + // Default ruler and disabled + rulerX = new Toolkit::DefaultRuler(); + rulerX->Disable(); + } + else + { + v8::Local xAxisSnapToIntervalValue= scrollModeObj->Get( v8::String::NewFromUtf8( isolate, "xAxisSnapToInterval" ) ); + if( xAxisSnapToIntervalValue->IsNumber() ) + { + // Fixed ruler and enabled + float xAxisSnapToInterval = xAxisSnapToIntervalValue->ToNumber()->Value(); + rulerX = new Toolkit::FixedRuler(xAxisSnapToInterval); + } + else + { + // Default ruler and enabled + rulerX = new Toolkit::DefaultRuler(); + } + + v8::Local xAxisScrollBoundaryValue= scrollModeObj->Get( v8::String::NewFromUtf8( isolate, "xAxisScrollBoundary" ) ); + if( xAxisScrollBoundaryValue->IsNumber() ) + { + // By default ruler domain is disabled unless set + float xAxisScrollBoundary = xAxisScrollBoundaryValue->ToNumber()->Value(); + rulerX->SetDomain( Toolkit::RulerDomain( 0, xAxisScrollBoundary, true ) ); + } + } + + // Check the scroll mode in the Y axis + bool yAxisScrollEnabled = true; + v8::Local yAxisScrollEnabledValue= scrollModeObj->Get( v8::String::NewFromUtf8( isolate, "yAxisScrollEnabled" ) ); + if( yAxisScrollEnabledValue->IsBoolean() ) + { + yAxisScrollEnabled = yAxisScrollEnabledValue->ToBoolean()->Value(); + } + else + { + DALI_SCRIPT_EXCEPTION( isolate, "Missing yAxisScrollEnabled"); + return; + } + + if(!yAxisScrollEnabled) + { + // Default ruler and disabled + rulerY = new Toolkit::DefaultRuler(); + rulerY->Disable(); + } + else + { + v8::Local yAxisSnapToIntervalValue= scrollModeObj->Get( v8::String::NewFromUtf8( isolate, "yAxisSnapToInterval" ) ); + if( yAxisSnapToIntervalValue->IsNumber() ) + { + // Fixed ruler and enabled + float yAxisSnapToInterval = yAxisSnapToIntervalValue->ToNumber()->Value(); + rulerY = new Toolkit::FixedRuler(yAxisSnapToInterval); + } + else + { + // Default ruler and enabled + rulerY = new Toolkit::DefaultRuler(); + } + + v8::Local yAxisScrollBoundaryValue= scrollModeObj->Get( v8::String::NewFromUtf8( isolate, "yAxisScrollBoundary" ) ); + if( yAxisScrollBoundaryValue->IsNumber() ) + { + // By default ruler domain is disabled unless set + float yAxisScrollBoundary = yAxisScrollBoundaryValue->ToNumber()->Value(); + rulerY->SetDomain( Toolkit::RulerDomain( 0, yAxisScrollBoundary, true ) ); + } + } + + scrollView.SetRulerX(rulerX); + scrollView.SetRulerY(rulerY); +} + +/** + * Retrieves current scroll page based on the defined snap interval being the + * size of one page, and all pages laid out in a grid fashion, increasing from + * left to right until the end of the scroll boundary. Pages start from 0 as the + * first page. + * + * If no snap interval is defined, this API will return undefined value. + * + * @for ScrollView + * @method getCurrentPage + * @return {Integer} The index of current page in scroll view + */ +void ScrollViewApi::GetCurrentPage( const v8::FunctionCallbackInfo< v8::Value >& args) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Toolkit::ScrollView scrollView = GetScrollView( isolate, args ); + args.GetReturnValue().Set( v8::Integer::New( isolate, scrollView.GetCurrentPage() ) ); +} + +/** + * Scrolls the contents to the given position. + * + * Position 0,0 is the origin. Increasing X scrolls contents left, while + * increasing Y scrolls contents up. If Rulers have been applied to the axes, + * then the contents will scroll until reaching the scroll boundary. + * Contents will not snap. + * + * The biasing parameters are provided such that in scenarios with 2 or 2x2 pages + * in wrap mode, the application developer can decide whether to scroll left or + * right to get to the target page. + * + * @for ScrollView + * @method scrollToPosition + * @param {Array} position The position to scroll to. + * @param {Float} [durationSeconds] The duration of the scroll animation in seconds (default value is scrollView.scrollSnapDuration) + * @param {Integer} [alphaFunction] The alpha function to use. + * @param {Integer} [horizontalBias] Whether to bias scrolling to left or right (by default no bias). + * @param {Integer} [verticalBias] Whether to bias scrolling to top or bottom (by default no bias). + * @example + * // scroll direction bias is one of the following + * dali.DIRECTION_BIAS_NONE // Don't bias scroll snap + * dali.DIRECTION_BIAS_LEFT // Bias scroll snap to Left + * dali.DIRECTION_BIAS_RIGHT // Bias scroll snap to Right + * + * scrollView.scrollToPosition( [150.0, 100.0], 0.5, dali.ALPHA_FUNCTION_EASE_IN_OUT, dali.DIRECTION_BIAS_LEFT, dali.DIRECTION_BIAS_NONE ); + */ +void ScrollViewApi::ScrollToPosition( const v8::FunctionCallbackInfo< v8::Value >& args) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Toolkit::ScrollView scrollView = GetScrollView( isolate, args ); + + bool found( false ); + Vector2 position = V8Utils::GetVector2Parameter( PARAMETER_0, found, isolate, args ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "bad position parameter" ); + return; + } + + float durationSeconds = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, scrollView.GetScrollSnapDuration() ); + + AlphaFunction alphaFunction = scrollView.GetScrollSnapAlphaFunction(); + + found = false; + int alpha = V8Utils::GetIntegerParameter( PARAMETER_2, found, isolate, args, 0 ); + if(found) + { + alphaFunction = static_cast(alpha); + } + + Toolkit::DirectionBias horizontalBias = static_cast( V8Utils::GetIntegerParameter( PARAMETER_3, found, isolate, args, Toolkit::DirectionBiasNone ) ); + Toolkit::DirectionBias verticalBias = static_cast( V8Utils::GetIntegerParameter( PARAMETER_4, found, isolate, args, Toolkit::DirectionBiasNone ) ); + + scrollView.ScrollTo( position, durationSeconds, alphaFunction, horizontalBias, verticalBias ); +} + +/** + * Scrolls the contents to the page with the given index. + * + * This is based on assumption that the page index starts from 0 and the + * position of each page is: [pageIndex * snapToInterval, 0]. + * + * If no snap interval is defined, calling this API will cause unexpected + * behaviour. + * + * The biasing parameter is provided such that in scenarios with 2 pages + * in wrap mode, the application developer can decide whether to scroll + * left or right to get to the target page. + * + * @for ScrollView + * @method scrollToPage + * @param {Integer} pageIndex The index of the page to scroll to. + * @param {Float} [durationSeconds] The duration of the scroll animation in seconds (default value is scrollView.scrollSnapDuration) + * @param {Integer} [bias] Whether to bias scrolling to left or right (by default no bias). + * @example + * // scroll direction bias is one of the following + * dali.DIRECTION_BIAS_NONE // Don't bias scroll snap + * dali.DIRECTION_BIAS_LEFT // Bias scroll snap to Left + * dali.DIRECTION_BIAS_RIGHT // Bias scroll snap to Right + * + * scrollView.scrollToPage( 1, 0.5, dali.DIRECTION_BIAS_RIGHT ); + */ +void ScrollViewApi::ScrollToPage( const v8::FunctionCallbackInfo< v8::Value >& args) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Toolkit::ScrollView scrollView = GetScrollView( isolate, args ); + + bool found( false ); + int pageIndex = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "bad page index parameter" ); + return; + } + + float durationSeconds = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, scrollView.GetScrollSnapDuration() ); + Toolkit::DirectionBias bias = static_cast( V8Utils::GetIntegerParameter( PARAMETER_2, found, isolate, args, Toolkit::DirectionBiasNone ) ); + + scrollView.ScrollTo( pageIndex, durationSeconds, bias ); +} + +/** + * Scrolls the contents such that the given actor appears in the center of + * the scroll view. + * + * The actor must be a direct child of scroll view. + * + * @for ScrollView + * @method scrollToActor + * @param {Object} actor The actor to scroll to. + * @param {Float} [durationSeconds] The duration of the scroll animation in seconds (default value is scrollView.scrollSnapDuration) + * @example + * scrollView.scrollToActor( childActor, 0.5 ); + */ +void ScrollViewApi::ScrollToActor( const v8::FunctionCallbackInfo< v8::Value >& args) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Toolkit::ScrollView scrollView = GetScrollView( isolate, args ); + + bool found( false ); + Actor actor = V8Utils::GetActorParameter( 0, found, isolate, args ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid actor parameter" ); + return; + } + + float durationSeconds = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, scrollView.GetScrollSnapDuration() ); + + scrollView.ScrollTo( actor, durationSeconds ); +} + +/** + * Scrolls the content to the nearest snap point as specified by the snap interval. + * If already at snap points, it will not scroll. + * + * @for ScrollView + * @method scrollToSnapInterval + * @return {Boolean} True if snapping is needed or false if already at snap points + * @example + * var success = scrollView.scrollToSnapInterval(); + */ +void ScrollViewApi::ScrollToSnapInterval( const v8::FunctionCallbackInfo< v8::Value >& args) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Toolkit::ScrollView scrollView = GetScrollView( isolate, args ); + + args.GetReturnValue().Set( v8::Boolean::New( isolate, scrollView.ScrollToSnapPoint() ) ); +} + +/** + * Set the alpha function of flick animation. + * + * @for ScrollView + * @method setScrollFlickAlphaFunction + * @param {Integer} alphaFunction The alpha function to use. + * @example + * scrollView.setScrollFlickAlphaFunction( dali.ALPHA_FUNCTION_EASE_IN_OUT ); + */ +void ScrollViewApi::SetScrollFlickAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Toolkit::ScrollView scrollView = GetScrollView( isolate, args ); + + bool found( false ); + int alphaFunction = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid alpha function parameter" ); + return; + } + else + { + scrollView.SetScrollFlickAlphaFunction( static_cast(alphaFunction) ); + } +} + +/** + * Set the alpha function of snap animation. + * + * @for ScrollView + * @method setScrollSnapAlphaFunction + * @param {String} alphaFunction The alpha function to use. + * @example + * scrollView.setScrollSnapAlphaFunction( dali.ALPHA_FUNCTION_EASE_IN_OUT ); + */ +void ScrollViewApi::SetScrollSnapAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Toolkit::ScrollView scrollView = GetScrollView( isolate, args ); + + bool found( false ); + int alphaFunction = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid alpha function parameter" ); + return; + } + else + { + scrollView.SetScrollSnapAlphaFunction( static_cast(alphaFunction) ); + } +} + +/** + * Set the alpha function of overshoot snap animation. + * + * @for ScrollView + * @method setSnapOvershootAlphaFunction + * @param {String} alphaFunction The alpha function to use. + * @example + * scrollView.setSnapOvershootAlphaFunction( dali.ALPHA_FUNCTION_EASE_IN_OUT ); + */ +void ScrollViewApi::SetSnapOvershootAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Toolkit::ScrollView scrollView = GetScrollView( isolate, args ); + + bool found( false ); + int alphaFunction = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid alpha function parameter" ); + return; + } + else + { + scrollView.SetSnapOvershootAlphaFunction( static_cast(alphaFunction) ); + } +} + +} // namespace V8Plugin + +} // namespace Dali diff --git a/plugins/dali-script-v8/src/controls/scroll-view-api.h b/plugins/dali-script-v8/src/controls/scroll-view-api.h new file mode 100644 index 0000000..0ca74db --- /dev/null +++ b/plugins/dali-script-v8/src/controls/scroll-view-api.h @@ -0,0 +1,58 @@ +#ifndef __DALI_V8PLUGIN_SCROLL_VIEW_API_H__ +#define __DALI_V8PLUGIN_SCROLL_VIEW_API_H__ + +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +namespace Dali +{ + +namespace V8Plugin +{ + +namespace ScrollViewApi +{ + + /** + * constructor + */ + Toolkit::Control New( const v8::FunctionCallbackInfo< v8::Value >& args ); + + /** + * ScrollView API. See scroll-view.h for description of functions + */ + void SetScrollMode( const v8::FunctionCallbackInfo< v8::Value >& args); + void GetCurrentPage( const v8::FunctionCallbackInfo< v8::Value >& args ); + void ScrollToPosition( const v8::FunctionCallbackInfo< v8::Value >& args ); + void ScrollToPage( const v8::FunctionCallbackInfo< v8::Value >& args ); + void ScrollToActor( const v8::FunctionCallbackInfo< v8::Value >& args ); + void ScrollToSnapInterval( const v8::FunctionCallbackInfo< v8::Value >& args ); + void SetScrollFlickAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args ); + void SetScrollSnapAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args ); + void SetSnapOvershootAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args ); + +}; // namespace ScrollViewApi + +} // namespace V8Plugin + +} // namespace Dali + +#endif // header __DALI_V8PLUGIN_SCROLL_VIEW_API_H__ diff --git a/plugins/dali-script-v8/src/shared/base-wrapped-object.h b/plugins/dali-script-v8/src/shared/base-wrapped-object.h index 0bd9840..0efc17e 100644 --- a/plugins/dali-script-v8/src/shared/base-wrapped-object.h +++ b/plugins/dali-script-v8/src/shared/base-wrapped-object.h @@ -82,6 +82,7 @@ public: ACTOR_PROPERTY, ITEMVIEW, ITEMFACTORY, + SCROLLVIEW, RENDER_TASK, RENDER_TASK_LIST, TIMER,