#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-overshoot-indicator-impl.h>
#include <dali/integration-api/debug.h>
+#define ENABLED_SCROLL_STATE_LOGGING
+
+#ifdef ENABLED_SCROLL_STATE_LOGGING
+#define DALI_LOG_SCROLL_STATE(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugInfo, "%s:%d " format, __PRETTY_FUNCTION__, __LINE__, ## args)
+#else
+#define DALI_LOG_SCROLL_STATE(format, args...)
+#endif
+
// TODO: Change to two class system:
// 1. DraggableActor (is an actor which can be dragged anywhere/scaled/rotated, can be set to range using the ruler)
// 2. ScrollView (contains a draggable actor that can a) be dragged in the negative X, and Y domain, b) has a hitArea for touches)
const float DEFAULT_OVERSHOOT_ANIMATION_DURATION = 0.35f; // time in seconds
const Vector2 OVERSCROLL_CLAMP(1.0f, 1.0f); // maximum overscroll allowed in pixels when overshoot indicator is being used
const float TOUCH_DOWN_TIMER_INTERVAL = 100.0f;
+const float DEFAULT_SCROLL_UPDATE_DISTANCE( 30.0f ); ///< Default distance to travel in pixels for scroll update signal
// predefined effect values
const Vector3 ANGLE_CAROUSEL_ROTATE(Math::PI * 0.5f, Math::PI * 0.5f, 0.0f);
float operator()(const float& current,
const PropertyInput& scrollPrePositionProperty,
- const PropertyInput& scrollPostPositionProperty)
+ const PropertyInput& scrollPostPositionProperty,
+ const PropertyInput& canScrollProperty)
{
- const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
- const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
- float newOvershoot = scrollPrePosition.x - scrollPostPosition.x;
- return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
+ if( canScrollProperty.GetBoolean() )
+ {
+ const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
+ const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
+ float newOvershoot = scrollPrePosition.x - scrollPostPosition.x;
+ return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
+ }
+ return 0.0f;
}
float mMaxOvershoot;
float operator()(const float& current,
const PropertyInput& scrollPrePositionProperty,
- const PropertyInput& scrollPostPositionProperty)
+ const PropertyInput& scrollPostPositionProperty,
+ const PropertyInput& canScrollProperty)
{
- const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
- const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
- float newOvershoot = scrollPrePosition.y - scrollPostPosition.y;
- return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
+ if( canScrollProperty.GetBoolean() )
+ {
+ const Vector3& scrollPrePosition = scrollPrePositionProperty.GetVector3();
+ const Vector3& scrollPostPosition = scrollPostPositionProperty.GetVector3();
+ float newOvershoot = scrollPrePosition.y - scrollPostPosition.y;
+ return (newOvershoot > 0.0f ? std::min(newOvershoot, mMaxOvershoot) : std::max(newOvershoot, -mMaxOvershoot)) / mMaxOvershoot;
+ }
+ return 0.0f;
}
float mMaxOvershoot;
mMinTouchesForPanning(1),
mMaxTouchesForPanning(1),
mLockAxis(LockPossible),
- mRefreshIntervalMilliseconds(DEFAULT_REFRESH_INTERVAL_MILLISECONDS),
+ mScrollUpdateDistance(DEFAULT_SCROLL_UPDATE_DISTANCE),
mOvershootDelay(1.0f),
mMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT),
mUserMaxOvershoot(Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT, Toolkit::ScrollView::DEFAULT_MAX_OVERSHOOT),
void ScrollView::OnControlStageConnection()
{
+ DALI_LOG_SCROLL_STATE("[0x%X]", this);
+
if ( mSensitive )
{
SetScrollSensitive( false );
void ScrollView::OnControlStageDisconnection()
{
+ DALI_LOG_SCROLL_STATE("[0x%X]", this);
+
StopAnimation();
}
ScrollView::~ScrollView()
{
+ DALI_LOG_SCROLL_STATE("[0x%X]", this);
}
AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
void ScrollView::UpdatePropertyDomain(const Vector3& size)
{
Actor self = Self();
- Vector3 min = self.GetProperty<Vector3>(mPropertyPositionMin);
- Vector3 max = self.GetProperty<Vector3>(mPropertyPositionMax);
+ Vector3 min = mMinScroll;
+ Vector3 max = mMaxScroll;
bool scrollPositionChanged = false;
bool domainChanged = false;
scrollPositionChanged = true;
mScrollPrePosition.x = Clamp(mScrollPrePosition.x, -(max.x - size.x), -min.x);
}
- if((fabsf(max.x - min.x) - size.x) > Math::MACHINE_EPSILON_10000)
- {
- canScrollHorizontal = true;
- }
+ }
+ if( (fabsf(rulerDomain.max - rulerDomain.min) - size.x) > Math::MACHINE_EPSILON_10000 )
+ {
+ canScrollHorizontal = true;
}
}
scrollPositionChanged = true;
mScrollPrePosition.y = Clamp(mScrollPrePosition.y, -(max.y - size.y), -min.y);
}
- if((fabsf(max.y - min.y) - size.y) > Math::MACHINE_EPSILON_10000)
- {
- canScrollVertical = true;
- }
+ }
+ if( (fabsf(rulerDomain.max - rulerDomain.min) - size.y) > Math::MACHINE_EPSILON_10000 )
+ {
+ canScrollVertical = true;
}
}
// avoid setting properties if possible, otherwise this will cause an entire update as well as triggering constraints using each property we update
}
if( self.GetProperty<bool>(mPropertyCanScrollHorizontal) != canScrollHorizontal )
{
- self.SetProperty(mPropertyCanScrollHorizontal, canScrollVertical);
+ self.SetProperty(mPropertyCanScrollHorizontal, canScrollHorizontal);
}
if( scrollPositionChanged )
{
}
if( domainChanged )
{
+ mMinScroll = min;
+ mMaxScroll = max;
self.SetProperty(mPropertyPositionMin, min );
self.SetProperty(mPropertyPositionMax, max );
}
Actor self = Self();
PanGestureDetector panGesture( GetPanGestureDetector() );
+ DALI_LOG_SCROLL_STATE("[0x%X] sensitive[%d]", this, int(sensitive));
+
if((!mSensitive) && (sensitive))
{
mSensitive = sensitive;
int ScrollView::GetRefreshInterval() const
{
- return mRefreshIntervalMilliseconds;
+ return mScrollUpdateDistance;
}
void ScrollView::SetRefreshInterval(int milliseconds)
{
- mRefreshIntervalMilliseconds = milliseconds;
+ mScrollUpdateDistance = milliseconds;
+}
+
+int ScrollView::GetScrollUpdateDistance() const
+{
+ return mScrollUpdateDistance;
+}
+
+void ScrollView::SetScrollUpdateDistance(int distance)
+{
+ mScrollUpdateDistance = distance;
}
bool ScrollView::GetAxisAutoLock() const
{
// set mScrolling to false, in case user has code that interrogates mScrolling Getter() in complete.
mScrolling = false;
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
mScrollCompletedSignalV2.Emit( currentScrollPosition );
}
Self().SetProperty(mPropertyScrolling, true);
mScrolling = true;
+
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignalV2 1 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
mScrollStartedSignalV2.Emit( currentScrollPosition );
bool animating = AnimateTo(-position,
Vector3::ONE * duration,
// if not animating, then this pan has completed right now.
Self().SetProperty(mPropertyScrolling, false);
mScrolling = false;
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 2 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
+ SetScrollUpdateNotification(false);
mScrollCompletedSignalV2.Emit( currentScrollPosition );
}
}
mScrollPreScale = mScrollPostScale = scale;
}
}
- StartRefreshTimer();
+ SetScrollUpdateNotification(true);
// Always send a snap event when AnimateTo is called.
Toolkit::ScrollView::SnapEvent snapEvent;
snapEvent.rotation = rotation;
snapEvent.duration = totalDuration;
+ DALI_LOG_SCROLL_STATE("[0x%X] mSnapStartedSignalV2 [%.2f, %.2f]", this, snapEvent.position.x, snapEvent.position.y);
mSnapStartedSignalV2.Emit( snapEvent );
return (mScrollStateFlags & SCROLL_ANIMATION_FLAGS) != 0;
void ScrollView::HandleStoppedAnimation()
{
- // Animation has stopped, so stop sending the scroll-update signal.
- CancelRefreshTimer();
+ SetScrollUpdateNotification(false);
}
void ScrollView::HandleSnapAnimationFinished()
self.SetProperty(mPropertyPrePosition, mScrollPrePosition);
Vector3 currentScrollPosition = GetCurrentScrollPosition();
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 3 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
mScrollCompletedSignalV2.Emit( currentScrollPosition );
mDomainOffset += deltaPosition - mScrollPostPosition;
HandleStoppedAnimation();
}
+void ScrollView::SetScrollUpdateNotification( bool enabled )
+{
+ Actor self = Self();
+ if( mScrollXUpdateNotification )
+ {
+ // disconnect now to avoid a notification before removed from update thread
+ mScrollXUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification);
+ self.RemovePropertyNotification(mScrollXUpdateNotification);
+ mScrollXUpdateNotification.Reset();
+ }
+ if( enabled )
+ {
+ mScrollXUpdateNotification = self.AddPropertyNotification(mPropertyPosition, 0, StepCondition(mScrollUpdateDistance, 0.0f));
+ mScrollXUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification );
+ }
+ if( mScrollYUpdateNotification )
+ {
+ // disconnect now to avoid a notification before removed from update thread
+ mScrollYUpdateNotification.NotifySignal().Disconnect(this, &ScrollView::OnScrollUpdateNotification);
+ self.RemovePropertyNotification(mScrollYUpdateNotification);
+ mScrollYUpdateNotification.Reset();
+ }
+ if( enabled )
+ {
+ mScrollYUpdateNotification = self.AddPropertyNotification(mPropertyPosition, 1, StepCondition(mScrollUpdateDistance, 0.0f));
+ mScrollYUpdateNotification.NotifySignal().Connect( this, &ScrollView::OnScrollUpdateNotification );
+ }
+}
+
+void ScrollView::OnScrollUpdateNotification(Dali::PropertyNotification& source)
+{
+ // Guard against destruction during signal emission
+ Toolkit::ScrollView handle( GetOwner() );
+
+ Vector3 currentScrollPosition = GetCurrentScrollPosition();
+ mScrollUpdatedSignalV2.Emit( currentScrollPosition );
+}
+
bool ScrollView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
{
Dali::BaseHandle handle( object );
}
else if( index == mPropertyPrePosition )
{
+ DALI_LOG_SCROLL_STATE("[0x%X]", this);
propertyValue.Get(mScrollPrePosition);
}
}
UpdateLocalScrollProperties();
Vector3 currentScrollPosition = GetCurrentScrollPosition();
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 4 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
mScrollCompletedSignalV2.Emit( currentScrollPosition );
}
}
mScrollStateFlags &= ~SCROLL_X_STATE_MASK;
// if internal x not equal to inputed parameter, animate it
- float current = self.GetProperty<Vector3>(mPropertyPrePosition).x;
- float duration = fabsf(position - current);
- mInternalXAnimation = Animation::New(duration);
- mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
- mInternalXAnimation.AnimateTo(Property(self, mPropertyPrePosition, 0), position);
- mInternalXAnimation.Play();
+ float duration = std::min(fabsf((position - mScrollPrePosition.x) / mMaxOvershoot.x) * mSnapOvershootDuration, mSnapOvershootDuration);
+ if( duration > Math::MACHINE_EPSILON_1 )
+ {
+ mInternalXAnimation = Animation::New(duration);
+ mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
+ mInternalXAnimation.AnimateTo(Property(self, mPropertyPrePosition, 0), position);
+ mInternalXAnimation.Play();
- // add internal animation state flag
- mScrollStateFlags |= SnappingInternalX;
+ // add internal animation state flag
+ mScrollStateFlags |= SnappingInternalX;
+ }
}
void ScrollView::SnapInternalYTo(float position)
mScrollStateFlags &= ~SCROLL_Y_STATE_MASK;
// if internal y not equal to inputed parameter, animate it
- float current = self.GetProperty<Vector3>(mPropertyPrePosition).y;
- float duration = fabsf(position - current);
- mInternalYAnimation = Animation::New(duration);
- mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
- mInternalYAnimation.AnimateTo(Property(self, mPropertyPrePosition, 1), position);
- mInternalYAnimation.Play();
+ float duration = std::min(fabsf((position - mScrollPrePosition.y) / mMaxOvershoot.y) * mSnapOvershootDuration, mSnapOvershootDuration);
+ if( duration > Math::MACHINE_EPSILON_1 )
+ {
+ mInternalYAnimation = Animation::New(duration);
+ mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnSnapInternalPositionFinished);
+ mInternalYAnimation.AnimateTo(Property(self, mPropertyPrePosition, 1), position);
+ mInternalYAnimation.Play();
- // add internal animation state flag
- mScrollStateFlags |= SnappingInternalY;
+ // add internal animation state flag
+ mScrollStateFlags |= SnappingInternalY;
+ }
}
void ScrollView::GestureStarted()
mScrolling = false;
// send negative scroll position since scroll internal scroll position works as an offset for actors,
// give applications the position within the domain from the scroll view's anchor position
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 5 [%.2f, %.2f]", this, -mScrollPostPosition.x, -mScrollPostPosition.y);
mScrollCompletedSignalV2.Emit( -mScrollPostPosition );
}
}
Vector3 currentScrollPosition = GetCurrentScrollPosition();
Self().SetProperty(mPropertyScrolling, true);
mScrolling = true;
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollStartedSignalV2 2 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
mScrollStartedSignalV2.Emit( currentScrollPosition );
}
else if( (state == Gesture::Finished) ||
if(!animating)
{
// if not animating, then this pan has completed right now.
+ SetScrollUpdateNotification(false);
mScrolling = false;
Self().SetProperty(mPropertyScrolling, false);
Vector3 currentScrollPosition = GetCurrentScrollPosition();
+ DALI_LOG_SCROLL_STATE("[0x%X] mScrollCompletedSignalV2 6 [%.2f, %.2f]", this, currentScrollPosition.x, currentScrollPosition.y);
mScrollCompletedSignalV2.Emit( currentScrollPosition );
- if( fabs(mScrollPrePosition.x - mScrollTargetPosition.x) > Math::MACHINE_EPSILON_10 )
- {
- SnapInternalXTo(mScrollTargetPosition.x);
- }
- if( fabs(mScrollPrePosition.y - mScrollTargetPosition.y) > Math::MACHINE_EPSILON_10 )
- {
- SnapInternalYTo(mScrollTargetPosition.y);
- }
}
}
Constraint constraint = Constraint::New<float>( mPropertyOvershootX,
LocalSource( mPropertyPrePosition ),
LocalSource( mPropertyPosition ),
+ LocalSource( mPropertyCanScrollHorizontal ),
OvershootXConstraint(mMaxOvershoot.x) );
mScrollMainInternalOvershootXConstraint = self.ApplyConstraint( constraint );
constraint = Constraint::New<float>( mPropertyOvershootY,
LocalSource( mPropertyPrePosition ),
LocalSource( mPropertyPosition ),
+ LocalSource( mPropertyCanScrollVertical ),
OvershootYConstraint(mMaxOvershoot.y) );
mScrollMainInternalOvershootYConstraint = self.ApplyConstraint( constraint );
}
ApplyConstraintToBoundActors(constraint);
}
-void ScrollView::StartRefreshTimer()
-{
- if(mRefreshIntervalMilliseconds > 0)
- {
- if (!mRefreshTimer)
- {
- mRefreshTimer = Timer::New( mRefreshIntervalMilliseconds );
- mRefreshTimer.TickSignal().Connect( this, &ScrollView::OnRefreshTick );
- }
-
- if (!mRefreshTimer.IsRunning())
- {
- mRefreshTimer.Start();
- }
- }
-}
-
-void ScrollView::CancelRefreshTimer()
-{
- if (mRefreshTimer)
- {
- mRefreshTimer.Stop();
- }
-}
-
-bool ScrollView::OnRefreshTick()
-{
- // Guard against destruction during signal emission
- Toolkit::ScrollView handle( GetOwner() );
-
- Vector3 currentScrollPosition = GetCurrentScrollPosition();
- mScrollUpdatedSignalV2.Emit( currentScrollPosition );
-
- return true;
-}
-
} // namespace Internal
} // namespace Toolkit