From bb5db46ebda86545c722a49f2ad35615262d04a3 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Thu, 7 May 2015 13:17:59 +0100 Subject: [PATCH] Updated demo for ScrollBar and ScrollView API changes Change-Id: I126a9ea79d3784dbf3357f7b5fb2af6d145815a2 --- demo/dali-table-view.cpp | 6 ++-- demo/dali-table-view.h | 4 +-- examples/cluster/cluster-example.cpp | 4 +-- .../image-scaling-irregular-grid-example.cpp | 39 +++++++++++++++++----- examples/scroll-view/scroll-view-example.cpp | 4 +-- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/demo/dali-table-view.cpp b/demo/dali-table-view.cpp index d647b67..8464339 100644 --- a/demo/dali-table-view.cpp +++ b/demo/dali-table-view.cpp @@ -140,7 +140,7 @@ public: // Bubbles X position moves parallax to horizontal // panning by a scale factor unique to each bubble. - position.x = mInitialX + ( inputs[0]->GetVector3().x * mScale ); + position.x = mInitialX + ( inputs[0]->GetVector2().x * mScale ); } private: @@ -637,14 +637,14 @@ void DaliTableView::OnPressedAnimationFinished( Dali::Animation& source ) } } -void DaliTableView::OnScrollStart( const Dali::Vector3& position ) +void DaliTableView::OnScrollStart( const Dali::Vector2& position ) { mScrolling = true; PlayAnimation(); } -void DaliTableView::OnScrollComplete( const Dali::Vector3& position ) +void DaliTableView::OnScrollComplete( const Dali::Vector2& position ) { mScrolling = false; diff --git a/demo/dali-table-view.h b/demo/dali-table-view.h index b19ac5d9..e721ca6 100644 --- a/demo/dali-table-view.h +++ b/demo/dali-table-view.h @@ -217,14 +217,14 @@ private: // Application callbacks & implementation * * @param[in] position The current position of the scroll contents. */ - void OnScrollStart(const Dali::Vector3& position); + void OnScrollStart(const Dali::Vector2& position); /** * Signal emitted when scrolling has completed. * * @param[in] position The current position of the scroll contents. */ - void OnScrollComplete(const Dali::Vector3& position); + void OnScrollComplete(const Dali::Vector2& position); /** * Signal emitted when any Sensitive Actor has been touched diff --git a/examples/cluster/cluster-example.cpp b/examples/cluster/cluster-example.cpp index 7dd8673..6bcd5fe 100644 --- a/examples/cluster/cluster-example.cpp +++ b/examples/cluster/cluster-example.cpp @@ -691,8 +691,8 @@ public: // Apply new shader-effects. // Move Y to origin incase we came from an effect where user could free pan in y axis. - const Vector3 currentScrollPosition(mScrollView.GetCurrentScrollPosition()); - mScrollView.ScrollTo(Vector3(currentScrollPosition.x, 0.0f, 0.0f)); + const Vector2 currentScrollPosition(mScrollView.GetCurrentScrollPosition()); + mScrollView.ScrollTo(Vector2(currentScrollPosition.x, 0.0f)); switch(type) { diff --git a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp index d921645..259f0d2 100644 --- a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp +++ b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp @@ -335,13 +335,11 @@ public: mScrollView.ScrollStartedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollStarted ); mScrollView.ScrollCompletedSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollCompleted ); - mScrollView.EnableScrollComponent( Scrollable::VerticalScrollBar ); - mScrollView.EnableScrollComponent( Scrollable::HorizontalScrollBar ); - mScrollView.SetAnchorPoint(AnchorPoint::CENTER); mScrollView.SetParentOrigin(ParentOrigin::CENTER); - mScrollView.SetSize( stageSize );//Vector2( stageSize.width, fieldHeight ) );//stageSize ); + mScrollView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mScrollView.SetAxisAutoLock( true ); mScrollView.SetAxisAutoLockGradient( 1.0f ); @@ -351,7 +349,7 @@ public: rulerX->SetDomain( RulerDomain( stageSize.width * -0.125f, stageSize.width * 1.125f ) ); //< Scroll slightly left/right of image field. mScrollView.SetRulerX ( rulerX ); - RulerPtr rulerY = new DefaultRuler(); //stageSize.height ); //< Snap in multiples of a screen / stage height + RulerPtr rulerY = new DefaultRuler(); //< Snap in multiples of a screen / stage height rulerY->SetDomain( RulerDomain( - fieldHeight * 0.5f + stageSize.height * 0.5f - GRID_CELL_PADDING, fieldHeight * 0.5f + stageSize.height * 0.5f + GRID_CELL_PADDING ) ); mScrollView.SetRulerY ( rulerY ); @@ -359,8 +357,31 @@ public: mScrollView.Add( imageField ); mGridActor = imageField; + // Create the scroll bar + mScrollBarVertical = ScrollBar::New(Toolkit::ScrollBar::Vertical); + mScrollBarVertical.SetParentOrigin(ParentOrigin::TOP_RIGHT); + mScrollBarVertical.SetAnchorPoint(AnchorPoint::TOP_RIGHT); + mScrollBarVertical.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT); + mScrollBarVertical.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::WIDTH); + mScrollView.Add(mScrollBarVertical); + + mScrollBarHorizontal = ScrollBar::New(Toolkit::ScrollBar::Horizontal); + mScrollBarHorizontal.SetParentOrigin(ParentOrigin::BOTTOM_LEFT); + mScrollBarHorizontal.SetAnchorPoint(AnchorPoint::TOP_LEFT); + mScrollBarHorizontal.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::WIDTH); + mScrollBarHorizontal.SetOrientation(Quaternion(Radian( 1.5f * Math::PI ), Vector3::ZAXIS)); + mScrollView.Add(mScrollBarHorizontal); + + mScrollView.OnRelayoutSignal().Connect( this, &ImageScalingIrregularGridController::OnScrollViewRelayout ); + // Scroll to top of grid so first images loaded are on-screen: - mScrollView.ScrollTo( Vector3( 0, -1000000, 0 ) ); + mScrollView.ScrollTo( Vector2( 0, -1000000 ) ); + } + + void OnScrollViewRelayout(Actor actor) + { + // Make the height of the horizontal scroll bar to be the same as the width of scroll view. + mScrollBarHorizontal.SetSize(Vector2(0.0f, mScrollView.GetRelayoutSize( Dimension::WIDTH) )); } /** @@ -549,7 +570,7 @@ public: * note this state (mScrolling = true) * @param[in] position Current Scroll Position */ - void OnScrollStarted( const Vector3& position ) + void OnScrollStarted( const Vector2& position ) { mScrolling = true; } @@ -559,7 +580,7 @@ public: * note this state (mScrolling = false). * @param[in] position Current Scroll Position */ - void OnScrollCompleted( const Vector3& position ) + void OnScrollCompleted( const Vector2& position ) { mScrolling = false; } @@ -573,6 +594,8 @@ private: TextLabel mTitleActor; ///< The Toolbar's Title. Actor mGridActor; ///< The container for the grid of images ScrollView mScrollView; ///< ScrollView UI Component + ScrollBar mScrollBarVertical; + ScrollBar mScrollBarHorizontal; bool mScrolling; ///< ScrollView scrolling state (true = scrolling, false = stationary) std::map mFittingModes; ///< Stores the current scaling mode of each image, keyed by image actor id. std::map mSizes; ///< Stores the current size of each image, keyed by image actor id. diff --git a/examples/scroll-view/scroll-view-example.cpp b/examples/scroll-view/scroll-view-example.cpp index f067d60..7f9ceea 100644 --- a/examples/scroll-view/scroll-view-example.cpp +++ b/examples/scroll-view/scroll-view-example.cpp @@ -630,7 +630,7 @@ private: * note this state (mScrolling = true) * @param[in] position Current Scroll Position */ - void OnScrollStarted( const Vector3& position ) + void OnScrollStarted( const Vector2& position ) { mScrolling = true; } @@ -640,7 +640,7 @@ private: * note this state (mScrolling = false) * @param[in] position Current Scroll Position */ - void OnScrollCompleted( const Vector3& position ) + void OnScrollCompleted( const Vector2& position ) { mScrolling = false; } -- 2.7.4