-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
// INTERNAL INCLUDES
#include <dali-toolkit/internal/controls/scrollable/scrollable-impl.h>
-#include <dali-toolkit/internal/controls/scroll-component/scroll-bar-impl.h>
+#include <dali-toolkit/internal/controls/scroll-component/scroll-bar-internal-impl.h>
using namespace Dali;
namespace Toolkit
{
+const Property::Index Scrollable::PROPERTY_OVERSHOOT_EFFECT_COLOR( Toolkit::Internal::Control::CONTROL_PROPERTY_END_INDEX + 1 );
+const Property::Index Scrollable::PROPERTY_OVERSHOOT_ANIMATION_SPEED( Toolkit::Internal::Control::CONTROL_PROPERTY_END_INDEX + 2 );
+
namespace Internal
{
namespace
{
+const Vector4 DEFAULT_OVERSHOOT_COLOUR(0.0f, 0.64f, 0.85f, 0.25f);
+const float DEFAULT_OVERSHOOT_ANIMATION_SPEED(120.0f); // 120 pixels per second
+
+// Signals
+
+const char* const SIGNAL_SCROLL_STARTED = "scroll-started";
+const char* const SIGNAL_SCROLL_COMPLETED = "scroll-completed";
+const char* const SIGNAL_SCROLL_UPDATED = "scroll-updated";
BaseHandle Create()
{
return BaseHandle();
}
-TypeRegistration mType( typeid(Toolkit::Scrollable), typeid(Toolkit::Control), Create );
+TypeRegistration mType( typeid( Toolkit::Scrollable ), typeid( Toolkit::Control ), Create );
+
+SignalConnectorType s1( mType, SIGNAL_SCROLL_STARTED, &Scrollable::DoConnectSignal );
+SignalConnectorType s2( mType, SIGNAL_SCROLL_COMPLETED, &Scrollable::DoConnectSignal );
+SignalConnectorType s3( mType, SIGNAL_SCROLL_UPDATED, &Scrollable::DoConnectSignal );
-SignalConnectorType s1(mType, Toolkit::Scrollable::SIGNAL_SCROLL_STARTED, &Scrollable::DoConnectSignal);
-SignalConnectorType s2(mType, Toolkit::Scrollable::SIGNAL_SCROLL_COMPLETED, &Scrollable::DoConnectSignal);
-SignalConnectorType s3(mType, Toolkit::Scrollable::SIGNAL_SCROLL_UPDATED, &Scrollable::DoConnectSignal);
-SignalConnectorType s4(mType, Toolkit::Scrollable::SIGNAL_SCROLL_CLAMPED, &Scrollable::DoConnectSignal);
+PropertyRegistration property1( mType,
+ "overshoot-effect-color",
+ Toolkit::Scrollable::PROPERTY_OVERSHOOT_EFFECT_COLOR,
+ Property::VECTOR4,
+ &Scrollable::SetProperty,
+ &Scrollable::GetProperty );
+
+PropertyRegistration property2( mType,
+ "overshoot-animation-speed",
+ Toolkit::Scrollable::PROPERTY_OVERSHOOT_ANIMATION_SPEED,
+ Property::FLOAT,
+ &Scrollable::SetProperty,
+ &Scrollable::GetProperty );
}
// Scrollable
///////////////////////////////////////////////////////////////////////////////////////////////////
+// Scrollable controls are not layout containers so they dont need size negotiation..
+// we dont want size negotiation while scrolling if we can avoid it
Scrollable::Scrollable()
-: ControlImpl(true/*requires touch*/),
+: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS | NO_SIZE_NEGOTIATION ) ),
+ mOvershootEffectColor( DEFAULT_OVERSHOOT_COLOUR ),
+ mOvershootAnimationSpeed ( DEFAULT_OVERSHOOT_ANIMATION_SPEED ),
mPropertyRelativePosition(Property::INVALID_INDEX),
mPropertyPositionMin(Property::INVALID_INDEX),
mPropertyPositionMax(Property::INVALID_INDEX),
mPropertyScrollDirection(Property::INVALID_INDEX),
+ mPropertyCanScrollVertical(Property::INVALID_INDEX),
+ mPropertyCanScrollHorizontal(Property::INVALID_INDEX),
mOvershootEnabled(false)
{
}
{
if(type == Toolkit::Scrollable::OvershootIndicator)
{
- SetOvershootEnabled(true);
- mOvershootEnabled = true;
+ if( !mOvershootEnabled )
+ {
+ SetOvershootEnabled(true);
+ mOvershootEnabled = true;
+ }
return;
}
if( mComponents.find(type) == mComponents.end() )
{
// Create ScrollComponent
Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Self());
- Toolkit::ScrollComponent scrollComponent = ScrollComponent::New(scrollable, type);
- Toolkit::Internal::ScrollComponent& component = static_cast<Toolkit::Internal::ScrollComponent&>(scrollComponent.GetImplementation());
+ Toolkit::ScrollComponent scrollComponent = NewScrollComponent(scrollable, type);
+ Toolkit::ScrollComponentImpl& component = static_cast<Toolkit::ScrollComponentImpl&>(scrollComponent.GetImplementation());
ScrollComponentPtr componentPtr(&component);
mComponents[type] = componentPtr;
{
if(type == Toolkit::Scrollable::OvershootIndicator)
{
- SetOvershootEnabled(false);
- mOvershootEnabled = false;
+ if( mOvershootEnabled )
+ {
+ SetOvershootEnabled(false);
+ mOvershootEnabled = false;
+ }
return;
}
ComponentIter pair = mComponents.find( type );
}
}
-Toolkit::Scrollable::ScrollStartedSignalV2& Scrollable::ScrollStartedSignal()
+Vector4 Scrollable::GetOvershootEffectColor() const
+{
+ return mOvershootEffectColor;
+};
+
+void Scrollable::SetOvershootAnimationSpeed( float pixelsPerSecond )
{
- return mScrollStartedSignalV2;
+ mOvershootAnimationSpeed = pixelsPerSecond;
}
-Toolkit::Scrollable::ScrollUpdatedSignalV2& Scrollable::ScrollUpdatedSignal()
+float Scrollable::GetOvershootAnimationSpeed() const
+{
+ return mOvershootAnimationSpeed;
+};
+
+Toolkit::Scrollable::ScrollStartedSignalType& Scrollable::ScrollStartedSignal()
{
- return mScrollUpdatedSignalV2;
+ return mScrollStartedSignal;
}
-Toolkit::Scrollable::ScrollCompletedSignalV2& Scrollable::ScrollCompletedSignal()
+Toolkit::Scrollable::ScrollUpdatedSignalType& Scrollable::ScrollUpdatedSignal()
{
- return mScrollCompletedSignalV2;
+ return mScrollUpdatedSignal;
}
-Toolkit::Scrollable::ScrollClampedSignalV2& Scrollable::ScrollClampedSignal()
+Toolkit::Scrollable::ScrollCompletedSignalType& Scrollable::ScrollCompletedSignal()
{
- return mScrollClampedSignalV2;
+ return mScrollCompletedSignal;
}
bool Scrollable::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
bool connected( true );
Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( handle );
- if( Toolkit::Scrollable::SIGNAL_SCROLL_STARTED == signalName )
+ if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_STARTED ) )
{
scrollable.ScrollStartedSignal().Connect( tracker, functor );
}
- else if( Toolkit::Scrollable::SIGNAL_SCROLL_UPDATED == signalName )
+ else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_UPDATED ) )
{
scrollable.ScrollUpdatedSignal().Connect( tracker, functor );
}
- else if( Toolkit::Scrollable::SIGNAL_SCROLL_COMPLETED == signalName )
+ else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_COMPLETED ) )
{
scrollable.ScrollCompletedSignal().Connect( tracker, functor );
}
- else if( Toolkit::Scrollable::SIGNAL_SCROLL_CLAMPED == signalName )
- {
- scrollable.ScrollClampedSignal().Connect( tracker, functor );
- }
else
{
// signalName does not match any signal
return connected;
}
+void Scrollable::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+{
+ Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( Dali::BaseHandle( object ) );
+
+ if( scrollable )
+ {
+ Scrollable& scrollableImpl( GetImpl( scrollable ) );
+ switch( index )
+ {
+ case Toolkit::Scrollable::PROPERTY_OVERSHOOT_EFFECT_COLOR:
+ {
+ scrollableImpl.SetOvershootEffectColor( value.Get<Vector4>() );
+ break;
+ }
+ case Toolkit::Scrollable::PROPERTY_OVERSHOOT_ANIMATION_SPEED:
+ {
+ scrollableImpl.SetOvershootAnimationSpeed( value.Get<float>() );
+ break;
+ }
+ }
+ }
+}
+
+Property::Value Scrollable::GetProperty( BaseObject* object, Property::Index index )
+{
+ Property::Value value;
+
+ Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( Dali::BaseHandle( object ) );
+
+ if( scrollable )
+ {
+ Scrollable& scrollableImpl( GetImpl( scrollable ) );
+ switch( index )
+ {
+ case Toolkit::Scrollable::PROPERTY_OVERSHOOT_EFFECT_COLOR:
+ {
+ value = scrollableImpl.GetOvershootEffectColor();
+ break;
+ }
+ case Toolkit::Scrollable::PROPERTY_OVERSHOOT_ANIMATION_SPEED:
+ {
+ value = scrollableImpl.GetOvershootAnimationSpeed();
+ break;
+ }
+ }
+ }
+
+ return value;
+}
+
+Toolkit::ScrollComponent Scrollable::NewScrollComponent(Toolkit::Scrollable& scrollable, Toolkit::Scrollable::ScrollComponentType type)
+{
+ Toolkit::ScrollComponent instance;
+
+ switch(type)
+ {
+ case Toolkit::Scrollable::VerticalScrollBar:
+ {
+ instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, true));
+ break;
+ }
+ case Toolkit::Scrollable::HorizontalScrollBar:
+ {
+ instance = static_cast<Toolkit::ScrollComponent>(Toolkit::ScrollBarInternal::New(scrollable, false));
+ break;
+ }
+ case Toolkit::Scrollable::OvershootIndicator:
+ {
+ DALI_ASSERT_ALWAYS(!"Unrecognized component type");
+ break;
+ }
+ }
+
+ return instance;
+}
+
} // namespace Internal
} // namespace Toolkit