X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fscrollable%2Fitem-view%2Fitem-view-impl.cpp;h=27054bd59a6ecd7bbaf5a1a7811959f81dd240cd;hp=ebe8f7776ad9cb42d709094d0798c57733f4d8f2;hb=9e56847af25f4bddb5a2484b724d1f9b6f401538;hpb=928136dbb9e23970f3894eabc7c8b224003b77be diff --git a/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp b/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp index ebe8f77..27054bd 100644 --- a/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp +++ b/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp @@ -19,57 +19,62 @@ #include // EXTERNAL INCLUDES +#include // for strcmp #include -#include #include #include -#include +#include #include -#include +#include #include #include +#include // INTERNAL INCLUDES +#include #include -#include #include using std::string; using std::set; using namespace Dali; -namespace // unnamed namespace +namespace // Unnamed namespace { //Type registration -TypeRegistration mType( typeid(Toolkit::ItemView), typeid(Toolkit::Scrollable), NULL ); + +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ItemView, Toolkit::Scrollable, NULL) + +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "layout-position", FLOAT, LAYOUT_POSITION) +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "scroll-speed", FLOAT, SCROLL_SPEED) +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "overshoot", FLOAT, OVERSHOOT) +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "scroll-direction", VECTOR2, SCROLL_DIRECTION) +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "layout-orientation", INTEGER, LAYOUT_ORIENTATION) +DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "scroll-content-size", FLOAT, SCROLL_CONTENT_SIZE) + +DALI_SIGNAL_REGISTRATION( Toolkit, ItemView, "layout-activated", LAYOUT_ACTIVATED_SIGNAL ) + +DALI_TYPE_REGISTRATION_END() const float DEFAULT_MINIMUM_SWIPE_SPEED = 1.0f; const float DEFAULT_MINIMUM_SWIPE_DISTANCE = 3.0f; -const float DEFAULT_MOUSE_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION = 0.1f; +const float DEFAULT_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION = 0.1f; const float DEFAULT_MINIMUM_SWIPE_DURATION = 0.45f; const float DEFAULT_MAXIMUM_SWIPE_DURATION = 2.6f; const float DEFAULT_REFRESH_INTERVAL_LAYOUT_POSITIONS = 20.0f; // 1 updates per 20 items -const int MOUSE_WHEEL_EVENT_FINISHED_TIME_OUT = 500; // 0.5 second +const int WHEEL_EVENT_FINISHED_TIME_OUT = 500; // 0.5 second const float DEFAULT_ANCHORING_DURATION = 1.0f; // 1 second const float MILLISECONDS_PER_SECONDS = 1000.0f; -const Vector2 OVERSHOOT_BOUNCE_ACTOR_DEFAULT_SIZE( 720.0f, 42.0f ); const float OVERSHOOT_BOUNCE_ACTOR_RESIZE_THRESHOLD = 180.0f; const Vector4 OVERSHOOT_OVERLAY_NINE_PATCH_BORDER(0.0f, 0.0f, 1.0f, 12.0f); const float DEFAULT_KEYBOARD_FOCUS_SCROLL_DURATION = 0.2f; -const string LAYOUT_POSITION_PROPERTY_NAME( "item-view-layout-position" ); -const string POSITION_PROPERTY_NAME( "item-view-position" ); -const string MINIMUM_LAYOUT_POSITION_PROPERTY_NAME( "item-view-minimum-layout-position" ); -const string SCROLL_SPEED_PROPERTY_NAME( "item-view-scroll-speed" ); -const string SCROLL_DIRECTION_PROPERTY_NAME( "item-view-scroll-direction" ); -const string OVERSHOOT_PROPERTY_NAME( "item-view-overshoot" ); - /** * Local helper to convert pan distance (in actor coordinates) to the layout-specific scrolling direction */ @@ -84,201 +89,157 @@ float CalculateScrollDistance(Vector2 panDistance, Toolkit::ItemLayout& layout) } // Overshoot overlay constraints - struct OvershootOverlaySizeConstraint { - Vector3 operator()(const Vector3& current, - const PropertyInput& parentScrollDirectionProperty, - const PropertyInput& parentOvershootProperty, - const PropertyInput& parentSizeProperty) + OvershootOverlaySizeConstraint( float height ) + : mOvershootHeight( height ) { - const Vector3 parentScrollDirection = parentScrollDirectionProperty.GetVector3(); - const Vector3 parentSize = parentSizeProperty.GetVector3(); - const Toolkit::ControlOrientation::Type& parentOrientation = static_cast(parentScrollDirection.z); + } - float overlayWidth; + void operator()( Vector3& current, const PropertyInputContainer& inputs ) + { + const Vector2& parentScrollDirection = inputs[0]->GetVector2(); + const Toolkit::ControlOrientation::Type& layoutOrientation = static_cast(inputs[1]->GetInteger()); + const Vector3& parentSize = inputs[2]->GetVector3(); - if(Toolkit::IsVertical(parentOrientation)) + if(Toolkit::IsVertical(layoutOrientation)) { - overlayWidth = fabsf(parentScrollDirection.y) > Math::MACHINE_EPSILON_1 ? parentSize.x : parentSize.y; + current.width = fabsf(parentScrollDirection.y) > Math::MACHINE_EPSILON_1 ? parentSize.x : parentSize.y; } else { - overlayWidth = fabsf(parentScrollDirection.x) > Math::MACHINE_EPSILON_1 ? parentSize.y : parentSize.x; + current.width = fabsf(parentScrollDirection.x) > Math::MACHINE_EPSILON_1 ? parentSize.y : parentSize.x; } - float overlayHeight = (overlayWidth > OVERSHOOT_BOUNCE_ACTOR_RESIZE_THRESHOLD) ? OVERSHOOT_BOUNCE_ACTOR_DEFAULT_SIZE.height : OVERSHOOT_BOUNCE_ACTOR_DEFAULT_SIZE.height*0.5f; - - return Vector3( overlayWidth, overlayHeight, current.depth ); + current.height = ( current.width > OVERSHOOT_BOUNCE_ACTOR_RESIZE_THRESHOLD ) ? mOvershootHeight : mOvershootHeight*0.5f; } + + float mOvershootHeight; }; -struct OvershootOverlayRotationConstraint +void OvershootOverlayRotationConstraint( Quaternion& current, const PropertyInputContainer& inputs ) { - Quaternion operator()(const Quaternion& current, - const PropertyInput& parentScrollDirectionProperty, - const PropertyInput& parentOvershootProperty) - { - const Vector3 parentScrollDirection = parentScrollDirectionProperty.GetVector3(); - const float parentOvershoot = parentOvershootProperty.GetFloat(); - const Toolkit::ControlOrientation::Type& parentOrientation = static_cast(parentScrollDirection.z); - - Quaternion rotation; + const Vector2& parentScrollDirection = inputs[0]->GetVector2(); + const Toolkit::ControlOrientation::Type& layoutOrientation = static_cast(inputs[1]->GetInteger()); + const float parentOvershoot = inputs[2]->GetFloat(); - if(Toolkit::IsVertical(parentOrientation)) + float multiplier = 0; + if(Toolkit::IsVertical(layoutOrientation)) + { + if(fabsf(parentScrollDirection.y) <= Math::MACHINE_EPSILON_1) { - if(fabsf(parentScrollDirection.y) <= Math::MACHINE_EPSILON_1) - { - if( (parentOrientation == Toolkit::ControlOrientation::Up && parentOvershoot < Math::MACHINE_EPSILON_0) - || (parentOrientation == Toolkit::ControlOrientation::Down && parentOvershoot > Math::MACHINE_EPSILON_0) ) - { - rotation = Quaternion(0.5f * Math::PI, Vector3::ZAXIS); - } - else - { - rotation = Quaternion(1.5f * Math::PI, Vector3::ZAXIS); - } - } - else if( (parentOvershoot > Math::MACHINE_EPSILON_0 && parentScrollDirection.y > Math::MACHINE_EPSILON_0) - || (parentOvershoot < Math::MACHINE_EPSILON_0 && parentScrollDirection.y < Math::MACHINE_EPSILON_0) ) + if( (layoutOrientation == Toolkit::ControlOrientation::Up && parentOvershoot < Math::MACHINE_EPSILON_0) + || (layoutOrientation == Toolkit::ControlOrientation::Down && parentOvershoot > Math::MACHINE_EPSILON_0) ) { - rotation = Quaternion(0.0f, Vector3::ZAXIS); + multiplier = 0.5f; } else { - rotation = Quaternion(Math::PI, Vector3::ZAXIS); + multiplier = 1.5f; } } + else if( (parentOvershoot > Math::MACHINE_EPSILON_0 && parentScrollDirection.y > Math::MACHINE_EPSILON_0) + || (parentOvershoot < Math::MACHINE_EPSILON_0 && parentScrollDirection.y < Math::MACHINE_EPSILON_0) ) + { + multiplier = 0.0f; + } else { - if(fabsf(parentScrollDirection.x) <= Math::MACHINE_EPSILON_1) - { - if( (parentOrientation == Toolkit::ControlOrientation::Left && parentOvershoot > Math::MACHINE_EPSILON_0) - ||(parentOrientation == Toolkit::ControlOrientation::Right && parentOvershoot < Math::MACHINE_EPSILON_0) ) - { - rotation = Quaternion(Math::PI, Vector3::ZAXIS); - } - else - { - rotation = Quaternion(0.0f, Vector3::ZAXIS); - } - } - else if( (parentOvershoot > Math::MACHINE_EPSILON_0 && parentScrollDirection.x > Math::MACHINE_EPSILON_0) - || (parentOvershoot < Math::MACHINE_EPSILON_0 && parentScrollDirection.x < Math::MACHINE_EPSILON_0) ) + multiplier = 1.0f; + } + } + else + { + if(fabsf(parentScrollDirection.x) <= Math::MACHINE_EPSILON_1) + { + if( (layoutOrientation == Toolkit::ControlOrientation::Left && parentOvershoot > Math::MACHINE_EPSILON_0) + ||(layoutOrientation == Toolkit::ControlOrientation::Right && parentOvershoot < Math::MACHINE_EPSILON_0) ) { - rotation = Quaternion(1.5f * Math::PI, Vector3::ZAXIS); + multiplier = 1.0f; } else { - rotation = Quaternion(0.5f * Math::PI, Vector3::ZAXIS); + multiplier = 0.0f; } } - - return rotation; + else if( (parentOvershoot > Math::MACHINE_EPSILON_0 && parentScrollDirection.x > Math::MACHINE_EPSILON_0) + || (parentOvershoot < Math::MACHINE_EPSILON_0 && parentScrollDirection.x < Math::MACHINE_EPSILON_0) ) + { + multiplier = 1.5f; + } + else + { + multiplier = 0.5f; + } } -}; -struct OvershootOverlayPositionConstraint + current = Quaternion( Radian( multiplier * Math::PI ), Vector3::ZAXIS ); +} + +void OvershootOverlayPositionConstraint( Vector3& current, const PropertyInputContainer& inputs ) { - Vector3 operator()(const Vector3& current, - const PropertyInput& parentSizeProperty, - const PropertyInput& parentScrollDirectionProperty, - const PropertyInput& parentOvershootProperty) - { - const Vector3 parentScrollDirection = parentScrollDirectionProperty.GetVector3(); - const float parentOvershoot = parentOvershootProperty.GetFloat(); - const Vector3 parentSize = parentSizeProperty.GetVector3(); - const Toolkit::ControlOrientation::Type& parentOrientation = static_cast(parentScrollDirection.z); + const Vector3& parentSize = inputs[0]->GetVector3(); + const Vector2& parentScrollDirection = inputs[1]->GetVector2(); + const Toolkit::ControlOrientation::Type& layoutOrientation = static_cast(inputs[2]->GetInteger()); + const float parentOvershoot = inputs[3]->GetFloat(); - Vector3 relativeOffset; + Vector3 relativeOffset; - if(Toolkit::IsVertical(parentOrientation)) + if(Toolkit::IsVertical(layoutOrientation)) + { + if(fabsf(parentScrollDirection.y) <= Math::MACHINE_EPSILON_1) { - if(fabsf(parentScrollDirection.y) <= Math::MACHINE_EPSILON_1) + if( (layoutOrientation == Toolkit::ControlOrientation::Up && parentOvershoot < Math::MACHINE_EPSILON_0) + || (layoutOrientation == Toolkit::ControlOrientation::Down && parentOvershoot > Math::MACHINE_EPSILON_0) ) { - if( (parentOrientation == Toolkit::ControlOrientation::Up && parentOvershoot < Math::MACHINE_EPSILON_0) - || (parentOrientation == Toolkit::ControlOrientation::Down && parentOvershoot > Math::MACHINE_EPSILON_0) ) - { - relativeOffset = Vector3(1.0f, 0.0f, 0.0f); - } - else - { - relativeOffset =Vector3(0.0f, 1.0f, 0.0f); - } - } - else if( (parentOvershoot > Math::MACHINE_EPSILON_0 && parentScrollDirection.y > Math::MACHINE_EPSILON_0) - || (parentOvershoot < Math::MACHINE_EPSILON_0 && parentScrollDirection.y < Math::MACHINE_EPSILON_0) ) - { - relativeOffset = Vector3(0.0f, 0.0f, 0.0f); + relativeOffset = Vector3(1.0f, 0.0f, 0.0f); } else { - relativeOffset = Vector3(1.0f, 1.0f, 0.0f); + relativeOffset =Vector3(0.0f, 1.0f, 0.0f); } } + else if( (parentOvershoot > Math::MACHINE_EPSILON_0 && parentScrollDirection.y > Math::MACHINE_EPSILON_0) + || (parentOvershoot < Math::MACHINE_EPSILON_0 && parentScrollDirection.y < Math::MACHINE_EPSILON_0) ) + { + relativeOffset = Vector3(0.0f, 0.0f, 0.0f); + } else { - if(fabsf(parentScrollDirection.x) <= Math::MACHINE_EPSILON_1) - { - if( (parentOrientation == Toolkit::ControlOrientation::Left && parentOvershoot < Math::MACHINE_EPSILON_0) - || (parentOrientation == Toolkit::ControlOrientation::Right && parentOvershoot > Math::MACHINE_EPSILON_0) ) - { - relativeOffset = Vector3(0.0f, 0.0f, 0.0f); - } - else - { - relativeOffset = Vector3(1.0f, 1.0f, 0.0f); - } - } - else if( (parentOvershoot > Math::MACHINE_EPSILON_0 && parentScrollDirection.x > Math::MACHINE_EPSILON_0) - || (parentOvershoot < Math::MACHINE_EPSILON_0 && parentScrollDirection.x < Math::MACHINE_EPSILON_0) ) + relativeOffset = Vector3(1.0f, 1.0f, 0.0f); + } + } + else + { + if(fabsf(parentScrollDirection.x) <= Math::MACHINE_EPSILON_1) + { + if( (layoutOrientation == Toolkit::ControlOrientation::Left && parentOvershoot < Math::MACHINE_EPSILON_0) + || (layoutOrientation == Toolkit::ControlOrientation::Right && parentOvershoot > Math::MACHINE_EPSILON_0) ) { - relativeOffset = Vector3(0.0f, 1.0f, 0.0f); + relativeOffset = Vector3(0.0f, 0.0f, 0.0f); } else { - relativeOffset = Vector3(1.0f, 0.0f, 0.0f); + relativeOffset = Vector3(1.0f, 1.0f, 0.0f); } } - - return relativeOffset * parentSize; - + else if( (parentOvershoot > Math::MACHINE_EPSILON_0 && parentScrollDirection.x > Math::MACHINE_EPSILON_0) + || (parentOvershoot < Math::MACHINE_EPSILON_0 && parentScrollDirection.x < Math::MACHINE_EPSILON_0) ) + { + relativeOffset = Vector3(0.0f, 1.0f, 0.0f); + } + else + { + relativeOffset = Vector3(1.0f, 0.0f, 0.0f); + } } -}; -struct OvershootOverlayVisibilityConstraint -{ - bool operator()(const bool& current, - const PropertyInput& parentLayoutScrollableProperty) - { - const bool parentLayoutScrollable = parentLayoutScrollableProperty.GetBoolean(); - - return parentLayoutScrollable; - } -}; + current = relativeOffset * parentSize; +} -/** - * Relative position Constraint - * Generates the relative position value of the item view based on the layout position, - * and it's relation to the layout domain. This is a value from 0.0f to 1.0f in each axis. - */ -Vector3 RelativePositionConstraint(const Vector3& current, - const PropertyInput& scrollPositionProperty, - const PropertyInput& scrollMinProperty, - const PropertyInput& scrollMaxProperty, - const PropertyInput& layoutSizeProperty) +void OvershootOverlayVisibilityConstraint( bool& current, const PropertyInputContainer& inputs ) { - const Vector3& position = Vector3(0.0f, scrollPositionProperty.GetFloat(), 0.0f); - const Vector3& min = scrollMinProperty.GetVector3(); - const Vector3& max = scrollMaxProperty.GetVector3(); - - Vector3 relativePosition; - Vector3 domainSize = max - min; - - relativePosition.x = fabsf(domainSize.x) > Math::MACHINE_EPSILON_1 ? ((min.x - position.x) / fabsf(domainSize.x)) : 0.0f; - relativePosition.y = fabsf(domainSize.y) > Math::MACHINE_EPSILON_1 ? ((min.y - position.y) / fabsf(domainSize.y)) : 0.0f; - - return relativePosition; + current = inputs[0]->GetBoolean(); } } // unnamed namespace @@ -326,18 +287,18 @@ Dali::Toolkit::ItemView ItemView::New(ItemFactory& factory) } ItemView::ItemView(ItemFactory& factory) -: Scrollable(), +: Scrollable( ControlBehaviour( DISABLE_SIZE_NEGOTIATION | REQUIRES_WHEEL_EVENTS | REQUIRES_KEYBOARD_NAVIGATION_SUPPORT ) ), mItemFactory(factory), mActiveLayout(NULL), mAnimatingOvershootOn(false), mAnimateOvershootOff(false), - mAnchoringEnabled(true), + mAnchoringEnabled(false), mAnchoringDuration(DEFAULT_ANCHORING_DURATION), mRefreshIntervalLayoutPositions(0.0f), mRefreshOrderHint(true/*Refresh item 0 first*/), mMinimumSwipeSpeed(DEFAULT_MINIMUM_SWIPE_SPEED), mMinimumSwipeDistance(DEFAULT_MINIMUM_SWIPE_DISTANCE), - mMouseWheelScrollDistanceStep(0.0f), + mWheelScrollDistanceStep(0.0f), mScrollDistance(0.0f), mScrollSpeed(0.0f), mTotalPanDisplacement(Vector2::ZERO), @@ -345,50 +306,23 @@ ItemView::ItemView(ItemFactory& factory) mIsFlicking(false), mGestureState(Gesture::Clear), mAddingItems(false), - mPropertyPosition(Property::INVALID_INDEX), - mPropertyMinimumLayoutPosition(Property::INVALID_INDEX), - mPropertyScrollSpeed(Property::INVALID_INDEX), mRefreshEnabled(true), mItemsParentOrigin( ParentOrigin::CENTER), mItemsAnchorPoint( AnchorPoint::CENTER) { - SetRequiresMouseWheelEvents(true); - SetKeyboardNavigationSupport(true); } void ItemView::OnInitialize() { - SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed ); - - RegisterCommonProperties(); - Actor self = Self(); - mScrollConnector = Dali::Toolkit::ScrollConnector::New(); - mScrollPositionObject = mScrollConnector.GetScrollPositionObject(); - mScrollConnector.ScrollPositionChangedSignal().Connect( this, &ItemView::OnScrollPositionChanged ); - - mPropertyMinimumLayoutPosition = self.RegisterProperty(MINIMUM_LAYOUT_POSITION_PROPERTY_NAME, 0.0f); - mPropertyPosition = self.RegisterProperty(POSITION_PROPERTY_NAME, 0.0f); - mPropertyScrollSpeed = self.RegisterProperty(SCROLL_SPEED_PROPERTY_NAME, 0.0f); - - EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator); - - Constraint constraint = Constraint::New(mPropertyRelativePosition, - LocalSource(mPropertyPosition), - LocalSource(mPropertyPositionMin), - LocalSource(mPropertyPositionMax), - LocalSource(Actor::Property::Size), - RelativePositionConstraint); - self.ApplyConstraint(constraint); - Vector2 stageSize = Stage::GetCurrent().GetSize(); - mMouseWheelScrollDistanceStep = stageSize.y * DEFAULT_MOUSE_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION; + mWheelScrollDistanceStep = stageSize.y * DEFAULT_WHEEL_SCROLL_DISTANCE_STEP_PROPORTION; EnableGestureDetection(Gesture::Type(Gesture::Pan)); - mMouseWheelEventFinishedTimer = Timer::New( MOUSE_WHEEL_EVENT_FINISHED_TIME_OUT ); - mMouseWheelEventFinishedTimer.TickSignal().Connect( this, &ItemView::OnMouseWheelEventFinished ); + mWheelEventFinishedTimer = Timer::New( WHEEL_EVENT_FINISHED_TIME_OUT ); + mWheelEventFinishedTimer.TickSignal().Connect( this, &ItemView::OnWheelEventFinished ); SetRefreshInterval(DEFAULT_REFRESH_INTERVAL_LAYOUT_POSITIONS); } @@ -397,11 +331,6 @@ ItemView::~ItemView() { } -Dali::Toolkit::ScrollConnector ItemView::GetScrollConnector() const -{ - return mScrollConnector; -} - unsigned int ItemView::GetLayoutCount() const { return mLayouts.size(); @@ -436,7 +365,7 @@ ItemLayoutPtr ItemView::GetActiveLayout() const float ItemView::GetCurrentLayoutPosition(unsigned int itemId) const { - return mScrollConnector.GetScrollPosition() + static_cast( itemId ); + return Self().GetProperty( Toolkit::ItemView::Property::LAYOUT_POSITION ) + static_cast( itemId ); } void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSize, float durationSeconds) @@ -456,7 +385,6 @@ void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSiz // Move the items to the new layout positions... - bool resizeAnimationNeeded(false); for (ConstItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter) { unsigned int itemId = iter->first; @@ -466,39 +394,15 @@ void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSiz actor.RemoveConstraints(); Vector3 size; - if(mActiveLayout->GetItemSize(itemId, targetSize, size)) - { - if( durationSeconds > 0.0f ) - { - // Use a size animation - if (!resizeAnimationNeeded) - { - resizeAnimationNeeded = true; - RemoveAnimation(mResizeAnimation); - mResizeAnimation = Animation::New(durationSeconds); - } + mActiveLayout->GetItemSize( itemId, targetSize, size ); + actor.SetSize( size.GetVectorXY() ); - // The layout provides its own resize animation - mActiveLayout->GetResizeAnimation(mResizeAnimation, actor, size, durationSeconds); - } - else - { - // resize immediately - actor.SetSize(size); - } - } - - mActiveLayout->ApplyConstraints(actor, itemId, durationSeconds, mScrollPositionObject, Self() ); - } - - if (resizeAnimationNeeded) - { - mResizeAnimation.Play(); + mActiveLayout->ApplyConstraints(actor, itemId, targetSize, Self() ); } // Refresh the new layout ItemRange range = GetItemRange(*mActiveLayout, targetSize, GetCurrentLayoutPosition(0), false/* don't reserve extra*/); - AddActorsWithinRange( range, durationSeconds ); + AddActorsWithinRange( range, targetSize ); // Scroll to an appropriate layout position @@ -507,7 +411,6 @@ void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSiz float current = GetCurrentLayoutPosition(0); float minimum = ClampFirstItemPosition(current, targetSize, *mActiveLayout); - self.SetProperty(mPropertyPosition, GetScrollPosition(current, targetSize)); if (current < minimum) { @@ -524,21 +427,23 @@ void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSiz { RemoveAnimation(mScrollAnimation); 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.AnimateTo( Property(self, Toolkit::ItemView::Property::LAYOUT_POSITION), firstItemScrollPosition, AlphaFunction::EASE_OUT ); mScrollAnimation.FinishedSignal().Connect(this, &ItemView::OnLayoutActivationScrollFinished); mScrollAnimation.Play(); } + else + { + // Emit the layout activated signal + mLayoutActivatedSignal.Emit(); + } - self.SetProperty(mPropertyMinimumLayoutPosition, mActiveLayout->GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), targetSize)); AnimateScrollOvershoot(0.0f); mScrollOvershoot = 0.0f; Radian scrollDirection(mActiveLayout->GetScrollDirection()); - float orientation = static_cast(mActiveLayout->GetOrientation()); - self.SetProperty(mPropertyScrollDirection, Vector3(sinf(scrollDirection), cosf(scrollDirection), orientation)); - - self.SetProperty(mPropertyScrollSpeed, mScrollSpeed); + self.SetProperty(Toolkit::ItemView::Property::SCROLL_DIRECTION, Vector2(sinf(scrollDirection), cosf(scrollDirection))); + self.SetProperty(Toolkit::ItemView::Property::LAYOUT_ORIENTATION, static_cast(mActiveLayout->GetOrientation())); + self.SetProperty(Toolkit::ItemView::Property::SCROLL_SPEED, mScrollSpeed); CalculateDomainSize(targetSize); } @@ -559,11 +464,25 @@ void ItemView::DeactivateCurrentLayout() void ItemView::OnRefreshNotification(PropertyNotification& source) { - if(mRefreshEnabled || mScrollAnimation) + // Cancel scroll animation to prevent any fighting of setting the scroll position property by scroll bar during fast scroll. + if(!mRefreshEnabled && mScrollAnimation) { - // Only refresh the cache during normal scrolling - DoRefresh(GetCurrentLayoutPosition(0), true); + RemoveAnimation(mScrollAnimation); + } + + // Only cache extra items when it is not a fast scroll + DoRefresh(GetCurrentLayoutPosition(0), mRefreshEnabled || mScrollAnimation); +} + +void ItemView::Refresh() +{ + for (ItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter ) + { + ReleaseActor( iter->first, iter->second ); } + mItemPool.clear(); + + DoRefresh(GetCurrentLayoutPosition(0), true); } void ItemView::DoRefresh(float currentLayoutPosition, bool cacheExtra) @@ -572,9 +491,9 @@ void ItemView::DoRefresh(float currentLayoutPosition, bool cacheExtra) { ItemRange range = GetItemRange(*mActiveLayout, mActiveLayoutTargetSize, currentLayoutPosition, cacheExtra/*reserve extra*/); RemoveActorsOutsideRange( range ); - AddActorsWithinRange( range, 0.0f/*immediate*/ ); + AddActorsWithinRange( range, Self().GetCurrentSize() ); - mScrollUpdatedSignal.Emit( Vector3(0.0f, currentLayoutPosition, 0.0f) ); + mScrollUpdatedSignal.Emit( Vector2(0.0f, currentLayoutPosition) ); } } @@ -598,14 +517,14 @@ float ItemView::GetMinimumSwipeDistance() const return mMinimumSwipeDistance; } -void ItemView::SetMouseWheelScrollDistanceStep(float step) +void ItemView::SetWheelScrollDistanceStep(float step) { - mMouseWheelScrollDistanceStep = step; + mWheelScrollDistanceStep = step; } -float ItemView::GetMouseWheelScrollDistanceStep() const +float ItemView::GetWheelScrollDistanceStep() const { - return mMouseWheelScrollDistanceStep; + return mWheelScrollDistanceStep; } void ItemView::SetAnchoring(bool enabled) @@ -634,11 +553,12 @@ void ItemView::SetRefreshInterval(float intervalLayoutPositions) { mRefreshIntervalLayoutPositions = intervalLayoutPositions; + Actor self = Self(); if(mRefreshNotification) { - mScrollPositionObject.RemovePropertyNotification(mRefreshNotification); + self.RemovePropertyNotification(mRefreshNotification); } - mRefreshNotification = mScrollPositionObject.AddPropertyNotification( ScrollConnector::SCROLL_POSITION, StepCondition(mRefreshIntervalLayoutPositions, 0.0f) ); + mRefreshNotification = self.AddPropertyNotification( Toolkit::ItemView::Property::LAYOUT_POSITION, StepCondition(mRefreshIntervalLayoutPositions, 0.0f) ); mRefreshNotification.NotifySignal().Connect( this, &ItemView::OnRefreshNotification ); } } @@ -685,6 +605,7 @@ unsigned int ItemView::GetItemId( Actor actor ) const void ItemView::InsertItem( Item newItem, float durationSeconds ) { mAddingItems = true; + Vector3 layoutSize = Self().GetCurrentSize(); Actor displacedActor; ItemPoolIter afterDisplacedIter = mItemPool.end(); @@ -692,7 +613,7 @@ void ItemView::InsertItem( Item newItem, float durationSeconds ) ItemPoolIter foundIter = mItemPool.find( newItem.first ); if( mItemPool.end() != foundIter ) { - SetupActor( newItem, durationSeconds ); + SetupActor( newItem, layoutSize ); Self().Add( newItem.second ); displacedActor = foundIter->second; @@ -724,7 +645,7 @@ void ItemView::InsertItem( Item newItem, float durationSeconds ) displacedActor = temp; iter->second.RemoveConstraints(); - mActiveLayout->ApplyConstraints( iter->second, iter->first, durationSeconds, mScrollPositionObject, Self() ); + mActiveLayout->ApplyConstraints( iter->second, iter->first, layoutSize, Self() ); } // Create last item @@ -736,11 +657,11 @@ void ItemView::InsertItem( Item newItem, float durationSeconds ) mItemPool.insert( lastItem ); lastItem.second.RemoveConstraints(); - mActiveLayout->ApplyConstraints( lastItem.second, lastItem.first, durationSeconds, mScrollPositionObject, Self() ); + mActiveLayout->ApplyConstraints( lastItem.second, lastItem.first, layoutSize, Self() ); } } - CalculateDomainSize(Self().GetCurrentSize()); + CalculateDomainSize( layoutSize ); mAddingItems = false; } @@ -748,6 +669,7 @@ void ItemView::InsertItem( Item newItem, float durationSeconds ) void ItemView::InsertItems( const ItemContainer& newItems, float durationSeconds ) { mAddingItems = true; + Vector3 layoutSize = Self().GetCurrentSize(); // Insert from lowest id to highest std::set sortedItems; @@ -791,16 +713,16 @@ void ItemView::InsertItems( const ItemContainer& newItems, float durationSeconds // If newly inserted if( FindById( newItems, iter->first ) ) { - SetupActor( *iter, durationSeconds ); + SetupActor( *iter, layoutSize ); } else { iter->second.RemoveConstraints(); - mActiveLayout->ApplyConstraints( iter->second, iter->first, durationSeconds, mScrollPositionObject, Self() ); + mActiveLayout->ApplyConstraints( iter->second, iter->first, layoutSize, Self() ); } } - CalculateDomainSize(Self().GetCurrentSize()); + CalculateDomainSize( layoutSize ); mAddingItems = false; } @@ -810,7 +732,7 @@ void ItemView::RemoveItem( unsigned int itemId, float durationSeconds ) bool actorsReordered = RemoveActor( itemId ); if( actorsReordered ) { - ReapplyAllConstraints( durationSeconds ); + ReapplyAllConstraints(); OnItemsRemoved(); } @@ -837,7 +759,7 @@ void ItemView::RemoveItems( const ItemIdContainer& itemIds, float durationSecond if( actorsReordered ) { - ReapplyAllConstraints( durationSeconds ); + ReapplyAllConstraints(); OnItemsRemoved(); } @@ -896,8 +818,9 @@ bool ItemView::RemoveActor(unsigned int itemId) void ItemView::ReplaceItem( Item replacementItem, float durationSeconds ) { mAddingItems = true; + Vector3 layoutSize = Self().GetCurrentSize(); - SetupActor( replacementItem, durationSeconds ); + SetupActor( replacementItem, layoutSize ); Self().Add( replacementItem.second ); const ItemPoolIter iter = mItemPool.find( replacementItem.first ); @@ -911,7 +834,7 @@ void ItemView::ReplaceItem( Item replacementItem, float durationSeconds ) mItemPool.insert( replacementItem ); } - CalculateDomainSize(Self().GetCurrentSize()); + CalculateDomainSize( layoutSize ); mAddingItems = false; } @@ -944,7 +867,7 @@ void ItemView::RemoveActorsOutsideRange( ItemRange range ) } } -void ItemView::AddActorsWithinRange( ItemRange range, float durationSeconds ) +void ItemView::AddActorsWithinRange( ItemRange range, const Vector3& layoutSize ) { range.end = std::min(mItemFactory.GetNumberOfItems(), range.end); @@ -953,14 +876,14 @@ void ItemView::AddActorsWithinRange( ItemRange range, float durationSeconds ) { for (unsigned int itemId = range.begin; itemId < range.end; ++itemId) { - AddNewActor( itemId, durationSeconds ); + AddNewActor( itemId, layoutSize ); } } else { for (unsigned int itemId = range.end; itemId > range.begin; --itemId) { - AddNewActor( itemId-1, durationSeconds ); + AddNewActor( itemId-1, layoutSize ); } } @@ -969,7 +892,7 @@ void ItemView::AddActorsWithinRange( ItemRange range, float durationSeconds ) CalculateDomainSize(Self().GetCurrentSize()); } -void ItemView::AddNewActor( unsigned int itemId, float durationSeconds ) +void ItemView::AddNewActor( unsigned int itemId, const Vector3& layoutSize ) { mAddingItems = true; @@ -983,7 +906,7 @@ void ItemView::AddNewActor( unsigned int itemId, float durationSeconds ) mItemPool.insert( newItem ); - SetupActor( newItem, durationSeconds ); + SetupActor( newItem, layoutSize ); Self().Add( actor ); } } @@ -991,7 +914,7 @@ void ItemView::AddNewActor( unsigned int itemId, float durationSeconds ) mAddingItems = false; } -void ItemView::SetupActor( Item item, float durationSeconds ) +void ItemView::SetupActor( Item item, const Vector3& layoutSize ) { item.second.SetParentOrigin( mItemsParentOrigin ); item.second.SetAnchorPoint( mItemsAnchorPoint ); @@ -999,12 +922,10 @@ void ItemView::SetupActor( Item item, float durationSeconds ) if( mActiveLayout ) { Vector3 size; - if( mActiveLayout->GetItemSize( item.first, mActiveLayoutTargetSize, size ) ) - { - item.second.SetSize( size ); - } + mActiveLayout->GetItemSize( item.first, mActiveLayoutTargetSize, size ); + item.second.SetSize( size.GetVectorXY() ); - mActiveLayout->ApplyConstraints( item.second, item.first, durationSeconds, mScrollPositionObject, Self() ); + mActiveLayout->ApplyConstraints( item.second, item.first, layoutSize, Self() ); } } @@ -1038,11 +959,14 @@ void ItemView::OnChildAdd(Actor& child) if(!mAddingItems) { // We don't want to do this downcast check for any item added by ItemView itself. - Dali::Toolkit::ScrollComponent scrollComponent = Dali::Toolkit::ScrollComponent::DownCast(child); - if(scrollComponent) + Dali::Toolkit::ScrollBar scrollBar = Dali::Toolkit::ScrollBar::DownCast(child); + if(scrollBar) { - // Set the scroll connector when scroll bar is being added - scrollComponent.SetScrollConnector(mScrollConnector); + scrollBar.SetScrollPropertySource(Self(), + Toolkit::ItemView::Property::LAYOUT_POSITION, + Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_Y, + Toolkit::Scrollable::Property::SCROLL_POSITION_MAX_Y, + Toolkit::ItemView::Property::SCROLL_CONTENT_SIZE); } } } @@ -1062,7 +986,7 @@ bool ItemView::OnTouchEvent(const TouchEvent& event) mScrollDistance = 0.0f; mScrollSpeed = 0.0f; - Self().SetProperty(mPropertyScrollSpeed, mScrollSpeed); + Self().SetProperty(Toolkit::ItemView::Property::SCROLL_SPEED, mScrollSpeed); mScrollOvershoot = 0.0f; AnimateScrollOvershoot(0.0f); @@ -1078,39 +1002,39 @@ bool ItemView::OnTouchEvent(const TouchEvent& event) return true; // consume since we're potentially scrolling } -bool ItemView::OnMouseWheelEvent(const MouseWheelEvent& event) +bool ItemView::OnWheelEvent(const WheelEvent& event) { - // Respond the mouse wheel event to scroll + // Respond the wheel event to scroll if (mActiveLayout) { Actor self = Self(); const Vector3 layoutSize = Self().GetCurrentSize(); - float layoutPositionDelta = GetCurrentLayoutPosition(0) - (event.z * mMouseWheelScrollDistanceStep * mActiveLayout->GetScrollSpeedFactor()); + float layoutPositionDelta = GetCurrentLayoutPosition(0) - (event.z * mWheelScrollDistanceStep * mActiveLayout->GetScrollSpeedFactor()); float firstItemScrollPosition = ClampFirstItemPosition(layoutPositionDelta, layoutSize, *mActiveLayout); - mScrollPositionObject.SetProperty( ScrollConnector::SCROLL_POSITION, firstItemScrollPosition ); - self.SetProperty(mPropertyPosition, GetScrollPosition(firstItemScrollPosition, layoutSize)); + self.SetProperty(Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition ); + mScrollStartedSignal.Emit(GetCurrentScrollPosition()); mRefreshEnabled = true; } - if (mMouseWheelEventFinishedTimer.IsRunning()) + if (mWheelEventFinishedTimer.IsRunning()) { - mMouseWheelEventFinishedTimer.Stop(); + mWheelEventFinishedTimer.Stop(); } - mMouseWheelEventFinishedTimer.Start(); + mWheelEventFinishedTimer.Start(); return true; } -bool ItemView::OnMouseWheelEventFinished() +bool ItemView::OnWheelEventFinished() { if (mActiveLayout) { RemoveAnimation(mScrollAnimation); - // No more mouse wheel events coming. Do the anchoring if enabled. + // No more wheel events coming. Do the anchoring if enabled. mScrollAnimation = DoAnchoring(); if (mScrollAnimation) { @@ -1129,15 +1053,17 @@ bool ItemView::OnMouseWheelEventFinished() return false; } -void ItemView::ReapplyAllConstraints( float durationSeconds ) +void ItemView::ReapplyAllConstraints() { + Vector3 layoutSize = Self().GetCurrentSize(); + for (ConstItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter) { unsigned int id = iter->first; Actor actor = iter->second; actor.RemoveConstraints(); - mActiveLayout->ApplyConstraints(actor, id, durationSeconds, mScrollPositionObject, Self()); + mActiveLayout->ApplyConstraints(actor, id, layoutSize, Self()); } } @@ -1149,8 +1075,7 @@ void ItemView::OnItemsRemoved() if( mActiveLayout ) { float firstItemScrollPosition = ClampFirstItemPosition(GetCurrentLayoutPosition(0), Self().GetCurrentSize(), *mActiveLayout); - - mScrollPositionObject.SetProperty( ScrollConnector::SCROLL_POSITION, firstItemScrollPosition ); + Self().SetProperty( Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition ); } } @@ -1160,7 +1085,7 @@ float ItemView::ClampFirstItemPosition(float targetPosition, const Vector3& targ float minLayoutPosition = layout.GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), targetSize); float clamppedPosition = std::min(0.0f, std::max(minLayoutPosition, targetPosition)); mScrollOvershoot = targetPosition - clamppedPosition; - self.SetProperty(mPropertyMinimumLayoutPosition, minLayoutPosition); + self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX, Vector2(0.0f, -minLayoutPosition)); return clamppedPosition; } @@ -1209,9 +1134,8 @@ void ItemView::OnPan( const PanGesture& gesture ) , DEFAULT_MINIMUM_SWIPE_DURATION, DEFAULT_MAXIMUM_SWIPE_DURATION); mScrollAnimation = Animation::New(flickAnimationDuration); - mScrollAnimation.AnimateTo( Property( mScrollPositionObject, ScrollConnector::SCROLL_POSITION ), firstItemScrollPosition, AlphaFunctions::EaseOut ); - mScrollAnimation.AnimateTo( Property(self, mPropertyPosition), GetScrollPosition(firstItemScrollPosition, layoutSize), AlphaFunctions::EaseOut ); - mScrollAnimation.AnimateTo( Property(self, mPropertyScrollSpeed), 0.0f, AlphaFunctions::EaseOut ); + mScrollAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::LAYOUT_POSITION ), firstItemScrollPosition, AlphaFunction::EASE_OUT ); + mScrollAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::SCROLL_SPEED), 0.0f, AlphaFunction::EASE_OUT ); mIsFlicking = true; // Check whether it has already scrolled to the end @@ -1256,18 +1180,20 @@ void ItemView::OnPan( const PanGesture& gesture ) float firstItemScrollPosition = ClampFirstItemPosition(layoutPositionDelta, layoutSize, *mActiveLayout); - float currentOvershoot = mScrollPositionObject.GetProperty(ScrollConnector::OVERSHOOT); + float currentOvershoot = self.GetProperty(Toolkit::ItemView::Property::OVERSHOOT); - mScrollPositionObject.SetProperty( ScrollConnector::SCROLL_POSITION, firstItemScrollPosition ); - self.SetProperty(mPropertyPosition, GetScrollPosition(firstItemScrollPosition, layoutSize)); + self.SetProperty(Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition ); - if( (firstItemScrollPosition >= 0.0f && currentOvershoot < 1.0f) || (firstItemScrollPosition <= mActiveLayout->GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), layoutSize) && currentOvershoot > -1.0f) ) + if( ( firstItemScrollPosition >= 0.0f && + currentOvershoot < 1.0f ) || + ( firstItemScrollPosition <= mActiveLayout->GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), layoutSize) && + currentOvershoot > -1.0f ) ) { mTotalPanDisplacement += gesture.displacement; } mScrollOvershoot = CalculateScrollOvershoot(); - mScrollPositionObject.SetProperty( ScrollConnector::OVERSHOOT, mScrollOvershoot ); + self.SetProperty( Toolkit::ItemView::Property::OVERSHOOT, mScrollOvershoot ); } break; @@ -1294,7 +1220,7 @@ bool ItemView::OnAccessibilityPan(PanGesture gesture) return true; } -Actor ItemView::GetNextKeyboardFocusableActor(Actor actor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled) +Actor ItemView::GetNextKeyboardFocusableActor(Actor actor, Toolkit::Control::KeyboardFocus::Direction direction, bool loopEnabled) { Actor nextFocusActor; if(mActiveLayout) @@ -1339,7 +1265,7 @@ void ItemView::OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) Vector3 layoutSize = Self().GetCurrentSize(); float scrollTo = mActiveLayout->GetClosestOnScreenLayoutPosition(nextItemID, layoutPosition, layoutSize); - ScrollTo(Vector3(0.0f, scrollTo, 0.0f), DEFAULT_KEYBOARD_FOCUS_SCROLL_DURATION); + ScrollTo(Vector2(0.0f, scrollTo), DEFAULT_KEYBOARD_FOCUS_SCROLL_DURATION); } } @@ -1353,9 +1279,8 @@ Animation ItemView::DoAnchoring() float anchorPosition = mActiveLayout->GetClosestAnchorPosition( GetCurrentLayoutPosition(0) ); anchoringAnimation = Animation::New(mAnchoringDuration); - anchoringAnimation.AnimateTo( Property( mScrollPositionObject, ScrollConnector::SCROLL_POSITION ), anchorPosition, AlphaFunctions::EaseOut ); - anchoringAnimation.AnimateTo( Property(self, mPropertyPosition), GetScrollPosition(anchorPosition, self.GetCurrentSize()), AlphaFunctions::EaseOut ); - anchoringAnimation.AnimateTo( Property(self, mPropertyScrollSpeed), 0.0f, AlphaFunctions::EaseOut ); + anchoringAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::LAYOUT_POSITION), anchorPosition, AlphaFunction::EASE_OUT ); + anchoringAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::SCROLL_SPEED), 0.0f, AlphaFunction::EASE_OUT ); if(!mIsFlicking) { AnimateScrollOvershoot(0.0f); @@ -1392,6 +1317,9 @@ void ItemView::OnLayoutActivationScrollFinished(Animation& source) RemoveAnimation(mScrollAnimation); mRefreshEnabled = true; DoRefresh(GetCurrentLayoutPosition(0), true); + + // Emit the layout activated signal + mLayoutActivatedSignal.Emit(); } void ItemView::OnOvershootOnFinished(Animation& animation) @@ -1415,14 +1343,13 @@ void ItemView::ScrollToItem(unsigned int itemId, float durationSeconds) { RemoveAnimation(mScrollAnimation); mScrollAnimation = Animation::New(durationSeconds); - mScrollAnimation.AnimateTo( Property( mScrollPositionObject, ScrollConnector::SCROLL_POSITION ), firstItemScrollPosition, AlphaFunctions::EaseOut ); - mScrollAnimation.AnimateTo( Property(self, mPropertyPosition), GetScrollPosition(firstItemScrollPosition, layoutSize), AlphaFunctions::EaseOut ); + mScrollAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::LAYOUT_POSITION), firstItemScrollPosition, AlphaFunction::EASE_OUT ); mScrollAnimation.FinishedSignal().Connect(this, &ItemView::OnScrollFinished); mScrollAnimation.Play(); } else { - mScrollPositionObject.SetProperty( ScrollConnector::SCROLL_POSITION, firstItemScrollPosition ); + self.SetProperty( Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition ); AnimateScrollOvershoot(0.0f); } @@ -1452,40 +1379,38 @@ void ItemView::CalculateDomainSize(const Vector3& layoutSize) firstItemPosition = mActiveLayout->GetItemPosition( 0,0,layoutSize ); float minLayoutPosition = mActiveLayout->GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), layoutSize); - self.SetProperty(mPropertyMinimumLayoutPosition, minLayoutPosition); lastItemPosition = mActiveLayout->GetItemPosition( fabs(minLayoutPosition),fabs(minLayoutPosition),layoutSize ); float domainSize; if(IsHorizontal(mActiveLayout->GetOrientation())) { - self.SetProperty(mPropertyPositionMin, Vector3(0.0f, firstItemPosition.x, 0.0f)); - self.SetProperty(mPropertyPositionMax, Vector3(0.0f, lastItemPosition.x, 0.0f)); domainSize = fabs(firstItemPosition.x - lastItemPosition.x); } else { - self.SetProperty(mPropertyPositionMin, Vector3(0.0f, firstItemPosition.y, 0.0f)); - self.SetProperty(mPropertyPositionMax, Vector3(0.0f, lastItemPosition.y, 0.0f)); domainSize = fabs(firstItemPosition.y - lastItemPosition.y); } - mScrollConnector.SetScrollDomain(minLayoutPosition, 0.0f, domainSize); + self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MIN, Vector2::ZERO); + self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX, Vector2(0.0f, -minLayoutPosition)); + + self.SetProperty(Toolkit::ItemView::Property::SCROLL_CONTENT_SIZE, domainSize); bool isLayoutScrollable = IsLayoutScrollable(layoutSize); - self.SetProperty(mPropertyCanScrollVertical, isLayoutScrollable); - self.SetProperty(mPropertyCanScrollHorizontal, false); + self.SetProperty(Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL, isLayoutScrollable); + self.SetProperty(Toolkit::Scrollable::Property::CAN_SCROLL_HORIZONTAL, false); } } -Vector3 ItemView::GetDomainSize() const +Vector2 ItemView::GetDomainSize() const { Actor self = Self(); - float minScrollPosition = self.GetProperty(mPropertyPositionMin); - float maxScrollPosition = self.GetProperty(mPropertyPositionMax); + float minScrollPosition = self.GetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_Y); + float maxScrollPosition = self.GetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX_Y); - return Vector3(0.0f, fabs(maxScrollPosition - minScrollPosition), 0.0f); + return Vector2(0.0f, fabs(GetScrollPosition(minScrollPosition, self.GetCurrentSize()) - GetScrollPosition(-maxScrollPosition, self.GetCurrentSize()))); } bool ItemView::IsLayoutScrollable(const Vector3& layoutSize) @@ -1505,14 +1430,14 @@ float ItemView::GetScrollPosition(float layoutPosition, const Vector3& layoutSiz return IsHorizontal(mActiveLayout->GetOrientation()) ? firstItemPosition.x: firstItemPosition.y; } -Vector3 ItemView::GetCurrentScrollPosition() const +Vector2 ItemView::GetCurrentScrollPosition() const { - float currentLayoutPosition = GetCurrentLayoutPosition(0); - return Vector3(0.0f, GetScrollPosition(currentLayoutPosition, Self().GetCurrentSize()), 0.0f); + return Vector2(0.0f, GetScrollPosition(GetCurrentLayoutPosition(0), Self().GetCurrentSize())); } void ItemView::AddOverlay(Actor actor) { + actor.SetDrawMode( DrawMode::OVERLAY_2D ); Self().Add(actor); } @@ -1521,7 +1446,7 @@ void ItemView::RemoveOverlay(Actor actor) Self().Remove(actor); } -void ItemView::ScrollTo(const Vector3& position, float duration) +void ItemView::ScrollTo(const Vector2& position, float duration) { Actor self = Self(); const Vector3 layoutSize = Self().GetCurrentSize(); @@ -1532,14 +1457,13 @@ void ItemView::ScrollTo(const Vector3& position, float duration) { RemoveAnimation(mScrollAnimation); mScrollAnimation = Animation::New(duration); - mScrollAnimation.AnimateTo( Property( mScrollPositionObject, ScrollConnector::SCROLL_POSITION ), firstItemScrollPosition, AlphaFunctions::EaseOut ); - mScrollAnimation.AnimateTo( Property(self, mPropertyPosition), GetScrollPosition(firstItemScrollPosition, layoutSize), AlphaFunctions::EaseOut ); + mScrollAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::LAYOUT_POSITION), firstItemScrollPosition, AlphaFunction::EASE_OUT ); mScrollAnimation.FinishedSignal().Connect(this, &ItemView::OnScrollFinished); mScrollAnimation.Play(); } else { - mScrollPositionObject.SetProperty( ScrollConnector::SCROLL_POSITION, firstItemScrollPosition ); + self.SetProperty( Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition ); AnimateScrollOvershoot(0.0f); } @@ -1556,7 +1480,7 @@ void ItemView::SetOvershootEffectColor( const Vector4& color ) } } -void ItemView::SetOvershootEnabled( bool enable ) +void ItemView::EnableScrollOvershoot( bool enable ) { Actor self = Self(); if( enable ) @@ -1566,39 +1490,37 @@ void ItemView::SetOvershootEnabled( bool enable ) mOvershootOverlay.SetColor(mOvershootEffectColor); mOvershootOverlay.SetParentOrigin(ParentOrigin::TOP_LEFT); mOvershootOverlay.SetAnchorPoint(AnchorPoint::TOP_LEFT); - mOvershootOverlay.SetDrawMode(DrawMode::OVERLAY); + mOvershootOverlay.SetDrawMode( DrawMode::OVERLAY_2D ); self.Add(mOvershootOverlay); - Constraint constraint = Constraint::New( Actor::Property::Size, - ParentSource( mPropertyScrollDirection ), - Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), - ParentSource( Actor::Property::Size ), - OvershootOverlaySizeConstraint() ); - mOvershootOverlay.ApplyConstraint(constraint); - mOvershootOverlay.SetSize(OVERSHOOT_BOUNCE_ACTOR_DEFAULT_SIZE.width, OVERSHOOT_BOUNCE_ACTOR_DEFAULT_SIZE.height); - - constraint = Constraint::New( Actor::Property::Rotation, - ParentSource( mPropertyScrollDirection ), - Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), - OvershootOverlayRotationConstraint() ); - mOvershootOverlay.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::Property::Position, - ParentSource( Actor::Property::Size ), - ParentSource( mPropertyScrollDirection ), - Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), - OvershootOverlayPositionConstraint() ); - mOvershootOverlay.ApplyConstraint(constraint); - - constraint = Constraint::New( Actor::Property::Visible, - ParentSource( mPropertyCanScrollVertical ), - OvershootOverlayVisibilityConstraint() ); - mOvershootOverlay.ApplyConstraint(constraint); - - constraint = Constraint::New( effectOvershootPropertyIndex, - Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), - EqualToConstraint() ); - mOvershootOverlay.ApplyConstraint(constraint); + Constraint constraint = Constraint::New( mOvershootOverlay, Actor::Property::SIZE, OvershootOverlaySizeConstraint(mOvershootSize.height) ); + constraint.AddSource( ParentSource( Toolkit::ItemView::Property::SCROLL_DIRECTION ) ); + constraint.AddSource( ParentSource( Toolkit::ItemView::Property::LAYOUT_ORIENTATION ) ); + constraint.AddSource( ParentSource( Actor::Property::SIZE ) ); + constraint.Apply(); + + mOvershootOverlay.SetSize(mOvershootSize.width, mOvershootSize.height); + + constraint = Constraint::New( mOvershootOverlay, Actor::Property::ORIENTATION, OvershootOverlayRotationConstraint ); + constraint.AddSource( ParentSource( Toolkit::ItemView::Property::SCROLL_DIRECTION ) ); + constraint.AddSource( ParentSource( Toolkit::ItemView::Property::LAYOUT_ORIENTATION ) ); + constraint.AddSource( ParentSource( Toolkit::ItemView::Property::OVERSHOOT ) ); + constraint.Apply(); + + constraint = Constraint::New( mOvershootOverlay, Actor::Property::POSITION, OvershootOverlayPositionConstraint ); + constraint.AddSource( ParentSource( Actor::Property::SIZE ) ); + constraint.AddSource( ParentSource( Toolkit::ItemView::Property::SCROLL_DIRECTION ) ); + constraint.AddSource( ParentSource( Toolkit::ItemView::Property::LAYOUT_ORIENTATION ) ); + constraint.AddSource( ParentSource( Toolkit::ItemView::Property::OVERSHOOT ) ); + constraint.Apply(); + + constraint = Constraint::New( mOvershootOverlay, Actor::Property::VISIBLE, OvershootOverlayVisibilityConstraint ); + constraint.AddSource( ParentSource( Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL ) ); + constraint.Apply(); + + constraint = Constraint::New( mOvershootOverlay, effectOvershootPropertyIndex, EqualToConstraint() ); + constraint.AddSource( ParentSource( Toolkit::ItemView::Property::OVERSHOOT ) ); + constraint.Apply(); } else { @@ -1622,7 +1544,7 @@ float ItemView::CalculateScrollOvershoot() float scrollDistance = CalculateScrollDistance(mTotalPanDisplacement, *mActiveLayout) * mActiveLayout->GetScrollSpeedFactor(); float positionDelta = GetCurrentLayoutPosition(0) + scrollDistance; float minLayoutPosition = mActiveLayout->GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), Self().GetCurrentSize()); - self.SetProperty(mPropertyMinimumLayoutPosition, minLayoutPosition); + self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX, Vector2(0.0f, -minLayoutPosition)); float clamppedPosition = std::min(0.0f, std::max(minLayoutPosition, positionDelta)); overshoot = positionDelta - clamppedPosition; } @@ -1643,22 +1565,29 @@ void ItemView::AnimateScrollOvershoot(float overshootAmount, bool animateBack) return; } + Actor self = Self(); + if(mOvershootAnimationSpeed > Math::MACHINE_EPSILON_0) { - float currentOvershoot = mScrollPositionObject.GetProperty(ScrollConnector::OVERSHOOT); - float duration = mOvershootOverlay.GetCurrentSize().height * (animatingOn ? (1.0f - fabsf(currentOvershoot)) : fabsf(currentOvershoot)) / mOvershootAnimationSpeed; + float currentOvershoot = self.GetProperty(Toolkit::ItemView::Property::OVERSHOOT); + float duration = 0.0f; + + if (mOvershootOverlay) + { + duration = mOvershootOverlay.GetCurrentSize().height * (animatingOn ? (1.0f - fabsf(currentOvershoot)) : fabsf(currentOvershoot)) / mOvershootAnimationSpeed; + } RemoveAnimation(mScrollOvershootAnimation); mScrollOvershootAnimation = Animation::New(duration); mScrollOvershootAnimation.FinishedSignal().Connect(this, &ItemView::OnOvershootOnFinished); - mScrollOvershootAnimation.AnimateTo( Property(mScrollPositionObject, ScrollConnector::OVERSHOOT), overshootAmount, TimePeriod(0.0f, duration) ); + mScrollOvershootAnimation.AnimateTo( Property(self, Toolkit::ItemView::Property::OVERSHOOT), overshootAmount, TimePeriod(0.0f, duration) ); mScrollOvershootAnimation.Play(); mAnimatingOvershootOn = animatingOn; } else { - mScrollPositionObject.SetProperty( ScrollConnector::OVERSHOOT, overshootAmount ); + self.SetProperty( Toolkit::ItemView::Property::OVERSHOOT, overshootAmount ); } } @@ -1710,13 +1639,24 @@ void ItemView::GetItemsRange(ItemRange& range) } } -void ItemView::OnScrollPositionChanged( float position ) +bool ItemView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { - // Cancel scroll animation to prevent any fighting of setting the scroll position property. - RemoveAnimation(mScrollAnimation); + Dali::BaseHandle handle( object ); + + bool connected( true ); + Toolkit::ItemView itemView = Toolkit::ItemView::DownCast( handle ); + + if( 0 == strcmp( signalName.c_str(), LAYOUT_ACTIVATED_SIGNAL ) ) + { + itemView.LayoutActivatedSignal().Connect( tracker, functor ); + } + else + { + // signalName does not match any signal + connected = false; + } - // Refresh the cache immediately when the scroll position is changed. - DoRefresh(position, false); // No need to cache extra items. + return connected; } } // namespace Internal