X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fscrollable%2Fitem-view%2Fitem-view-impl.cpp;h=43f134d83b3edbd5aea8f9ac0d297a9ab139f6b3;hb=56d412791a44c2a79135d2293c13fddb135c9d54;hp=ebe8f7776ad9cb42d709094d0798c57733f4d8f2;hpb=928136dbb9e23970f3894eabc7c8b224003b77be;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git 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..43f134d 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 @@ -28,21 +28,24 @@ #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_TYPE_REGISTRATION_END() const float DEFAULT_MINIMUM_SWIPE_SPEED = 1.0f; const float DEFAULT_MINIMUM_SWIPE_DISTANCE = 3.0f; @@ -123,8 +126,7 @@ struct OvershootOverlayRotationConstraint const float parentOvershoot = parentOvershootProperty.GetFloat(); const Toolkit::ControlOrientation::Type& parentOrientation = static_cast(parentScrollDirection.z); - Quaternion rotation; - + float multiplier = 0; if(Toolkit::IsVertical(parentOrientation)) { if(fabsf(parentScrollDirection.y) <= Math::MACHINE_EPSILON_1) @@ -132,21 +134,21 @@ struct OvershootOverlayRotationConstraint 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); + multiplier = 0.5f; } else { - rotation = Quaternion(1.5f * 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) ) { - rotation = Quaternion(0.0f, Vector3::ZAXIS); + multiplier = 0.0f; } else { - rotation = Quaternion(Math::PI, Vector3::ZAXIS); + multiplier = 1.0f; } } else @@ -156,24 +158,26 @@ struct OvershootOverlayRotationConstraint 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); + multiplier = 1.0f; } else { - rotation = Quaternion(0.0f, Vector3::ZAXIS); + multiplier = 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) ) { - rotation = Quaternion(1.5f * Math::PI, Vector3::ZAXIS); + multiplier = 1.5f; } else { - rotation = Quaternion(0.5f * Math::PI, Vector3::ZAXIS); + multiplier = 0.5f; } } + Quaternion rotation( Radian( multiplier * Math::PI ), Vector3::ZAXIS ); + return rotation; } }; @@ -358,12 +362,11 @@ ItemView::ItemView(ItemFactory& factory) void ItemView::OnInitialize() { - SetSizePolicy( Toolkit::Control::Fixed, Toolkit::Control::Fixed ); - - RegisterCommonProperties(); - Actor self = Self(); + // Disable size negotiation for item views + self.SetRelayoutEnabled( false ); + mScrollConnector = Dali::Toolkit::ScrollConnector::New(); mScrollPositionObject = mScrollConnector.GetScrollPositionObject(); mScrollConnector.ScrollPositionChangedSignal().Connect( this, &ItemView::OnScrollPositionChanged ); @@ -374,11 +377,11 @@ void ItemView::OnInitialize() EnableScrollComponent(Toolkit::Scrollable::OvershootIndicator); - Constraint constraint = Constraint::New(mPropertyRelativePosition, + Constraint constraint = Constraint::New(Toolkit::Scrollable::Property::SCROLL_RELATIVE_POSITION, LocalSource(mPropertyPosition), - LocalSource(mPropertyPositionMin), - LocalSource(mPropertyPositionMax), - LocalSource(Actor::Property::Size), + LocalSource(Toolkit::Scrollable::Property::SCROLL_POSITION_MIN), + LocalSource(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX), + LocalSource(Actor::Property::SIZE), RelativePositionConstraint); self.ApplyConstraint(constraint); @@ -456,7 +459,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; @@ -468,34 +470,13 @@ void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSiz 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); - } - - // The layout provides its own resize animation - mActiveLayout->GetResizeAnimation(mResizeAnimation, actor, size, durationSeconds); - } - else - { - // resize immediately - actor.SetSize(size); - } + // resize immediately + actor.SetSize( size.GetVectorXY() ); } mActiveLayout->ApplyConstraints(actor, itemId, durationSeconds, mScrollPositionObject, Self() ); } - if (resizeAnimationNeeded) - { - mResizeAnimation.Play(); - } - // Refresh the new layout ItemRange range = GetItemRange(*mActiveLayout, targetSize, GetCurrentLayoutPosition(0), false/* don't reserve extra*/); AddActorsWithinRange( range, durationSeconds ); @@ -536,7 +517,7 @@ void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSiz Radian scrollDirection(mActiveLayout->GetScrollDirection()); float orientation = static_cast(mActiveLayout->GetOrientation()); - self.SetProperty(mPropertyScrollDirection, Vector3(sinf(scrollDirection), cosf(scrollDirection), orientation)); + self.SetProperty(Toolkit::Scrollable::Property::SCROLL_DIRECTION, Vector3(sinf(scrollDirection), cosf(scrollDirection), orientation)); self.SetProperty(mPropertyScrollSpeed, mScrollSpeed); @@ -566,6 +547,17 @@ void ItemView::OnRefreshNotification(PropertyNotification& source) } } +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) { if (mActiveLayout) @@ -1001,7 +993,7 @@ void ItemView::SetupActor( Item item, float durationSeconds ) Vector3 size; if( mActiveLayout->GetItemSize( item.first, mActiveLayoutTargetSize, size ) ) { - item.second.SetSize( size ); + item.second.SetSize( size.GetVectorXY() ); } mActiveLayout->ApplyConstraints( item.second, item.first, durationSeconds, mScrollPositionObject, Self() ); @@ -1459,22 +1451,22 @@ void ItemView::CalculateDomainSize(const Vector3& layoutSize) if(IsHorizontal(mActiveLayout->GetOrientation())) { - self.SetProperty(mPropertyPositionMin, Vector3(0.0f, firstItemPosition.x, 0.0f)); - self.SetProperty(mPropertyPositionMax, Vector3(0.0f, lastItemPosition.x, 0.0f)); + self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MIN, Vector3(0.0f, firstItemPosition.x, 0.0f)); + self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX, 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)); + self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MIN, Vector3(0.0f, firstItemPosition.y, 0.0f)); + self.SetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX, Vector3(0.0f, lastItemPosition.y, 0.0f)); domainSize = fabs(firstItemPosition.y - lastItemPosition.y); } mScrollConnector.SetScrollDomain(minLayoutPosition, 0.0f, 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); } } @@ -1482,8 +1474,8 @@ Vector3 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); + float maxScrollPosition = self.GetProperty(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX); return Vector3(0.0f, fabs(maxScrollPosition - minScrollPosition), 0.0f); } @@ -1569,29 +1561,29 @@ void ItemView::SetOvershootEnabled( bool enable ) mOvershootOverlay.SetDrawMode(DrawMode::OVERLAY); self.Add(mOvershootOverlay); - Constraint constraint = Constraint::New( Actor::Property::Size, - ParentSource( mPropertyScrollDirection ), + Constraint constraint = Constraint::New( Actor::Property::SIZE, + ParentSource( Toolkit::Scrollable::Property::SCROLL_DIRECTION ), Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), - ParentSource( Actor::Property::Size ), + 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 ), + constraint = Constraint::New( Actor::Property::ORIENTATION, + ParentSource( Toolkit::Scrollable::Property::SCROLL_DIRECTION ), Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), OvershootOverlayRotationConstraint() ); mOvershootOverlay.ApplyConstraint(constraint); - constraint = Constraint::New( Actor::Property::Position, - ParentSource( Actor::Property::Size ), - ParentSource( mPropertyScrollDirection ), + constraint = Constraint::New( Actor::Property::POSITION, + ParentSource( Actor::Property::SIZE ), + ParentSource( Toolkit::Scrollable::Property::SCROLL_DIRECTION ), Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ), OvershootOverlayPositionConstraint() ); mOvershootOverlay.ApplyConstraint(constraint); - constraint = Constraint::New( Actor::Property::Visible, - ParentSource( mPropertyCanScrollVertical ), + constraint = Constraint::New( Actor::Property::VISIBLE, + ParentSource( Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL ), OvershootOverlayVisibilityConstraint() ); mOvershootOverlay.ApplyConstraint(constraint); @@ -1646,7 +1638,12 @@ void ItemView::AnimateScrollOvershoot(float overshootAmount, bool animateBack) 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 duration = 0.0f; + + if (mOvershootOverlay) + { + duration = mOvershootOverlay.GetCurrentSize().height * (animatingOn ? (1.0f - fabsf(currentOvershoot)) : fabsf(currentOvershoot)) / mOvershootAnimationSpeed; + } RemoveAnimation(mScrollOvershootAnimation); mScrollOvershootAnimation = Animation::New(duration);