From cf4a459fd1449c6afe34464a69e2111975cc747d Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Wed, 18 Jun 2014 14:30:55 +0100 Subject: [PATCH] Notify ItemFactory when an item is removed from ItemView Change-Id: I0620a480d54d5fc78b7e032957f30829f5ae9feb Signed-off-by: Adeel Kazmi --- .../controls/scrollable/item-view/item-view-impl.cpp | 15 +++++++++++---- .../controls/scrollable/item-view/item-view-impl.h | 7 +++++++ .../controls/scrollable/item-view/item-factory.h | 10 +++++++++- 3 files changed, 27 insertions(+), 5 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 73a25ff..b8899de 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 @@ -585,7 +585,7 @@ void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSiz if (scrollAnimationNeeded) { RemoveAnimation(mScrollAnimation); - mScrollAnimation = Animation::New(mAnchoringDuration); + mScrollAnimation = Animation::New(durationSeconds); mScrollAnimation.AnimateTo( Property( mScrollPositionObject, ScrollConnector::SCROLL_POSITION ), firstItemScrollPosition, AlphaFunctions::EaseOut ); mScrollAnimation.AnimateTo( Property(self, mPropertyPosition), GetScrollPosition(firstItemScrollPosition, targetSize), AlphaFunctions::EaseOut ); mScrollAnimation.Play(); @@ -896,7 +896,8 @@ bool ItemView::RemoveActor(unsigned int itemId) if( removeIter != mItemPool.end() ) { - Self().Remove( removeIter->second ); + ReleaseActor(itemId, removeIter->second); + removed = true; // Adjust the remaining item IDs, for example if item 2 is removed: @@ -932,7 +933,7 @@ void ItemView::ReplaceItem( Item replacementItem, float durationSeconds ) const ItemPoolIter iter = mItemPool.find( replacementItem.first ); if( mItemPool.end() != iter ) { - Self().Remove( iter->second ); + ReleaseActor(iter->first, iter->second); iter->second = replacementItem.second; } else @@ -962,7 +963,7 @@ void ItemView::RemoveActorsOutsideRange( ItemRange range ) if( ! range.Within( current ) ) { - Self().Remove( iter->second ); + ReleaseActor(iter->first, iter->second); mItemPool.erase( iter++ ); // erase invalidates the return value of post-increment; iter remains valid } @@ -1037,6 +1038,12 @@ void ItemView::SetupActor( Item item, float durationSeconds ) } } +void ItemView::ReleaseActor( ItemId item, Actor actor ) +{ + Self().Remove( actor ); + mItemFactory.ItemReleased(item, actor); +} + ItemRange ItemView::GetItemRange(ItemLayout& layout, const Vector3& layoutSize, float layoutPosition, bool reserveExtra) { unsigned int itemCount = mItemFactory.GetNumberOfItems(); 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 bd143eb..62ba4df 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 @@ -325,6 +325,13 @@ private: */ void SetupActor( Item item, float durationSeconds ); + /** + * Remove the Actor from the ItemPool and notify the ItemFactory the actor has been released by ItemView. + * @param[in] item The ID for the item to be released. + * @param[in] actor The actor to be removed from ItemView. + */ + void ReleaseActor( ItemId item, Actor actor ); + private: // From CustomActorImpl /** diff --git a/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-factory.h b/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-factory.h index fa5db20..f08a7e6 100644 --- a/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-factory.h +++ b/capi/dali-toolkit/public-api/controls/scrollable/item-view/item-factory.h @@ -33,7 +33,7 @@ namespace Toolkit { /** - * @brief ItemFactory is an abstract interface for providing actors to ItemView. + * @brief ItemFactory is for providing actors to ItemView. * Each actor is identified by a unique ID, and has a linear order from 0 to GetNumberOfItems()-1. */ class ItemFactory @@ -60,6 +60,14 @@ public: * @return An actor, or an uninitialized pointer if the ID is out of range. */ virtual Actor NewItem(unsigned int itemId) = 0; + + /** + * @brief Notify the factory the actor representing the item is removed from ItemView. + * + * @param[in] itemId The ID of the released item. + * @param[in] actor The actor that represents the released item. + */ + virtual void ItemReleased(unsigned int itemId, Actor actor) {}; }; } // namespace Toolkit -- 2.7.4