/*
- * Copyright (c) 2015 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.
#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/public-api/object/property-map.h>
+#include <dali/devel-api/object/property-helper-devel.h>
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
#include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
#include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view-constraints.h>
+#include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-mode.h>
#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-overshoot-indicator-impl.h>
#include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-effect-impl.h>
DALI_PROPERTY_REGISTRATION( Toolkit, ScrollView, "panningEnabled", BOOLEAN, PANNING_ENABLED )
DALI_PROPERTY_REGISTRATION( Toolkit, ScrollView, "axisAutoLockEnabled", BOOLEAN, AXIS_AUTO_LOCK_ENABLED )
DALI_PROPERTY_REGISTRATION( Toolkit, ScrollView, "wheelScrollDistanceStep", VECTOR2, WHEEL_SCROLL_DISTANCE_STEP )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollView, "scrollMode", MAP, SCROLL_MODE )
DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "scrollPosition", VECTOR2, SCROLL_POSITION)
DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, ScrollView, "scrollPrePosition", VECTOR2, SCROLL_PRE_POSITION)
}
ScrollView::ScrollView()
-: ScrollBase( ControlBehaviour( REQUIRES_WHEEL_EVENTS ) ), // Enable size negotiation
+: ScrollBase( ControlBehaviour( REQUIRES_WHEEL_EVENTS | DISABLE_STYLE_CHANGE_SIGNALS ) ), // Enable size negotiation
mTouchDownTime(0u),
mGestureStackDepth(0),
mScrollStateFlags(0),
mAlterChild(false),
mDefaultMaxOvershoot(true),
mCanScrollHorizontal(true),
- mCanScrollVertical(true)
+ mCanScrollVertical(true),
+ mTransientScrollBar(true)
{
}
void ScrollView::OnStageConnection( int depth )
{
- ScrollBase::OnStageConnection( depth );
-
DALI_LOG_SCROLL_STATE("[0x%X]", this);
if ( mSensitive )
SetScrollSensitive( false );
SetScrollSensitive( true );
}
+
if(IsOvershootEnabled())
{
// try and make sure property notifications are set
EnableScrollOvershoot(true);
}
+
+ ScrollBase::OnStageConnection( depth );
}
void ScrollView::OnStageDisconnection()
if(child)
{
- Vector2 position = Self().GetProperty<Vector2>(Toolkit::ScrollView::Property::SCROLL_POSITION);
+ Vector2 position = Self().GetCurrentProperty<Vector2>( Toolkit::ScrollView::Property::SCROLL_POSITION );
// Get center-point of the Actor.
Vector3 childPosition = GetPositionOfAnchor(child, AnchorPoint::CENTER);
}
DALI_LOG_SCROLL_STATE("[0x%X] position-changed, mScrollTargetPosition[%.2f, %.2f], mScrollPrePosition[%.2f, %.2f], mScrollPostPosition[%.2f, %.2f]", this, mScrollTargetPosition.x, mScrollTargetPosition.y, mScrollPrePosition.x, mScrollPrePosition.y, mScrollPostPosition.x, mScrollPostPosition.y );
- DALI_LOG_SCROLL_STATE("[0x%X] SCROLL_PRE_POSITION[%.2f, %.2f], SCROLL_POSITION[%.2f, %.2f]", this, self.GetProperty( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ).Get<Vector2>().x, self.GetProperty( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ).Get<Vector2>().y, self.GetProperty( Toolkit::ScrollView::Property::SCROLL_POSITION ).Get<Vector2>().x, self.GetProperty( Toolkit::ScrollView::Property::SCROLL_POSITION ).Get<Vector2>().y );
+ DALI_LOG_SCROLL_STATE("[0x%X] SCROLL_PRE_POSITION[%.2f, %.2f], SCROLL_POSITION[%.2f, %.2f]", this, self.GetCurrentProperty( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ).Get<Vector2>().x, self.GetCurrentProperty( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ).Get<Vector2>().y, self.GetCurrentProperty( Toolkit::ScrollView::Property::SCROLL_POSITION ).Get<Vector2>().x, self.GetCurrentProperty( Toolkit::ScrollView::Property::SCROLL_POSITION ).Get<Vector2>().y );
}
SetScrollUpdateNotification(true);
mInternalActor.Remove( actor );
}
+void ScrollView::SetOvershootSize( const Vector2& size )
+{
+ mOvershootSize = size;
+ if( IsOvershootEnabled() && mOvershootIndicator )
+ {
+ mOvershootIndicator->AttachToScrollable(*this);
+ }
+}
+
void ScrollView::SetOvershootEffectColor( const Vector4& color )
{
mOvershootEffectColor = color;
Vector2 ScrollView::GetPropertyPrePosition() const
{
- Vector2 position = Self().GetProperty<Vector2>(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION);
+ Vector2 position = Self().GetCurrentProperty< Vector2 >( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION );
WrapPosition(position);
return position;
}
Vector2 ScrollView::GetPropertyPosition() const
{
- Vector2 position = Self().GetProperty<Vector2>(Toolkit::ScrollView::Property::SCROLL_POSITION);
+ Vector2 position = Self().GetCurrentProperty< Vector2 >( Toolkit::ScrollView::Property::SCROLL_POSITION );
WrapPosition(position);
return position;
{
mOvershootIndicator->Reset();
}
+
+ ScrollBase::OnSizeSet( size );
}
void ScrollView::OnChildAdd(Actor& child)
ScrollBase::OnChildAdd( child );
Dali::Toolkit::ScrollBar scrollBar = Dali::Toolkit::ScrollBar::DownCast(child);
- if(scrollBar)
+ if( scrollBar )
{
- mInternalActor.Add(scrollBar);
- if(scrollBar.GetScrollDirection() == Toolkit::ScrollBar::Horizontal)
+ mScrollBar = scrollBar;
+ scrollBar.SetName("ScrollBar");
+
+ mInternalActor.Add( scrollBar );
+ if( scrollBar.GetScrollDirection() == Toolkit::ScrollBar::Horizontal )
{
- scrollBar.SetScrollPropertySource(Self(),
- Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_X,
- Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_X,
- Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_MAX_X,
- Toolkit::ScrollView::Property::SCROLL_DOMAIN_SIZE_X);
+ scrollBar.SetScrollPropertySource( Self(),
+ Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_X,
+ Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_X,
+ Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_MAX_X,
+ Toolkit::ScrollView::Property::SCROLL_DOMAIN_SIZE_X );
}
else
{
- scrollBar.SetScrollPropertySource(Self(),
- Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_Y,
- Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_Y,
- Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_MAX_Y,
- Toolkit::ScrollView::Property::SCROLL_DOMAIN_SIZE_Y);
+ scrollBar.SetScrollPropertySource( Self(),
+ Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_Y,
+ Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_Y,
+ Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_MAX_Y,
+ Toolkit::ScrollView::Property::SCROLL_DOMAIN_SIZE_Y );
+ }
+
+ if( mTransientScrollBar )
+ {
+ // Show the scroll-indicator for a brief period
+ Property::Map emptyMap;
+ scrollBar.DoAction( "ShowTransientIndicator", emptyMap );
}
}
else if(mAlterChild)
void ScrollView::ResetScrolling()
{
Actor self = Self();
- self.GetProperty(Toolkit::ScrollView::Property::SCROLL_POSITION).Get(mScrollPostPosition);
+ self.GetCurrentProperty( Toolkit::ScrollView::Property::SCROLL_POSITION ).Get( mScrollPostPosition );
mScrollPrePosition = mScrollPostPosition;
DALI_LOG_SCROLL_STATE("[0x%X] Setting SCROLL_PRE_POSITION To[%.2f, %.2f]", this, mScrollPostPosition.x, mScrollPostPosition.y );
self.SetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION, mScrollPostPosition);
void ScrollView::UpdateLocalScrollProperties()
{
Actor self = Self();
- self.GetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get(mScrollPrePosition);
- self.GetProperty(Toolkit::ScrollView::Property::SCROLL_POSITION).Get(mScrollPostPosition);
+ self.GetCurrentProperty( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ).Get( mScrollPrePosition );
+ self.GetCurrentProperty( Toolkit::ScrollView::Property::SCROLL_POSITION ).Get( mScrollPostPosition );
}
// private functions
if( duration > Math::MACHINE_EPSILON_10 )
{
Actor self = Self();
- DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get<Vector2>().x, position );
+ DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetCurrentProperty( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ).Get< Vector2 >().x, position );
mInternalXAnimation = Animation::New(duration);
DALI_LOG_SCROLL_STATE("[0x%X], mInternalXAnimation[0x%X]", this, mInternalXAnimation.GetObjectPtr() );
mInternalXAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished);
if( duration > Math::MACHINE_EPSILON_10 )
{
Actor self = Self();
- DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetProperty(Toolkit::ScrollView::Property::SCROLL_PRE_POSITION).Get<Vector2>().y, position );
+ DALI_LOG_SCROLL_STATE("[0x%X], Animating from[%.2f] to[%.2f]", this, self.GetCurrentProperty( Toolkit::ScrollView::Property::SCROLL_PRE_POSITION ).Get< Vector2 >().y, position );
mInternalYAnimation = Animation::New(duration);
DALI_LOG_SCROLL_STATE("[0x%X], mInternalYAnimation[0x%X]", this, mInternalYAnimation.GetObjectPtr() );
mInternalYAnimation.FinishedSignal().Connect(this, &ScrollView::OnScrollAnimationFinished);
if( source == mInternalXAnimation )
{
- DALI_LOG_SCROLL_STATE("[0x%X] mInternalXAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalXAnimation.GetObjectPtr(), mScrollTargetPosition.x, Self().GetProperty(SCROLL_PRE_POSITION).Get<Vector2>().x, mScrollPostPosition.x );
+ DALI_LOG_SCROLL_STATE("[0x%X] mInternalXAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalXAnimation.GetObjectPtr(), mScrollTargetPosition.x, Self().GetCurrentProperty( SCROLL_PRE_POSITION ).Get< Vector2 >().x, mScrollPostPosition.x );
if( !(mScrollStateFlags & AnimatingInternalY) )
{
if( source == mInternalYAnimation )
{
- DALI_LOG_SCROLL_STATE("[0x%X] mInternalYAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalYAnimation.GetObjectPtr(), mScrollTargetPosition.y, Self().GetProperty(SCROLL_PRE_POSITION).Get<Vector2>().y, mScrollPostPosition.y );
+ DALI_LOG_SCROLL_STATE("[0x%X] mInternalYAnimation[0x%X], expected[%.2f], actual[%.2f], post[%.2f]", this, mInternalYAnimation.GetObjectPtr(), mScrollTargetPosition.y, DevelHandle::GetProperty( Self(), SCROLL_PRE_POSITION ).Get< Vector2 >().y, mScrollPostPosition.y );
if( !(mScrollStateFlags & AnimatingInternalX) )
{
self.SetProperty( Toolkit::ScrollView::Property::START_PAGE_POSITION, Vector3(gesture.position.x, gesture.position.y, 0.0f) );
UpdateMainInternalConstraint();
+ Toolkit::ScrollBar scrollBar = mScrollBar.GetHandle();
+ if( scrollBar && mTransientScrollBar )
+ {
+ Vector3 size = Self().GetCurrentSize();
+ const Toolkit::RulerDomain& rulerDomainX = mRulerX->GetDomain();
+ const Toolkit::RulerDomain& rulerDomainY = mRulerY->GetDomain();
+
+ if( ( rulerDomainX.max > size.width ) || ( rulerDomainY.max > size.height ) )
+ {
+ scrollBar.ShowIndicator();
+ }
+ }
break;
}
{
mScrollMainInternalPrePositionConstraint.Remove();
}
+
+ Toolkit::ScrollBar scrollBar = mScrollBar.GetHandle();
+ if( scrollBar && mTransientScrollBar )
+ {
+ scrollBar.HideIndicator();
+ }
}
else
{
scrollViewImpl.SetWheelScrollDistanceStep( value.Get<Vector2>() );
break;
}
+ case Toolkit::ScrollView::Property::SCROLL_MODE:
+ {
+ Property::Map* map = value.GetMap();
+ if( map )
+ {
+ scrollViewImpl.SetScrollMode( *map );
+ }
+ }
}
}
}
return value;
}
+void ScrollView::SetScrollMode( const Property::Map& scrollModeMap )
+{
+ Toolkit::RulerPtr rulerX, rulerY;
+
+ // Check the scroll mode in the X axis
+ bool xAxisScrollEnabled = true;
+ Property::Value* valuePtr = scrollModeMap.Find( Toolkit::ScrollMode::X_AXIS_SCROLL_ENABLED, "xAxisScrollEnabled" );
+ if( valuePtr && valuePtr->GetType() == Property::BOOLEAN )
+ {
+ valuePtr->Get( xAxisScrollEnabled );
+ }
+
+ if( !xAxisScrollEnabled )
+ {
+ // Default ruler and disabled
+ rulerX = new Toolkit::DefaultRuler();
+ rulerX->Disable();
+ }
+ else
+ {
+ valuePtr = scrollModeMap.Find( Toolkit::ScrollMode::X_AXIS_SNAP_TO_INTERVAL, "xAxisSnapToInterval" );
+ float xAxisSnapToInterval = 0.0f;
+ if( valuePtr && valuePtr->Get( xAxisSnapToInterval ) )
+ {
+ // Fixed ruler and enabled
+ rulerX = new Toolkit::FixedRuler( xAxisSnapToInterval );
+ }
+ else
+ {
+ // Default ruler and enabled
+ rulerX = new Toolkit::DefaultRuler();
+ }
+
+ valuePtr = scrollModeMap.Find( Toolkit::ScrollMode::X_AXIS_SCROLL_BOUNDARY, "xAxisScrollBoundary" );
+ float xAxisScrollBoundary = 0.0f;
+ if( valuePtr && valuePtr->Get( xAxisScrollBoundary ) )
+ {
+ // By default ruler domain is disabled unless set
+ rulerX->SetDomain( Toolkit::RulerDomain( 0, xAxisScrollBoundary, true ) );
+ }
+ }
+
+ // Check the scroll mode in the Y axis
+ bool yAxisScrollEnabled = true;
+ valuePtr = scrollModeMap.Find( Toolkit::ScrollMode::Y_AXIS_SCROLL_ENABLED, "yAxisScrollEnabled" );
+ if( valuePtr && valuePtr->GetType() == Property::BOOLEAN )
+ {
+ valuePtr->Get( yAxisScrollEnabled );
+ }
+
+ if( !yAxisScrollEnabled )
+ {
+ // Default ruler and disabled
+ rulerY = new Toolkit::DefaultRuler();
+ rulerY->Disable();
+ }
+ else
+ {
+ valuePtr = scrollModeMap.Find( Toolkit::ScrollMode::Y_AXIS_SNAP_TO_INTERVAL, "yAxisSnapToInterval" );
+ float yAxisSnapToInterval = 0.0f;
+ if( valuePtr && valuePtr->Get( yAxisSnapToInterval ) )
+ {
+ // Fixed ruler and enabled
+ rulerY = new Toolkit::FixedRuler(yAxisSnapToInterval);
+ }
+ else
+ {
+ // Default ruler and enabled
+ rulerY = new Toolkit::DefaultRuler();
+ }
+
+ valuePtr = scrollModeMap.Find( Toolkit::ScrollMode::Y_AXIS_SCROLL_BOUNDARY, "yAxisScrollBoundary" );
+ float yAxisScrollBoundary = 0.0f;
+ if( valuePtr && valuePtr->Get( yAxisScrollBoundary ) )
+ {
+ // By default ruler domain is disabled unless set
+ rulerY->SetDomain( Toolkit::RulerDomain( 0, yAxisScrollBoundary, true ) );
+ }
+ }
+
+ SetRulerX(rulerX);
+ SetRulerY(rulerY);
+}
+
} // namespace Internal
} // namespace Toolkit