From 8471101b42398b9b3892cd4fd3efb88127032bc1 Mon Sep 17 00:00:00 2001 From: Ferran Sole Date: Wed, 7 May 2014 13:31:42 +0100 Subject: [PATCH] Configurable anchor point and parent origin of the items in an ItemView control [Issue] N/A [Problem] ItemView set parent origin and anchor point of new items to the center [Cause] N/A [Solution] Added functions to set a different anchor point and parent origin --- .../scrollable/item-view/item-view-impl.cpp | 42 ++++++++++++++++++++-- .../controls/scrollable/item-view/item-view-impl.h | 24 +++++++++++++ .../controls/scrollable/item-view/item-view.cpp | 21 +++++++++++ .../controls/scrollable/item-view/item-view.h | 30 ++++++++++++++++ 4 files changed, 114 insertions(+), 3 deletions(-) diff --git a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp index 8bebcd5..93effd8 100644 --- a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp @@ -411,7 +411,9 @@ ItemView::ItemView(ItemFactory& factory) mIsFlicking(false), mGestureState(Gesture::Clear), mAddingItems(false), - mRefreshEnabled(true) + mRefreshEnabled(true), + mItemsParentOrigin( ParentOrigin::CENTER), + mItemsAnchorPoint( AnchorPoint::CENTER) { SetRequiresMouseWheelEvents(true); SetKeyboardNavigationSupport(true); @@ -1019,8 +1021,8 @@ void ItemView::AddNewActor( unsigned int itemId, float durationSeconds ) void ItemView::SetupActor( Item item, float durationSeconds ) { - item.second.SetParentOrigin( ParentOrigin::CENTER ); - item.second.SetAnchorPoint( AnchorPoint::CENTER ); + item.second.SetParentOrigin( mItemsParentOrigin ); + item.second.SetAnchorPoint( mItemsAnchorPoint ); if( mActiveLayout ) { @@ -1766,6 +1768,40 @@ void ItemView::AnimateScrollOvershoot(float overshootAmount, bool animateBack) mAnimatingOvershootOn = animatingOn; } +void ItemView::SetItemsParentOrigin( const Vector3& parentOrigin ) +{ + if( parentOrigin != mItemsParentOrigin ) + { + mItemsParentOrigin = parentOrigin; + for (ItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter) + { + iter->second.SetParentOrigin(parentOrigin); + } + } +} + +Vector3 ItemView::GetItemsParentOrigin() const +{ + return mItemsParentOrigin; +} + +void ItemView::SetItemsAnchorPoint( const Vector3& anchorPoint ) +{ + if( anchorPoint != mItemsAnchorPoint ) + { + mItemsAnchorPoint = anchorPoint; + for (ItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter) + { + iter->second.SetAnchorPoint(anchorPoint); + } + } +} + +Vector3 ItemView::GetItemsAnchorPoint() const +{ + return mItemsAnchorPoint; +} + } // namespace Internal } // namespace Toolkit diff --git a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h index d7e1340..242cf27 100644 --- a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h +++ b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h @@ -262,6 +262,27 @@ public: */ void DoRefresh(float currentLayoutPosition, bool cacheExtra); + + /** + * @copydoc Toolkit::ItemView::SetItemsParentOrigin + */ + void SetItemsParentOrigin( const Vector3& parentOrigin ); + + /** + * @copydoc Toolkit::ItemView::GetItemsParentOrigin + */ + Vector3 GetItemsParentOrigin() const; + + /** + * @copydoc Toolkit::ItemView::SetItemsAnchorPoint + */ + void SetItemsAnchorPoint( const Vector3& anchorPoint ); + + /** + * @copydoc Toolkit::ItemView::GetItemsAnchorPoint + */ + Vector3 GetItemsAnchorPoint() const; + private: /** @@ -564,6 +585,9 @@ private: Property::Index mPropertyScrollSpeed; ///< The current scroll speed of item view bool mRefreshEnabled; ///< Whether to refresh the cache automatically + + Vector3 mItemsParentOrigin; + Vector3 mItemsAnchorPoint; }; } // namespace Internal diff --git a/base/dali-toolkit/public-api/controls/scrollable/item-view/item-view.cpp b/base/dali-toolkit/public-api/controls/scrollable/item-view/item-view.cpp index d9f856e..c41fd61 100644 --- a/base/dali-toolkit/public-api/controls/scrollable/item-view/item-view.cpp +++ b/base/dali-toolkit/public-api/controls/scrollable/item-view/item-view.cpp @@ -227,6 +227,27 @@ void ItemView::ReplaceItems(const ItemContainer& replacementItems, float duratio GetImpl(*this).ReplaceItems( replacementItems, durationSeconds ); } + +void ItemView::SetItemsParentOrigin( const Vector3& parentOrigin ) +{ + GetImpl(*this).SetItemsParentOrigin( parentOrigin ); +} + +Vector3 ItemView::GetItemsParentOrigin() const +{ + return GetImpl(*this).GetItemsParentOrigin(); +} + +void ItemView::SetItemsAnchorPoint( const Vector3& anchorPoint ) +{ + GetImpl(*this).SetItemsAnchorPoint(anchorPoint); +} + +Vector3 ItemView::GetItemsAnchorPoint() const +{ + return GetImpl(*this).GetItemsAnchorPoint(); +} + } // namespace Toolkit } // namespace Dali diff --git a/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-view.h b/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-view.h index 82752b0..c8d101b 100644 --- a/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-view.h +++ b/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-view.h @@ -381,6 +381,36 @@ public: */ void ReplaceItems(const ItemContainer& replacementItems, float durationSeconds); + /** + * @brief Set the parent origin of the items + * + * A relayout will occur for all the items if the parent origin is different than the current one. + * @param[in] parentOrigin New parent origin position vector + */ + void SetItemsParentOrigin( const Vector3& parentOrigin ); + + /** + * @brief Get the parent origin of the items + * + * @return The current parent origin of the items + */ + Vector3 GetItemsParentOrigin() const; + + /** + * @brief Set the anchor point of the items + * + * A relayout will occur for all the items if the anchor point is different than the current one. + * @param[in] anchorPoint New anchor point position vector + */ + void SetItemsAnchorPoint( const Vector3& anchorPoint ); + + /** + * @brief Get the anchor point of the items + * + * @return The current anchor point of the items + */ + Vector3 GetItemsAnchorPoint() const; + public: // Not intended for application developers /** -- 2.7.4