2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/public-api/object/type-registry-helper.h>
20 #include <dali/public-api/object/type-registry.h>
21 #include <cstring> // for strcmp
24 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
25 #include <dali-toolkit/internal/controls/scrollable/scrollable-impl.h>
39 // empty handle as we cannot create Scrollable (but type registered for scroll signal)
43 // Setup properties, signals and actions using the type-registry.
44 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::Scrollable, Toolkit::Control, Create);
46 DALI_PROPERTY_REGISTRATION(Toolkit, Scrollable, "overshootEffectColor", VECTOR4, OVERSHOOT_EFFECT_COLOR)
47 DALI_PROPERTY_REGISTRATION(Toolkit, Scrollable, "overshootAnimationSpeed", FLOAT, OVERSHOOT_ANIMATION_SPEED)
48 DALI_PROPERTY_REGISTRATION(Toolkit, Scrollable, "overshootEnabled", BOOLEAN, OVERSHOOT_ENABLED)
49 DALI_PROPERTY_REGISTRATION(Toolkit, Scrollable, "overshootSize", VECTOR2, OVERSHOOT_SIZE)
50 DALI_PROPERTY_REGISTRATION(Toolkit, Scrollable, "scrollToAlphaFunction", INTEGER, SCROLL_TO_ALPHA_FUNCTION)
52 DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Scrollable, "scrollRelativePosition", VECTOR2, SCROLL_RELATIVE_POSITION)
53 DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Scrollable, "scrollPositionMin", VECTOR2, SCROLL_POSITION_MIN)
54 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, Scrollable, "scrollPositionMinX", SCROLL_POSITION_MIN_X, SCROLL_POSITION_MIN, 0)
55 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, Scrollable, "scrollPositionMinY", SCROLL_POSITION_MIN_Y, SCROLL_POSITION_MIN, 1)
56 DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Scrollable, "scrollPositionMax", VECTOR2, SCROLL_POSITION_MAX)
57 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, Scrollable, "scrollPositionMaxX", SCROLL_POSITION_MAX_X, SCROLL_POSITION_MAX, 0)
58 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, Scrollable, "scrollPositionMaxY", SCROLL_POSITION_MAX_Y, SCROLL_POSITION_MAX, 1)
59 DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Scrollable, "canScrollVertical", BOOLEAN, CAN_SCROLL_VERTICAL)
60 DALI_ANIMATABLE_PROPERTY_REGISTRATION(Toolkit, Scrollable, "canScrollHorizontal", BOOLEAN, CAN_SCROLL_HORIZONTAL)
62 DALI_SIGNAL_REGISTRATION(Toolkit, Scrollable, "scrollStarted", SIGNAL_SCROLL_STARTED)
63 DALI_SIGNAL_REGISTRATION(Toolkit, Scrollable, "scrollCompleted", SIGNAL_SCROLL_COMPLETED)
64 DALI_SIGNAL_REGISTRATION(Toolkit, Scrollable, "scrollUpdated", SIGNAL_SCROLL_UPDATED)
66 DALI_TYPE_REGISTRATION_END()
68 const Vector4 DEFAULT_OVERSHOOT_COLOUR(0.0f, 0.64f, 0.85f, 0.25f);
69 const float DEFAULT_OVERSHOOT_ANIMATION_SPEED(120.0f); // 120 pixels per second
70 const Vector2 OVERSHOOT_DEFAULT_SIZE(720.0f, 42.0f);
74 ///////////////////////////////////////////////////////////////////////////////////////////////////
76 ///////////////////////////////////////////////////////////////////////////////////////////////////
78 Scrollable::Scrollable(ControlBehaviour behaviourFlags)
79 : Control(ControlBehaviour(behaviourFlags)),
80 mOvershootEffectColor(DEFAULT_OVERSHOOT_COLOUR),
81 mOvershootAnimationSpeed(DEFAULT_OVERSHOOT_ANIMATION_SPEED),
82 mOvershootSize(OVERSHOOT_DEFAULT_SIZE),
83 mScrollToAlphaFunction(AlphaFunction::EASE_OUT),
84 mScrollStartedSignal(),
85 mScrollUpdatedSignal(),
86 mScrollCompletedSignal(),
87 mOvershootEnabled(true)
91 Scrollable::~Scrollable()
95 bool Scrollable::ScrollableAccessible::IsScrollable() const
100 void Scrollable::OnInitialize()
102 DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
103 return std::make_unique<ScrollableAccessible>(actor, Dali::Accessibility::Role::SCROLL_PANE);
107 bool Scrollable::IsOvershootEnabled() const
109 return mOvershootEnabled;
112 void Scrollable::SetOvershootEnabled(bool enable)
114 EnableScrollOvershoot(enable);
115 mOvershootEnabled = enable;
118 Vector4 Scrollable::GetOvershootEffectColor() const
120 return mOvershootEffectColor;
123 void Scrollable::SetOvershootAnimationSpeed(float pixelsPerSecond)
125 mOvershootAnimationSpeed = pixelsPerSecond;
128 float Scrollable::GetOvershootAnimationSpeed() const
130 return mOvershootAnimationSpeed;
133 const Vector2& Scrollable::GetOvershootSize() const
135 return mOvershootSize;
138 Toolkit::Scrollable::ScrollStartedSignalType& Scrollable::ScrollStartedSignal()
140 return mScrollStartedSignal;
143 Toolkit::Scrollable::ScrollUpdatedSignalType& Scrollable::ScrollUpdatedSignal()
145 return mScrollUpdatedSignal;
148 Toolkit::Scrollable::ScrollCompletedSignalType& Scrollable::ScrollCompletedSignal()
150 return mScrollCompletedSignal;
153 bool Scrollable::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
155 Dali::BaseHandle handle(object);
157 bool connected(true);
158 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(handle);
160 if(0 == strcmp(signalName.c_str(), SIGNAL_SCROLL_STARTED))
162 scrollable.ScrollStartedSignal().Connect(tracker, functor);
164 else if(0 == strcmp(signalName.c_str(), SIGNAL_SCROLL_UPDATED))
166 scrollable.ScrollUpdatedSignal().Connect(tracker, functor);
168 else if(0 == strcmp(signalName.c_str(), SIGNAL_SCROLL_COMPLETED))
170 scrollable.ScrollCompletedSignal().Connect(tracker, functor);
174 // signalName does not match any signal
181 void Scrollable::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
183 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Dali::BaseHandle(object));
187 Scrollable& scrollableImpl(GetImpl(scrollable));
190 case Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR:
192 scrollableImpl.SetOvershootEffectColor(value.Get<Vector4>());
195 case Toolkit::Scrollable::Property::OVERSHOOT_ANIMATION_SPEED:
197 scrollableImpl.SetOvershootAnimationSpeed(value.Get<float>());
200 case Toolkit::Scrollable::Property::OVERSHOOT_ENABLED:
202 scrollableImpl.SetOvershootEnabled(value.Get<bool>());
205 case Toolkit::Scrollable::Property::OVERSHOOT_SIZE:
207 scrollableImpl.SetOvershootSize(value.Get<Vector2>());
210 case Toolkit::Scrollable::Property::SCROLL_TO_ALPHA_FUNCTION:
212 int alphaFunction = value.Get<int>();
214 if(alphaFunction >= AlphaFunction::DEFAULT &&
215 alphaFunction < AlphaFunction::COUNT)
217 scrollableImpl.mScrollToAlphaFunction = static_cast<AlphaFunction::BuiltinFunction>(alphaFunction);
225 Property::Value Scrollable::GetProperty(BaseObject* object, Property::Index index)
227 Property::Value value;
229 Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast(Dali::BaseHandle(object));
233 Scrollable& scrollableImpl(GetImpl(scrollable));
236 case Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR:
238 value = scrollableImpl.GetOvershootEffectColor();
241 case Toolkit::Scrollable::Property::OVERSHOOT_ANIMATION_SPEED:
243 value = scrollableImpl.GetOvershootAnimationSpeed();
246 case Toolkit::Scrollable::Property::OVERSHOOT_ENABLED:
248 value = scrollableImpl.IsOvershootEnabled();
251 case Toolkit::Scrollable::Property::OVERSHOOT_SIZE:
253 value = scrollableImpl.mOvershootSize;
256 case Toolkit::Scrollable::Property::SCROLL_TO_ALPHA_FUNCTION:
258 value = static_cast<int>(scrollableImpl.mScrollToAlphaFunction);
267 } // namespace Internal
269 } // namespace Toolkit