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=a121343d01373e517977d052a30a6bd2e1ea742a;hp=23fcd36a6e0cf9c826a6f5ef696101a221739888;hb=a8d60282f49c906206c1ffb2f2425800b914d109;hpb=06f734a391814a2972e31351604e0a34ef712ed9 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 23fcd36..a121343 100755 --- a/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp +++ b/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ #include #include #include +#include // INTERNAL INCLUDES #include @@ -69,6 +70,8 @@ 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 unsigned int OVERSHOOT_SIZE_CONSTRAINT_TAG(42); + /** * Local helper to convert pan distance (in actor coordinates) to the layout-specific scrolling direction */ @@ -291,6 +294,21 @@ bool FindById( const ItemContainer& items, ItemId id ) return false; } +/** + * Helper to apply size constraint to mOvershootOverlay + * @param[in] overshootOverlay The overshootOverlay actor + * @param[in] The required height + */ +void ApplyOvershootSizeConstraint( Actor overshootOverlay, float height ) +{ + Constraint constraint = Constraint::New( overshootOverlay, Actor::Property::SIZE, OvershootOverlaySizeConstraint( height ) ); + constraint.AddSource( ParentSource( Dali::Toolkit::ItemView::Property::SCROLL_DIRECTION ) ); + constraint.AddSource( ParentSource( Dali::Toolkit::ItemView::Property::LAYOUT_ORIENTATION ) ); + constraint.AddSource( ParentSource( Dali::Actor::Property::SIZE ) ); + constraint.SetTag( OVERSHOOT_SIZE_CONSTRAINT_TAG ); + constraint.Apply(); +} + } // unnamed namespace Dali::Toolkit::ItemView ItemView::New(ItemFactory& factory) @@ -390,7 +408,7 @@ ItemLayoutPtr ItemView::GetActiveLayout() const float ItemView::GetCurrentLayoutPosition(unsigned int itemId) const { - return Self().GetProperty( Toolkit::ItemView::Property::LAYOUT_POSITION ) + static_cast( itemId ); + return DevelHandle::GetCurrentProperty< float >( Self(), Toolkit::ItemView::Property::LAYOUT_POSITION ) + static_cast( itemId ); } void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSize, float durationSeconds) @@ -997,6 +1015,8 @@ void ItemView::OnChildAdd(Actor& child) Toolkit::ItemView::Property::SCROLL_CONTENT_SIZE); } } + + Scrollable::OnChildAdd( child ); } bool ItemView::OnWheelEvent(const WheelEvent& event) @@ -1170,10 +1190,12 @@ void ItemView::OnPan( const PanGesture& gesture ) 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 - if(fabs(currentLayoutPosition - firstItemScrollPosition) > Math::MACHINE_EPSILON_0) + if( fabs(currentLayoutPosition - firstItemScrollPosition) < Math::MACHINE_EPSILON_0 ) { - AnimateScrollOvershoot(0.0f); + AnimateScrollOvershoot( 0.0f ); + RemoveAnimation( mScrollAnimation ); } } @@ -1212,7 +1234,7 @@ void ItemView::OnPan( const PanGesture& gesture ) float firstItemScrollPosition = ClampFirstItemPosition(layoutPositionDelta, layoutSize, *mActiveLayout); - float currentOvershoot = self.GetProperty(Toolkit::ItemView::Property::OVERSHOOT); + float currentOvershoot = DevelHandle::GetCurrentProperty< float >( self, Toolkit::ItemView::Property::OVERSHOOT ); self.SetProperty(Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition ); @@ -1517,6 +1539,18 @@ void ItemView::ScrollTo(const Vector2& position, float duration) mRefreshEnabled = true; } +void ItemView::SetOvershootSize( const Vector2& size ) +{ + mOvershootSize = size; + + if( mOvershootOverlay ) + { + // Remove old & add new size constraint + mOvershootOverlay.RemoveConstraints( OVERSHOOT_SIZE_CONSTRAINT_TAG ); + ApplyOvershootSizeConstraint( mOvershootOverlay, mOvershootSize.height ); + } +} + void ItemView::SetOvershootEffectColor( const Vector4& color ) { mOvershootEffectColor = color; @@ -1541,15 +1575,9 @@ void ItemView::EnableScrollOvershoot( bool enable ) mOvershootOverlay.SetDrawMode( DrawMode::OVERLAY_2D ); self.Add(mOvershootOverlay); - 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); + ApplyOvershootSizeConstraint( mOvershootOverlay, mOvershootSize.height ); - constraint = Constraint::New( mOvershootOverlay, Actor::Property::ORIENTATION, OvershootOverlayRotationConstraint ); + Constraint 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 ) ); @@ -1618,7 +1646,7 @@ void ItemView::AnimateScrollOvershoot(float overshootAmount, bool animateBack) if(mOvershootAnimationSpeed > Math::MACHINE_EPSILON_0) { - float currentOvershoot = self.GetProperty(Toolkit::ItemView::Property::OVERSHOOT); + float currentOvershoot = DevelHandle::GetCurrentProperty< float >( self, Toolkit::ItemView::Property::OVERSHOOT ); float duration = 0.0f; if (mOvershootOverlay) @@ -1765,9 +1793,10 @@ Property::Array ItemView::GetLayoutArray() void ItemView::SetLayoutArray( const Property::Array& layouts ) { mlayoutArray = layouts; - if(GetLayoutCount() > 0) + const int layoutCount = GetLayoutCount(); + if( layoutCount > 0 ) { - for(unsigned int index = GetLayoutCount() - 1; index >= 0; --index) + for(int index = layoutCount - 1; index >= 0; --index) { RemoveLayout(index); if(index == 0) break; @@ -1797,6 +1826,7 @@ void ItemView::SetLayoutArray( const Property::Array& layouts ) { Internal::DepthLayoutPtr depthLayout = Internal::DepthLayout::New(); (*depthLayout).SetLayoutProperties(*layout); + (*depthLayout).SetDepthLayoutProperties(*layout); AddLayout(*depthLayout); break; } @@ -1804,6 +1834,7 @@ void ItemView::SetLayoutArray( const Property::Array& layouts ) { Internal::GridLayoutPtr gridLayout = Internal::GridLayout::New(); (*gridLayout).SetLayoutProperties(*layout); + (*gridLayout).SetGridLayoutProperties(*layout); AddLayout(*gridLayout); break; } @@ -1812,6 +1843,7 @@ void ItemView::SetLayoutArray( const Property::Array& layouts ) Internal::GridLayoutPtr listLayout = Internal::GridLayout::New(); listLayout->SetNumberOfColumns( 1 ); (*listLayout).SetLayoutProperties(*layout); + (*listLayout).SetGridLayoutProperties(*layout); AddLayout(*listLayout); break; } @@ -1819,6 +1851,7 @@ void ItemView::SetLayoutArray( const Property::Array& layouts ) { Internal::SpiralLayoutPtr spiralLayout = Internal::SpiralLayout::New(); (*spiralLayout).SetLayoutProperties(*layout); + (*spiralLayout).SetSpiralLayoutProperties(*layout); AddLayout(*spiralLayout); break; }