/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
#include <dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h>
// EXTERNAL INCLUDES
+#include <cstring> // for strcmp
#include <algorithm>
-#include <dali/public-api/animation/active-constraint.h>
+#include <dali/public-api/actors/layer.h>
+
#include <dali/public-api/animation/constraint.h>
#include <dali/public-api/animation/constraints.h>
-#include <dali/public-api/common/set-wrapper.h>
-#include <dali/public-api/common/stage.h>
-#include <dali/public-api/events/mouse-wheel-event.h>
-#include <dali/public-api/events/touch-event.h>
+#include <dali/devel-api/common/stage.h>
+#include <dali/public-api/events/wheel-event.h>
+#include <dali/public-api/events/touch-data.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/devel-api/object/property-helper-devel.h>
// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
#include <dali-toolkit/public-api/controls/scrollable/item-view/item-factory.h>
+#include <dali-toolkit/public-api/controls/scrollable/item-view/default-item-layout.h>
+#include <dali-toolkit/public-api/controls/scrollable/item-view/default-item-layout-property.h>
+#include <dali-toolkit/internal/controls/scrollable/item-view/grid-layout.h>
+#include <dali-toolkit/internal/controls/scrollable/item-view/depth-layout.h>
+#include <dali-toolkit/internal/controls/scrollable/item-view/spiral-layout.h>
#include <dali-toolkit/internal/controls/scrollable/bouncing-effect-actor.h>
-#include <dali-toolkit/internal/controls/scrollable/scroll-connector-impl.h>
using std::string;
-using std::set;
using namespace Dali;
namespace // Unnamed namespace
{
-//Type registration
-
-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;
-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" );
+const unsigned int OVERSHOOT_SIZE_CONSTRAINT_TAG(42);
/**
* Local helper to convert pan distance (in actor coordinates) to the layout-specific scrolling direction
}
// 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<Toolkit::ControlOrientation::Type>(parentScrollDirection.z);
+ }
- float overlayWidth;
+ void operator()( Vector3& current, const PropertyInputContainer& inputs )
+ {
+ const Vector2& parentScrollDirection = inputs[0]->GetVector2();
+ const Toolkit::ControlOrientation::Type& layoutOrientation = static_cast<Toolkit::ControlOrientation::Type>(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<Toolkit::ControlOrientation::Type>(parentScrollDirection.z);
+ const Vector2& parentScrollDirection = inputs[0]->GetVector2();
+ const Toolkit::ControlOrientation::Type& layoutOrientation = static_cast<Toolkit::ControlOrientation::Type>(inputs[1]->GetInteger());
+ const float parentOvershoot = inputs[2]->GetFloat();
- float multiplier = 0;
- 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( (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) )
- {
- multiplier = 0.5f;
- }
- else
- {
- 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;
+ multiplier = 0.5f;
}
else
{
- multiplier = 1.0f;
+ 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) )
- {
- multiplier = 1.0f;
- }
- else
- {
- 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) )
+ 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) )
{
- multiplier = 1.5f;
+ multiplier = 1.0f;
}
else
{
- multiplier = 0.5f;
+ multiplier = 0.0f;
}
}
-
- Quaternion rotation( Radian( multiplier * Math::PI ), Vector3::ZAXIS );
-
- 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<Toolkit::ControlOrientation::Type>(parentScrollDirection.z);
+ const Vector3& parentSize = inputs[0]->GetVector3();
+ const Vector2& parentScrollDirection = inputs[1]->GetVector2();
+ const Toolkit::ControlOrientation::Type& layoutOrientation = static_cast<Toolkit::ControlOrientation::Type>(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
namespace // unnamed namespace
{
-bool FindById( const ItemContainer& items, ItemId id )
+//Type registration
+
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ItemView, Toolkit::Scrollable, NULL)
+
+DALI_PROPERTY_REGISTRATION( Toolkit, ItemView, "minimumSwipeSpeed", FLOAT, MINIMUM_SWIPE_SPEED )
+DALI_PROPERTY_REGISTRATION( Toolkit, ItemView, "minimumSwipeDistance", FLOAT, MINIMUM_SWIPE_DISTANCE )
+DALI_PROPERTY_REGISTRATION( Toolkit, ItemView, "wheelScrollDistanceStep", FLOAT, WHEEL_SCROLL_DISTANCE_STEP )
+DALI_PROPERTY_REGISTRATION( Toolkit, ItemView, "snapToItemEnabled", BOOLEAN, SNAP_TO_ITEM_ENABLED )
+DALI_PROPERTY_REGISTRATION( Toolkit, ItemView, "refreshInterval", FLOAT, REFRESH_INTERVAL )
+DALI_PROPERTY_REGISTRATION( Toolkit, ItemView, "layout", ARRAY, LAYOUT )
+
+
+DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "layoutPosition", FLOAT, LAYOUT_POSITION)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "scrollSpeed", FLOAT, SCROLL_SPEED)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "overshoot", FLOAT, OVERSHOOT)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "scrollDirection", VECTOR2, SCROLL_DIRECTION)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "layoutOrientation", INTEGER, LAYOUT_ORIENTATION)
+DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ItemView, "scrollContentSize", FLOAT, SCROLL_CONTENT_SIZE)
+
+DALI_SIGNAL_REGISTRATION( Toolkit, ItemView, "layoutActivated", LAYOUT_ACTIVATED_SIGNAL )
+
+DALI_ACTION_REGISTRATION( Toolkit, ItemView, "stopScrolling", ACTION_STOP_SCROLLING )
+
+DALI_ACTION_REGISTRATION( Toolkit, ItemView, "enableRefresh", ACTION_ENABLE_REFRESH )
+DALI_ACTION_REGISTRATION( Toolkit, ItemView, "disableRefresh", ACTION_DISABLE_REFRESH )
+
+DALI_TYPE_REGISTRATION_END()
+
+const ItemIter FindItemById( ItemContainer& items, ItemId id )
{
- for( ConstItemIter iter = items.begin(); items.end() != iter; ++iter )
+ for( ItemIter iter = items.begin(); items.end() != iter; ++iter )
{
if( iter->first == id )
{
- return true;
+ return iter;
}
}
- return false;
+ return items.end();
+}
+
+void InsertToItemContainer( ItemContainer& items, Item item )
+{
+ if( items.end() == FindItemById( items, item.first ) )
+ {
+ ItemIter iterToInsert = std::lower_bound( items.begin(), items.end(), item );
+ items.insert( iterToInsert, item );
+ }
+}
+
+
+/**
+ * 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<Vector3>( 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
}
ItemView::ItemView(ItemFactory& factory)
-: Scrollable(),
+: Scrollable( ControlBehaviour( DISABLE_SIZE_NEGOTIATION | DISABLE_STYLE_CHANGE_SIGNALS | REQUIRES_WHEEL_EVENTS | REQUIRES_KEYBOARD_NAVIGATION_SUPPORT ) ),
mItemFactory(factory),
+ mItemsParentOrigin(ParentOrigin::CENTER),
+ mItemsAnchorPoint(AnchorPoint::CENTER),
+ mTotalPanDisplacement(Vector2::ZERO),
mActiveLayout(NULL),
- mAnimatingOvershootOn(false),
- mAnimateOvershootOff(false),
- mAnchoringEnabled(true),
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),
mScrollOvershoot(0.0f),
- mIsFlicking(false),
mGestureState(Gesture::Clear),
+ mAnimatingOvershootOn(false),
+ mAnimateOvershootOff(false),
+ mAnchoringEnabled(false),
+ mRefreshOrderHint(true/*Refresh item 0 first*/),
+ mIsFlicking(false),
mAddingItems(false),
- mPropertyPosition(Property::INVALID_INDEX),
- mPropertyMinimumLayoutPosition(Property::INVALID_INDEX),
- mPropertyScrollSpeed(Property::INVALID_INDEX),
mRefreshEnabled(true),
- mItemsParentOrigin( ParentOrigin::CENTER),
- mItemsAnchorPoint( AnchorPoint::CENTER)
+ mRefreshNotificationEnabled(true),
+ mInAnimation(false)
{
- SetRequiresMouseWheelEvents(true);
- SetKeyboardNavigationSupport(true);
}
void ItemView::OnInitialize()
{
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 );
-
- 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<Vector3>(Toolkit::Scrollable::Property::SCROLL_RELATIVE_POSITION,
- LocalSource(mPropertyPosition),
- LocalSource(Toolkit::Scrollable::Property::SCROLL_POSITION_MIN),
- LocalSource(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX),
- 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;
+ self.TouchSignal().Connect( this, &ItemView::OnTouch );
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);
}
{
}
-Dali::Toolkit::ScrollConnector ItemView::GetScrollConnector() const
-{
- return mScrollConnector;
-}
-
unsigned int ItemView::GetLayoutCount() const
{
return mLayouts.size();
float ItemView::GetCurrentLayoutPosition(unsigned int itemId) const
{
- return mScrollConnector.GetScrollPosition() + static_cast<float>( itemId );
+ return Self().GetCurrentProperty< float >( Toolkit::ItemView::Property::LAYOUT_POSITION ) + static_cast<float>( itemId );
}
void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSize, float durationSeconds)
Actor self = Self();
// The ItemView size should match the active layout size
- self.SetSize(targetSize);
+ self.SetProperty( Actor::Property::SIZE, targetSize);
mActiveLayoutTargetSize = targetSize;
// Switch to the new layout
// Move the items to the new layout positions...
- for (ConstItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
+ for (ConstItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
{
unsigned int itemId = iter->first;
Actor actor = iter->second;
// Remove constraints from previous layout
actor.RemoveConstraints();
- Vector3 size;
- if(mActiveLayout->GetItemSize(itemId, targetSize, size))
- {
- // resize immediately
- actor.SetResizePolicy( FIXED, ALL_DIMENSIONS );
- actor.SetPreferredSize( size.GetVectorXY() );
- }
+ mActiveLayout->ApplyConstraints(actor, itemId, targetSize, Self() );
- mActiveLayout->ApplyConstraints(actor, itemId, durationSeconds, mScrollPositionObject, Self() );
+ Vector3 size;
+ mActiveLayout->GetItemSize( itemId, targetSize, size );
+ actor.SetProperty( Actor::Property::SIZE, size.GetVectorXY() );
}
// 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
float current = GetCurrentLayoutPosition(0);
float minimum = ClampFirstItemPosition(current, targetSize, *mActiveLayout);
- self.SetProperty(mPropertyPosition, GetScrollPosition(current, targetSize));
if (current < minimum)
{
{
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<float>(mActiveLayout->GetOrientation());
- self.SetProperty(Toolkit::Scrollable::Property::SCROLL_DIRECTION, 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<int>(mActiveLayout->GetOrientation()));
+ self.SetProperty(Toolkit::ItemView::Property::SCROLL_SPEED, mScrollSpeed);
CalculateDomainSize(targetSize);
}
{
if (mActiveLayout)
{
- for (ConstItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
+ for (ConstItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
{
Actor actor = iter->second;
actor.RemoveConstraints();
void ItemView::OnRefreshNotification(PropertyNotification& source)
{
- if(mRefreshEnabled || mScrollAnimation)
+ if( mRefreshNotificationEnabled )
{
- // Only refresh the cache during normal scrolling
- DoRefresh(GetCurrentLayoutPosition(0), true);
+ // Cancel scroll animation to prevent any fighting of setting the scroll position property by scroll bar during fast scroll.
+ if(!mRefreshEnabled && mScrollAnimation)
+ {
+ 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 )
+ for (ConstItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter )
{
ReleaseActor( iter->first, iter->second );
}
{
ItemRange range = GetItemRange(*mActiveLayout, mActiveLayoutTargetSize, currentLayoutPosition, cacheExtra/*reserve extra*/);
RemoveActorsOutsideRange( range );
- AddActorsWithinRange( range, 0.0f/*immediate*/ );
+ AddActorsWithinRange( range, Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) );
- mScrollUpdatedSignal.Emit( Vector3(0.0f, currentLayoutPosition, 0.0f) );
+ mScrollUpdatedSignal.Emit( Vector2(0.0f, currentLayoutPosition) );
}
}
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)
{
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 );
}
}
{
Actor actor;
- ConstItemPoolIter iter = mItemPool.find( itemId );
- if( iter != mItemPool.end() )
+ for ( ConstItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter )
{
- actor = iter->second;
+ if( iter->first == itemId )
+ {
+ actor = iter->second;
+ break;
+ }
}
return actor;
{
unsigned int itemId( 0 );
- for ( ConstItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter )
+ for ( ConstItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter )
{
if( iter->second == actor )
{
void ItemView::InsertItem( Item newItem, float durationSeconds )
{
mAddingItems = true;
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
Actor displacedActor;
- ItemPoolIter afterDisplacedIter = mItemPool.end();
+ ItemIter afterDisplacedIter = mItemPool.end();
- ItemPoolIter foundIter = mItemPool.find( newItem.first );
+ ItemIter foundIter = FindItemById( mItemPool, newItem.first );
if( mItemPool.end() != foundIter )
{
- SetupActor( newItem, durationSeconds );
+ SetupActor( newItem, layoutSize );
Self().Add( newItem.second );
displacedActor = foundIter->second;
else
{
// Inserting before the existing item range?
- ItemPoolIter iter = mItemPool.begin();
+ ItemIter iter = mItemPool.begin();
if( iter != mItemPool.end() &&
iter->first > newItem.first )
{
displacedActor = iter->second;
- mItemPool.erase( iter++ ); // iter is still valid after the erase
+ iter = mItemPool.erase( iter ); // iter is still valid after the erase
afterDisplacedIter = iter;
}
if( displacedActor )
{
// Move the existing actors to make room
- for( ItemPoolIter iter = afterDisplacedIter; mItemPool.end() != iter; ++iter )
+ for( ItemIter iter = afterDisplacedIter; mItemPool.end() != iter; ++iter )
{
Actor temp = iter->second;
iter->second = displacedActor;
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
- ItemPool::reverse_iterator lastIter = mItemPool.rbegin();
+ ItemContainer::reverse_iterator lastIter = mItemPool.rbegin();
if ( lastIter != mItemPool.rend() )
{
ItemId lastId = lastIter->first;
Item lastItem( lastId + 1, displacedActor );
- mItemPool.insert( lastItem );
+ InsertToItemContainer( mItemPool, 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;
}
void ItemView::InsertItems( const ItemContainer& newItems, float durationSeconds )
{
mAddingItems = true;
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
// Insert from lowest id to highest
- std::set<Item> sortedItems;
- for( ConstItemIter iter = newItems.begin(); newItems.end() != iter; ++iter )
- {
- sortedItems.insert( *iter );
- }
+ ItemContainer sortedItems(newItems);
+ std::sort( sortedItems.begin(), sortedItems.end() );
- for( std::set<Item>::iterator iter = sortedItems.begin(); sortedItems.end() != iter; ++iter )
+ for( ItemIter iter = sortedItems.begin(); sortedItems.end() != iter; ++iter )
{
Self().Add( iter->second );
- ItemPoolIter foundIter = mItemPool.find( iter->first );
+ ItemIter foundIter = FindItemById( mItemPool, iter->first );
if( mItemPool.end() != foundIter )
{
Actor moveMe = foundIter->second;
foundIter->second = iter->second;
// Move the existing actors to make room
- for( ItemPoolIter iter = ++foundIter; mItemPool.end() != iter; ++iter )
+ for( ItemIter iter = ++foundIter; mItemPool.end() != iter; ++iter )
{
Actor temp = iter->second;
iter->second = moveMe;
// Create last item
ItemId lastId = mItemPool.rbegin()->first;
Item lastItem( lastId + 1, moveMe );
- mItemPool.insert( lastItem );
+ InsertToItemContainer( mItemPool, lastItem );
}
else
{
- mItemPool.insert( *iter );
+ InsertToItemContainer( mItemPool, *iter );
}
}
// Relayout everything
- for (ItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
+ for (ItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
{
// If newly inserted
- if( FindById( newItems, iter->first ) )
+ if( std::binary_search( sortedItems.begin(), sortedItems.end(), *iter ) )
{
- 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;
}
bool actorsReordered = RemoveActor( itemId );
if( actorsReordered )
{
- ReapplyAllConstraints( durationSeconds );
+ ReapplyAllConstraints();
OnItemsRemoved();
}
bool actorsReordered( false );
// Remove from highest id to lowest
- set<ItemId> sortedItems;
- for( ConstItemIdIter iter = itemIds.begin(); itemIds.end() != iter; ++iter )
- {
- sortedItems.insert( *iter );
- }
+ ItemIdContainer sortedItems(itemIds);
+ std::sort( sortedItems.begin(), sortedItems.end() );
- for( set<ItemId>::reverse_iterator iter = sortedItems.rbegin(); sortedItems.rend() != iter; ++iter )
+ for( ItemIdContainer::reverse_iterator iter = sortedItems.rbegin(); sortedItems.rend() != iter; ++iter )
{
if( RemoveActor( *iter ) )
{
if( actorsReordered )
{
- ReapplyAllConstraints( durationSeconds );
+ ReapplyAllConstraints();
OnItemsRemoved();
}
{
bool reordered( false );
- ItemPoolIter removeIter = mItemPool.find( itemId );
+ ItemIter removeIter = FindItemById( mItemPool, itemId );
if( removeIter != mItemPool.end() )
{
ReleaseActor(itemId, removeIter->second);
else
{
// Removing before the existing item range?
- ItemPoolIter iter = mItemPool.begin();
+ ItemIter iter = mItemPool.begin();
if( iter != mItemPool.end() &&
iter->first > itemId )
{
// In order to decrement the first visible item ID
- mItemPool.insert( Item(iter->first - 1, Actor()) );
+ InsertToItemContainer( mItemPool, Item(iter->first - 1, Actor()) );
removeIter = mItemPool.begin();
}
// ID 2 - ActorB ID 2 - ActorC (previously ID 3)
// ID 3 - ActorC ID 3 - ActorB (previously ID 4)
// ID 4 - ActorD
- for (ItemPoolIter iter = removeIter; iter != mItemPool.end(); ++iter)
+ for (ItemIter iter = removeIter; iter != mItemPool.end(); ++iter)
{
if( iter->first < mItemPool.rbegin()->first )
{
- iter->second = mItemPool[ iter->first + 1 ];
+ iter->second = ( iter + 1 )->second;
}
else
{
void ItemView::ReplaceItem( Item replacementItem, float durationSeconds )
{
mAddingItems = true;
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
- SetupActor( replacementItem, durationSeconds );
+ SetupActor( replacementItem, layoutSize );
Self().Add( replacementItem.second );
- const ItemPoolIter iter = mItemPool.find( replacementItem.first );
+ const ItemIter iter = FindItemById( mItemPool, replacementItem.first );
if( mItemPool.end() != iter )
{
ReleaseActor(iter->first, iter->second);
}
else
{
- mItemPool.insert( replacementItem );
+ InsertToItemContainer( mItemPool, replacementItem );
}
- CalculateDomainSize(Self().GetCurrentSize());
+ CalculateDomainSize( layoutSize );
mAddingItems = false;
}
void ItemView::RemoveActorsOutsideRange( ItemRange range )
{
// Remove unwanted actors from the ItemView & ItemPool
- for (ItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); )
+ for (ItemIter iter = mItemPool.begin(); iter != mItemPool.end(); )
{
unsigned int current = iter->first;
{
ReleaseActor(iter->first, iter->second);
- mItemPool.erase( iter++ ); // erase invalidates the return value of post-increment; iter remains valid
+ iter = mItemPool.erase( iter ); // iter is still valid after the erase
}
else
{
}
}
-void ItemView::AddActorsWithinRange( ItemRange range, float durationSeconds )
+void ItemView::AddActorsWithinRange( ItemRange range, const Vector3& layoutSize )
{
range.end = std::min(mItemFactory.GetNumberOfItems(), range.end);
{
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 );
}
}
// Total number of items may change dynamically.
// Always recalculate the domain size to reflect that.
- CalculateDomainSize(Self().GetCurrentSize());
+ CalculateDomainSize(Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ));
}
-void ItemView::AddNewActor( unsigned int itemId, float durationSeconds )
+void ItemView::AddNewActor( unsigned int itemId, const Vector3& layoutSize )
{
mAddingItems = true;
- if( mItemPool.end() == mItemPool.find( itemId ) )
+ if( mItemPool.end() == FindItemById( mItemPool, itemId ) )
{
Actor actor = mItemFactory.NewItem( itemId );
{
Item newItem( itemId, actor );
- mItemPool.insert( newItem );
+ InsertToItemContainer( mItemPool, newItem );
- SetupActor( newItem, durationSeconds );
+ SetupActor( newItem, layoutSize );
Self().Add( actor );
}
}
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 );
+ item.second.SetProperty( Actor::Property::PARENT_ORIGIN, mItemsParentOrigin );
+ item.second.SetProperty( Actor::Property::ANCHOR_POINT, mItemsAnchorPoint );
if( mActiveLayout )
{
Vector3 size;
- if( mActiveLayout->GetItemSize( item.first, mActiveLayoutTargetSize, size ) )
- {
- item.second.SetResizePolicy( FIXED, ALL_DIMENSIONS );
- item.second.SetPreferredSize( size.GetVectorXY() );
- }
+ mActiveLayout->GetItemSize( item.first, mActiveLayoutTargetSize, size );
+ item.second.SetProperty( Actor::Property::SIZE, size.GetVectorXY() );
- mActiveLayout->ApplyConstraints( item.second, item.first, durationSeconds, mScrollPositionObject, Self() );
+ mActiveLayout->ApplyConstraints( item.second, item.first, layoutSize, Self() );
}
}
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)
- {
- // Set the scroll connector when scroll bar is being added
- scrollComponent.SetScrollConnector(mScrollConnector);
- }
- }
-}
-
-bool ItemView::OnTouchEvent(const TouchEvent& event)
-{
- // Ignore events with multiple-touch points
- if (event.GetPointCount() != 1)
- {
- return false;
- }
-
- if (event.GetPoint(0).state == TouchPoint::Down)
- {
- // Cancel ongoing scrolling etc.
- mGestureState = Gesture::Clear;
-
- mScrollDistance = 0.0f;
- mScrollSpeed = 0.0f;
- Self().SetProperty(mPropertyScrollSpeed, mScrollSpeed);
-
- mScrollOvershoot = 0.0f;
- AnimateScrollOvershoot(0.0f);
-
- if(mScrollAnimation)
+ Dali::Toolkit::ScrollBar scrollBar = Dali::Toolkit::ScrollBar::DownCast(child);
+ if(scrollBar)
{
- mScrollCompletedSignal.Emit(GetCurrentScrollPosition());
+ 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);
}
-
- RemoveAnimation(mScrollAnimation);
}
- return true; // consume since we're potentially scrolling
+ Scrollable::OnChildAdd( child );
}
-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());
+ const Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
+ 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)
{
return false;
}
-void ItemView::ReapplyAllConstraints( float durationSeconds )
+void ItemView::ReapplyAllConstraints()
{
- for (ConstItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
+
+ for (ConstItemIter 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());
}
}
void ItemView::OnItemsRemoved()
{
- CalculateDomainSize(Self().GetCurrentSize());
+ CalculateDomainSize(Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ));
// Adjust scroll-position after an item is removed
if( mActiveLayout )
{
- float firstItemScrollPosition = ClampFirstItemPosition(GetCurrentLayoutPosition(0), Self().GetCurrentSize(), *mActiveLayout);
-
- mScrollPositionObject.SetProperty( ScrollConnector::SCROLL_POSITION, firstItemScrollPosition );
+ float firstItemScrollPosition = ClampFirstItemPosition(GetCurrentLayoutPosition(0), Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ), *mActiveLayout);
+ Self().SetProperty( Toolkit::ItemView::Property::LAYOUT_POSITION, firstItemScrollPosition );
}
}
-float ItemView::ClampFirstItemPosition(float targetPosition, const Vector3& targetSize, ItemLayout& layout)
+float ItemView::ClampFirstItemPosition( float targetPosition, const Vector3& targetSize, ItemLayout& layout, bool updateOvershoot )
{
Actor self = Self();
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));
+
+ if( updateOvershoot )
+ {
+ mScrollOvershoot = targetPosition - clamppedPosition;
+ }
return clamppedPosition;
}
+bool ItemView::OnTouch( Actor actor, const TouchData& touch )
+{
+ // Ignore events with multiple-touch points
+ if (touch.GetPointCount() != 1)
+ {
+ return false;
+ }
+
+ if ( touch.GetState( 0 ) == PointState::DOWN )
+ {
+ // Cancel ongoing scrolling etc.
+ mGestureState = Gesture::Clear;
+
+ mScrollDistance = 0.0f;
+ mScrollSpeed = 0.0f;
+ Self().SetProperty(Toolkit::ItemView::Property::SCROLL_SPEED, mScrollSpeed);
+
+ mScrollOvershoot = 0.0f;
+ AnimateScrollOvershoot(0.0f);
+
+ if(mScrollAnimation)
+ {
+ mScrollCompletedSignal.Emit(GetCurrentScrollPosition());
+ }
+
+ RemoveAnimation(mScrollAnimation);
+ }
+
+ return false; // Do not consume as we're potentially scrolling (detecting pan gestures)
+}
+
void ItemView::OnPan( const PanGesture& gesture )
{
Actor self = Self();
- const Vector3 layoutSize = Self().GetCurrentSize();
+ const Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
RemoveAnimation(mScrollAnimation);
, 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
- if(fabs(currentLayoutPosition - firstItemScrollPosition) > Math::MACHINE_EPSILON_0)
+ if( fabs(currentLayoutPosition - firstItemScrollPosition) < Math::MACHINE_EPSILON_0 )
{
- AnimateScrollOvershoot(0.0f);
+ AnimateScrollOvershoot( 0.0f );
+ RemoveAnimation( mScrollAnimation );
}
}
float firstItemScrollPosition = ClampFirstItemPosition(layoutPositionDelta, layoutSize, *mActiveLayout);
- float currentOvershoot = mScrollPositionObject.GetProperty<float>(ScrollConnector::OVERSHOOT);
+ float currentOvershoot = self.GetCurrentProperty< float >( 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 );
+
+ // If the view is moved in a direction against the overshoot indicator, then the indicator should be animated off.
+ // First make sure we are not in an animation, otherwise a previously started
+ // off-animation will be overwritten as the user continues scrolling.
+ if( !mInAnimation )
+ {
+ // Check if the movement is against the current overshoot amount (if we are currently displaying the indicator).
+ if( ( ( mScrollOvershoot > Math::MACHINE_EPSILON_0 ) && ( mScrollDistance < -Math::MACHINE_EPSILON_0 ) ) ||
+ ( ( mScrollOvershoot < Math::MACHINE_EPSILON_0 ) && ( mScrollDistance > Math::MACHINE_EPSILON_0 ) ) )
+ {
+ // The user has moved against the indicator direction.
+ // First, we reset the total displacement. This means the overshoot amount will become zero the next frame,
+ // and if the user starts dragging in the overshoot direction again, the indicator will appear once more.
+ mTotalPanDisplacement = Vector2::ZERO;
+ // Animate the overshoot indicator off.
+ AnimateScrollOvershoot( 0.0f, false );
+ }
+ else
+ {
+ // Only set the property directly if we are not animating the overshoot away,
+ // as otherwise this will overwrite the animation generated value.
+ self.SetProperty( Toolkit::ItemView::Property::OVERSHOOT, mScrollOvershoot );
+ }
+ }
}
break;
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)
}
}
float layoutPosition = mActiveLayout->GetClosestAnchorPosition( GetCurrentLayoutPosition(0) );
- Vector3 layoutSize = Self().GetCurrentSize();
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
if(!nextFocusActor)
{
// likely the current item is not buffered, so not in our item pool, probably best to get first viewable item
{
int nextItemID = GetItemId(commitedFocusableActor);
float layoutPosition = GetCurrentLayoutPosition(0);
- Vector3 layoutSize = Self().GetCurrentSize();
+ Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
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);
}
}
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);
RemoveAnimation(mScrollAnimation);
mRefreshEnabled = true;
DoRefresh(GetCurrentLayoutPosition(0), true);
+
+ // Emit the layout activated signal
+ mLayoutActivatedSignal.Emit();
}
void ItemView::OnOvershootOnFinished(Animation& animation)
{
AnimateScrollOvershoot(0.0f);
}
+ mInAnimation = false;
}
void ItemView::ScrollToItem(unsigned int itemId, float durationSeconds)
{
Actor self = Self();
- const Vector3 layoutSize = Self().GetCurrentSize();
+ const Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
float firstItemScrollPosition = ClampFirstItemPosition(mActiveLayout->GetItemScrollToPosition(itemId), layoutSize, *mActiveLayout);
if(durationSeconds > 0.0f)
{
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, mScrollToAlphaFunction );
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);
}
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(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(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);
+ 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(Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL, isLayoutScrollable);
}
}
-Vector3 ItemView::GetDomainSize() const
-{
- Actor self = Self();
-
- float minScrollPosition = self.GetProperty<float>(Toolkit::Scrollable::Property::SCROLL_POSITION_MIN);
- float maxScrollPosition = self.GetProperty<float>(Toolkit::Scrollable::Property::SCROLL_POSITION_MAX);
-
- return Vector3(0.0f, fabs(maxScrollPosition - minScrollPosition), 0.0f);
-}
-
bool ItemView::IsLayoutScrollable(const Vector3& layoutSize)
{
Actor self = Self();
- float currentLayoutPosition = ClampFirstItemPosition( GetCurrentLayoutPosition(0), layoutSize, *mActiveLayout );
- float forwardClampedPosition = ClampFirstItemPosition(currentLayoutPosition + 1.0, layoutSize, *mActiveLayout);
- float backwardClampedPosition = ClampFirstItemPosition(currentLayoutPosition - 1.0, layoutSize, *mActiveLayout);
+ float currentLayoutPosition = ClampFirstItemPosition( GetCurrentLayoutPosition(0), layoutSize, *mActiveLayout, false );
+ float forwardClampedPosition = ClampFirstItemPosition( currentLayoutPosition + 1.0, layoutSize, *mActiveLayout, false );
+ float backwardClampedPosition = ClampFirstItemPosition( currentLayoutPosition - 1.0, layoutSize, *mActiveLayout, false );
return (fabs(forwardClampedPosition - backwardClampedPosition) > Math::MACHINE_EPSILON_0);
}
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().GetCurrentProperty< Vector3 >( Actor::Property::SIZE )));
}
void ItemView::AddOverlay(Actor actor)
{
+ actor.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
Self().Add(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();
+ const Vector3 layoutSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
float firstItemScrollPosition = ClampFirstItemPosition(position.y, layoutSize, *mActiveLayout);
{
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, mScrollToAlphaFunction );
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);
}
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;
if( mOvershootOverlay )
{
- mOvershootOverlay.SetColor( color );
+ mOvershootOverlay.SetProperty( Actor::Property::COLOR, color );
}
}
-void ItemView::SetOvershootEnabled( bool enable )
+void ItemView::EnableScrollOvershoot( bool enable )
{
Actor self = Self();
if( enable )
{
- Property::Index effectOvershootPropertyIndex = Property::INVALID_INDEX;
- mOvershootOverlay = CreateBouncingEffectActor( effectOvershootPropertyIndex );
- mOvershootOverlay.SetColor(mOvershootEffectColor);
- mOvershootOverlay.SetParentOrigin(ParentOrigin::TOP_LEFT);
- mOvershootOverlay.SetAnchorPoint(AnchorPoint::TOP_LEFT);
- mOvershootOverlay.SetDrawMode(DrawMode::OVERLAY);
- self.Add(mOvershootOverlay);
-
- Constraint constraint = Constraint::New<Vector3>( Actor::Property::SIZE,
- ParentSource( Toolkit::Scrollable::Property::SCROLL_DIRECTION ),
- 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<Quaternion>( Actor::Property::ORIENTATION,
- ParentSource( Toolkit::Scrollable::Property::SCROLL_DIRECTION ),
- Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
- OvershootOverlayRotationConstraint() );
- mOvershootOverlay.ApplyConstraint(constraint);
-
- constraint = Constraint::New<Vector3>( Actor::Property::POSITION,
- ParentSource( Actor::Property::SIZE ),
- ParentSource( Toolkit::Scrollable::Property::SCROLL_DIRECTION ),
- Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
- OvershootOverlayPositionConstraint() );
- mOvershootOverlay.ApplyConstraint(constraint);
-
- constraint = Constraint::New<bool>( Actor::Property::VISIBLE,
- ParentSource( Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL ),
- OvershootOverlayVisibilityConstraint() );
- mOvershootOverlay.ApplyConstraint(constraint);
-
- constraint = Constraint::New<float>( effectOvershootPropertyIndex,
- Source( mScrollPositionObject, ScrollConnector::OVERSHOOT ),
- EqualToConstraint() );
- mOvershootOverlay.ApplyConstraint(constraint);
+ if( !mOvershootOverlay )
+ {
+ Property::Index effectOvershootPropertyIndex = Property::INVALID_INDEX;
+ mOvershootOverlay = CreateBouncingEffectActor( effectOvershootPropertyIndex );
+ mOvershootOverlay.SetProperty( Actor::Property::COLOR,mOvershootEffectColor);
+ mOvershootOverlay.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT );
+ mOvershootOverlay.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
+ mOvershootOverlay.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
+ self.Add(mOvershootOverlay);
+
+ ApplyOvershootSizeConstraint( mOvershootOverlay, mOvershootSize.height );
+
+ Constraint constraint = Constraint::New<Quaternion>( 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<Vector3>( 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<bool>( mOvershootOverlay, Actor::Property::VISIBLE, OvershootOverlayVisibilityConstraint );
+ constraint.AddSource( ParentSource( Toolkit::Scrollable::Property::CAN_SCROLL_VERTICAL ) );
+ constraint.Apply();
+
+ constraint = Constraint::New<float>( mOvershootOverlay, effectOvershootPropertyIndex, EqualToConstraint() );
+ constraint.AddSource( ParentSource( Toolkit::ItemView::Property::OVERSHOOT ) );
+ constraint.Apply();
+ }
}
else
{
Actor self = Self();
float scrollDistance = CalculateScrollDistance(mTotalPanDisplacement, *mActiveLayout) * mActiveLayout->GetScrollSpeedFactor();
float positionDelta = GetCurrentLayoutPosition(0) + scrollDistance;
- float minLayoutPosition = mActiveLayout->GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), Self().GetCurrentSize());
- self.SetProperty(mPropertyMinimumLayoutPosition, minLayoutPosition);
+ float minLayoutPosition = mActiveLayout->GetMinimumLayoutPosition(mItemFactory.GetNumberOfItems(), Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ));
+ 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;
}
return;
}
+ Actor self = Self();
+
if(mOvershootAnimationSpeed > Math::MACHINE_EPSILON_0)
{
- float currentOvershoot = mScrollPositionObject.GetProperty<float>(ScrollConnector::OVERSHOOT);
- float duration = mOvershootOverlay.GetCurrentSize().height * (animatingOn ? (1.0f - fabsf(currentOvershoot)) : fabsf(currentOvershoot)) / mOvershootAnimationSpeed;
+ float currentOvershoot = self.GetCurrentProperty< float >( Toolkit::ItemView::Property::OVERSHOOT );
+ float duration = 0.0f;
+
+ if (mOvershootOverlay)
+ {
+ duration = mOvershootOverlay.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).height * (animatingOn ? (1.0f - fabsf(currentOvershoot)) : fabsf(currentOvershoot)) / mOvershootAnimationSpeed;
+ }
+ // Mark the animation as in progress to prevent manual property sets overwriting it.
+ mInAnimation = true;
+ mAnimatingOvershootOn = animatingOn;
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 );
}
}
if( parentOrigin != mItemsParentOrigin )
{
mItemsParentOrigin = parentOrigin;
- for (ItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
+ for (ItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
{
- iter->second.SetParentOrigin(parentOrigin);
+ iter->second.SetProperty( Actor::Property::PARENT_ORIGIN,parentOrigin );
}
}
}
if( anchorPoint != mItemsAnchorPoint )
{
mItemsAnchorPoint = anchorPoint;
- for (ItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
+ for (ItemIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
{
- iter->second.SetAnchorPoint(anchorPoint);
+ iter->second.SetProperty( Actor::Property::ANCHOR_POINT,anchorPoint);
}
}
}
}
}
-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;
+ }
+
+ return connected;
+}
+
+void ItemView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+{
+ Toolkit::ItemView itemView = Toolkit::ItemView::DownCast( Dali::BaseHandle( object ) );
+
+ if( itemView )
+ {
+ ItemView& itemViewImpl( GetImpl( itemView ) );
+ switch( index )
+ {
+ case Toolkit::ItemView::Property::MINIMUM_SWIPE_SPEED:
+ {
+ itemViewImpl.SetMinimumSwipeSpeed( value.Get<float>() );
+ break;
+ }
+
+ case Toolkit::ItemView::Property::MINIMUM_SWIPE_DISTANCE:
+ {
+ itemViewImpl.SetMinimumSwipeDistance( value.Get<float>() );
+ break;
+ }
+
+ case Toolkit::ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP:
+ {
+ itemViewImpl.SetWheelScrollDistanceStep( value.Get<float>() );
+ break;
+ }
+
+ case Toolkit::ItemView::Property::SNAP_TO_ITEM_ENABLED:
+ {
+ itemViewImpl.SetAnchoring( value.Get<bool>() );
+ break;
+ }
+
+ case Toolkit::ItemView::Property::REFRESH_INTERVAL:
+ {
+ itemViewImpl.SetRefreshInterval( value.Get<float>() );
+ break;
+ }
+
+ case Toolkit::ItemView::Property::LAYOUT:
+ {
+ // Get a Property::Array from the property if possible.
+ Property::Array layoutArray;
+ if( value.Get( layoutArray ) )
+ {
+ itemViewImpl.SetLayoutArray( layoutArray );
+ }
+ break;
+ }
+ }
+ }
+}
+
+Property::Array ItemView::GetLayoutArray()
+{
+ return mlayoutArray;
+}
+
+void ItemView::SetLayoutArray( const Property::Array& layouts )
+{
+ mlayoutArray = layouts;
+ const int layoutCount = GetLayoutCount();
+ if( layoutCount > 0 )
+ {
+ for(int index = layoutCount - 1; index >= 0; --index)
+ {
+ RemoveLayout(index);
+ if(index == 0) break;
+ }
+ }
+
+ for( unsigned int arrayIdx = 0, arrayCount = layouts.Count(); arrayIdx < arrayCount; ++arrayIdx )
+ {
+ const Property::Value& element = layouts.GetElementAt( arrayIdx );
+
+ Property::Map* layout = element.GetMap();
+ if( layout != NULL )
+ {
+ for( unsigned int mapIdx = 0, mapCount = (*layout).Count(); mapIdx < mapCount; ++mapIdx )
+ {
+ KeyValuePair propertyPair( (*layout).GetKeyValue( mapIdx ) );
+
+ if(propertyPair.first == DefaultItemLayoutProperty::TYPE)
+ {
+ int layoutType = propertyPair.second.Get<int>();
+ if(layoutType <= DefaultItemLayout::SPIRAL && layoutType >= DefaultItemLayout::DEPTH)
+ {
+ //DEPTH, GRID, LIST, SPIRAL
+ switch(DefaultItemLayout::Type(layoutType))
+ {
+ case DefaultItemLayout::DEPTH:
+ {
+ Internal::DepthLayoutPtr depthLayout = Internal::DepthLayout::New();
+ (*depthLayout).SetLayoutProperties(*layout);
+ (*depthLayout).SetDepthLayoutProperties(*layout);
+ AddLayout(*depthLayout);
+ break;
+ }
+ case DefaultItemLayout::GRID:
+ {
+ Internal::GridLayoutPtr gridLayout = Internal::GridLayout::New();
+ (*gridLayout).SetLayoutProperties(*layout);
+ (*gridLayout).SetGridLayoutProperties(*layout);
+ AddLayout(*gridLayout);
+ break;
+ }
+ case DefaultItemLayout::LIST:
+ {
+ Internal::GridLayoutPtr listLayout = Internal::GridLayout::New();
+ listLayout->SetNumberOfColumns( 1 );
+ (*listLayout).SetLayoutProperties(*layout);
+ (*listLayout).SetGridLayoutProperties(*layout);
+ AddLayout(*listLayout);
+ break;
+ }
+ case DefaultItemLayout::SPIRAL:
+ {
+ Internal::SpiralLayoutPtr spiralLayout = Internal::SpiralLayout::New();
+ (*spiralLayout).SetLayoutProperties(*layout);
+ (*spiralLayout).SetSpiralLayoutProperties(*layout);
+ AddLayout(*spiralLayout);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+Property::Value ItemView::GetProperty( BaseObject* object, Property::Index index )
+{
+ Property::Value value;
+
+ Toolkit::ItemView itemView = Toolkit::ItemView::DownCast( Dali::BaseHandle( object ) );
+
+ if( itemView )
+ {
+ ItemView& itemViewImpl( GetImpl( itemView ) );
+ switch( index )
+ {
+ case Toolkit::ItemView::Property::MINIMUM_SWIPE_SPEED:
+ {
+ value = itemViewImpl.GetMinimumSwipeSpeed();
+ break;
+ }
+
+ case Toolkit::ItemView::Property::MINIMUM_SWIPE_DISTANCE:
+ {
+ value = itemViewImpl.GetMinimumSwipeDistance();
+ break;
+ }
+
+ case Toolkit::ItemView::Property::WHEEL_SCROLL_DISTANCE_STEP:
+ {
+ value = itemViewImpl.GetWheelScrollDistanceStep();
+ break;
+ }
+
+ case Toolkit::ItemView::Property::SNAP_TO_ITEM_ENABLED:
+ {
+ value = itemViewImpl.GetAnchoring();
+ break;
+ }
+
+ case Toolkit::ItemView::Property::REFRESH_INTERVAL:
+ {
+ value = itemViewImpl.GetRefreshInterval();
+ break;
+ }
+
+ case Toolkit::ItemView::Property::LAYOUT:
+ {
+ Property::Array layouts= itemViewImpl.GetLayoutArray();
+ value = layouts;
+ break;
+ }
+ }
+ }
+
+ return value;
+}
+
+bool ItemView::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
+{
+ Dali::BaseHandle handle( object );
+
+ Toolkit::ItemView itemView = Toolkit::ItemView::DownCast( handle );
- // Refresh the cache immediately when the scroll position is changed.
- DoRefresh(position, false); // No need to cache extra items.
+ DALI_ASSERT_ALWAYS( itemView );
+
+ if( 0 == strcmp( actionName.c_str(), ACTION_STOP_SCROLLING ) )
+ {
+ GetImpl( itemView ).DoStopScrolling();
+ }
+ else if ( 0 == strcmp( actionName.c_str(), ACTION_ENABLE_REFRESH ) )
+ {
+ GetImpl( itemView ).SetRefreshNotificationEnabled( true );
+ }
+ else if ( 0 == strcmp( actionName.c_str(), ACTION_DISABLE_REFRESH ) )
+ {
+ GetImpl( itemView ).SetRefreshNotificationEnabled( false );
+ }
+
+ return true;
+}
+
+void ItemView::DoStopScrolling()
+{
+ if( mScrollAnimation )
+ {
+ mScrollAnimation.Stop();
+ mScrollAnimation.Reset();
+ }
+}
+
+void ItemView::SetRefreshNotificationEnabled( bool enabled )
+{
+ mRefreshNotificationEnabled = enabled;
}
} // namespace Internal