2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
17 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
18 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
19 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h>
29 ///////////////////////////////////////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////////////////////////////////////
33 RulerDomain::RulerDomain(float min, float max, bool enabled)
40 float RulerDomain::Clamp(float x, float length, float scale) const
44 return Clamp(x, length, scale, clamped);
47 float RulerDomain::Clamp(float x, float length, float scale, ClampState &clamped) const
55 const float minExtent = min * scale;
56 const float maxExtent = max * scale - length;
59 clamped = ClampedToMin;
62 else if(x > maxExtent)
64 clamped = ClampedToMax;
72 float RulerDomain::GetSize() const
77 ///////////////////////////////////////////////////////////////////////////////////////////////////
79 ///////////////////////////////////////////////////////////////////////////////////////////////////
84 mDomain(RulerDomain(0.0f,1.0f,false))
92 Ruler::RulerType Ruler::GetType() const
97 bool Ruler::IsEnabled() const
107 void Ruler::Disable()
112 void Ruler::SetDomain(RulerDomain domain)
117 const RulerDomain &Ruler::GetDomain() const
122 void Ruler::DisableDomain()
124 mDomain = RulerDomain(0.0f,1.0f,false);
127 float Ruler::Clamp(float x, float length, float scale) const
129 return mDomain.Clamp(x, length, scale);
132 float Ruler::Clamp(float x, float length, float scale, ClampState &clamped) const
134 return mDomain.Clamp(x, length, scale, clamped);
137 float Ruler::SnapAndClamp(float x, float bias, float length, float scale) const
139 return Clamp(Snap(x, bias), length, scale);
142 float Ruler::SnapAndClamp(float x, float bias, float length, float scale, ClampState &clamped) const
144 return Clamp(Snap(x, bias), length, scale, clamped);
147 ///////////////////////////////////////////////////////////////////////////////////////////////////
149 ///////////////////////////////////////////////////////////////////////////////////////////////////
151 DefaultRuler::DefaultRuler()
156 float DefaultRuler::Snap(float x, float bias) const
161 float DefaultRuler::GetPositionFromPage(unsigned int page, unsigned int &volume, bool wrap) const
167 unsigned int DefaultRuler::GetPageFromPosition(float position, bool wrap) const
172 unsigned int DefaultRuler::GetTotalPages() const
177 ///////////////////////////////////////////////////////////////////////////////////////////////////
179 ///////////////////////////////////////////////////////////////////////////////////////////////////
181 FixedRuler::FixedRuler(float spacing)
187 float FixedRuler::Snap(float x, float bias) const
189 return floor(x / mSpacing + bias) * mSpacing;
192 float FixedRuler::GetPositionFromPage(unsigned int page, unsigned int &volume, bool wrap) const
194 float position = mDomain.min;
198 // spacing must be present.
199 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
201 unsigned int column = page;
203 // In carry mode, a volume (carry) is produced when page exceeds limit within domain
206 unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
209 column += pagesPerVolume;
210 column %= pagesPerVolume;
211 volume = page/pagesPerVolume;
215 position = mDomain.min + column * mSpacing;
217 else // Domain (or Spacing) is not present, carry page to volume.
228 unsigned int FixedRuler::GetPageFromPosition(float position, bool wrap) const
230 unsigned int page = 0;
232 // spacing must be present.
233 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
235 page = floor((position - mDomain.min) / mSpacing + 0.5f);
239 unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
240 page %= pagesPerVolume;
247 unsigned int FixedRuler::GetTotalPages() const
249 unsigned int pagesPerVolume = 1;
251 // spacing must be present.
252 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
254 pagesPerVolume = mDomain.GetSize() / mSpacing;
257 return pagesPerVolume;
260 ///////////////////////////////////////////////////////////////////////////////////////////////////
262 ///////////////////////////////////////////////////////////////////////////////////////////////////
264 const std::string ScrollView::SCROLL_PAGE_CURRENT( "scroll-page-current" );
265 const std::string ScrollView::SCROLL_TIME_PROPERTY_NAME( "scroll-time" );
266 const std::string ScrollView::SCROLL_POSITION_PROPERTY_NAME( "scroll-position" );
267 const std::string ScrollView::SCROLL_PRE_POSITION_PROPERTY_NAME( "scroll-pre-position" );
268 const std::string ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME( "scroll-overshoot-x" );
269 const std::string ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME( "scroll-overshoot-y" );
270 const std::string ScrollView::SCROLL_FINAL_PROPERTY_NAME( "scroll-final" );
271 const std::string ScrollView::SCROLL_X_PROPERTY_NAME( "scroll-x" );
272 const std::string ScrollView::SCROLL_Y_PROPERTY_NAME( "scroll-y" );
273 const std::string ScrollView::SCROLL_SCALE_PROPERTY_NAME( "scroll-scale" );
274 const std::string ScrollView::SCROLL_WRAP_PROPERTY_NAME( "scroll-wrap" );
275 const std::string ScrollView::SCROLL_PANNING_PROPERTY_NAME( "scroll-panning" );
276 const std::string ScrollView::SCROLL_SCROLLING_PROPERTY_NAME( "scroll-scrolling" );
277 const std::string ScrollView::SCROLL_POSITION_DELTA_PROPERTY_NAME( "scroll-position-delta" );
278 const std::string ScrollView::SCROLL_START_PAGE_POSITION_PROPERTY_NAME( "scroll-start-page-position" );
280 const float ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION(0.5f);
281 const float ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION(0.25f);
282 const float ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION(1.0f);
283 const float ScrollView::DEFAULT_MAX_OVERSHOOT(100.0f); // 100 pixels
285 const float ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT(0.36f);
286 const float ScrollView::DEFAULT_FRICTION_COEFFICIENT(1.0f);
287 const float ScrollView::DEFAULT_FLICK_SPEED_COEFFICIENT(1.0f);
288 const float ScrollView::DEFAULT_MAX_FLICK_SPEED(3.0f);
290 const char* const ScrollView::SIGNAL_SNAP_STARTED = "snap-started";
292 ScrollView::ScrollView()
296 ScrollView::ScrollView(Internal::ScrollView& implementation)
297 : Scrollable(implementation)
301 ScrollView::ScrollView( Dali::Internal::CustomActor* internal )
302 : Scrollable( internal )
304 VerifyCustomActorPointer<Internal::ScrollView>(internal);
307 ScrollView::ScrollView( const ScrollView& handle )
308 : Scrollable( handle )
312 ScrollView& ScrollView::operator=( const ScrollView& handle )
314 if( &handle != this )
316 Control::operator=( handle );
321 ScrollView ScrollView::New()
323 return Internal::ScrollView::New();
326 ScrollView::~ScrollView()
330 ScrollView ScrollView::DownCast( BaseHandle handle )
332 return Control::DownCast<ScrollView, Internal::ScrollView>(handle);
335 AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
337 return GetImpl(*this).GetScrollSnapAlphaFunction();
340 void ScrollView::SetScrollSnapAlphaFunction(AlphaFunction alpha)
342 GetImpl(*this).SetScrollSnapAlphaFunction(alpha);
345 AlphaFunction ScrollView::GetScrollFlickAlphaFunction() const
347 return GetImpl(*this).GetScrollFlickAlphaFunction();
350 void ScrollView::SetScrollFlickAlphaFunction(AlphaFunction alpha)
352 GetImpl(*this).SetScrollFlickAlphaFunction(alpha);
355 float ScrollView::GetScrollSnapDuration() const
357 return GetImpl(*this).GetScrollSnapDuration();
360 void ScrollView::SetScrollSnapDuration(float time)
362 GetImpl(*this).SetScrollSnapDuration(time);
365 float ScrollView::GetScrollFlickDuration() const
367 return GetImpl(*this).GetScrollFlickDuration();
370 void ScrollView::SetScrollFlickDuration(float time)
372 GetImpl(*this).SetScrollFlickDuration(time);
375 void ScrollView::SetRulerX(RulerPtr ruler)
377 GetImpl(*this).SetRulerX(ruler);
380 void ScrollView::SetRulerY(RulerPtr ruler)
382 GetImpl(*this).SetRulerY(ruler);
385 void ScrollView::SetRulerScaleX(RulerPtr ruler)
387 GetImpl(*this).SetRulerScaleX(ruler);
390 void ScrollView::SetRulerScaleY(RulerPtr ruler)
392 GetImpl(*this).SetRulerScaleY(ruler);
395 void ScrollView::SetScrollSensitive(bool sensitive)
397 GetImpl(*this).SetScrollSensitive(sensitive);
400 void ScrollView::SetMaxOvershoot(float overshootX, float overshootY)
402 GetImpl(*this).SetMaxOvershoot(overshootX, overshootY);
405 void ScrollView::SetSnapOvershootAlphaFunction(AlphaFunction alpha)
407 GetImpl(*this).SetSnapOvershootAlphaFunction(alpha);
410 void ScrollView::SetSnapOvershootDuration(float duration)
412 GetImpl(*this).SetSnapOvershootDuration(duration);
415 void ScrollView::SetTouchesRequiredForPanning(unsigned int minTouches, unsigned int maxTouches, bool endOutside)
417 GetImpl(*this).SetTouchesRequiredForPanning(minTouches, maxTouches, endOutside);
420 void ScrollView::SetActorAutoSnap(bool enable)
422 GetImpl(*this).SetActorAutoSnap(enable);
425 void ScrollView::SetWrapMode(bool enable)
427 GetImpl(*this).SetWrapMode(enable);
430 int ScrollView::GetRefreshInterval() const
432 return GetImpl(*this).GetRefreshInterval();
435 void ScrollView::SetRefreshInterval(int milliseconds)
437 GetImpl(*this).SetRefreshInterval(milliseconds);
440 bool ScrollView::GetAxisAutoLock() const
442 return GetImpl(*this).GetAxisAutoLock();
445 void ScrollView::SetAxisAutoLock(bool enable)
447 GetImpl(*this).SetAxisAutoLock(enable);
450 float ScrollView::GetAxisAutoLockGradient() const
452 return GetImpl(*this).GetAxisAutoLockGradient();
455 void ScrollView::SetAxisAutoLockGradient(float gradient)
457 GetImpl(*this).SetAxisAutoLockGradient(gradient);
460 float ScrollView::GetFrictionCoefficient() const
462 return GetImpl(*this).GetFrictionCoefficient();
465 void ScrollView::SetFrictionCoefficient(float friction)
467 GetImpl(*this).SetFrictionCoefficient(friction);
470 float ScrollView::GetFlickSpeedCoefficient() const
472 return GetImpl(*this).GetFlickSpeedCoefficient();
475 void ScrollView::SetFlickSpeedCoefficient(float speed)
477 GetImpl(*this).SetFlickSpeedCoefficient(speed);
480 float ScrollView::GetMaxFlickSpeed() const
482 return GetImpl(*this).GetMaxFlickSpeed();
485 void ScrollView::SetMaxFlickSpeed(float speed)
487 GetImpl(*this).SetMaxFlickSpeed(speed);
490 Vector2 ScrollView::GetMouseWheelScrollDistanceStep() const
492 return GetImpl(*this).GetMouseWheelScrollDistanceStep();
495 void ScrollView::SetMouseWheelScrollDistanceStep(Vector2 step)
497 GetImpl(*this).SetMouseWheelScrollDistanceStep(step);
500 Vector3 ScrollView::GetCurrentScrollPosition() const
502 return GetImpl(*this).GetCurrentScrollPosition();
505 Vector3 ScrollView::GetCurrentScrollScale() const
507 return GetImpl(*this).GetCurrentScrollScale();
510 unsigned int ScrollView::GetCurrentPage() const
512 return GetImpl(*this).GetCurrentPage();
515 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation)
517 GetImpl(*this).TransformTo(position, scale, rotation);
520 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration)
522 GetImpl(*this).TransformTo(position, scale, rotation, duration);
525 void ScrollView::ScrollTo(const Vector3 &position)
527 GetImpl(*this).ScrollTo(position);
530 void ScrollView::ScrollTo(const Vector3 &position, float duration)
532 GetImpl(*this).ScrollTo(position, duration);
535 void ScrollView::ScrollTo(const Vector3 &position, float duration,
536 DirectionBias horizontalBias, DirectionBias verticalBias)
538 GetImpl(*this).ScrollTo(position, duration, horizontalBias, verticalBias);
541 void ScrollView::ScrollTo(unsigned int page)
543 GetImpl(*this).ScrollTo(page);
546 void ScrollView::ScrollTo(unsigned int page, float duration)
548 GetImpl(*this).ScrollTo(page, duration);
551 void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
553 GetImpl(*this).ScrollTo(page, duration, bias);
556 void ScrollView::ScrollTo(Actor &actor)
558 GetImpl(*this).ScrollTo(actor);
561 void ScrollView::ScrollTo(Actor &actor, float duration)
563 GetImpl(*this).ScrollTo(actor, duration);
566 bool ScrollView::ScrollToSnapPoint()
568 return GetImpl(*this).ScrollToSnapPoint();
571 void ScrollView::ScaleTo(const Vector3 &scale)
573 GetImpl(*this).ScaleTo(scale);
576 void ScrollView::ScaleTo(const Vector3 &scale, float duration)
578 GetImpl(*this).ScaleTo(scale, duration);
581 void ScrollView::ApplyConstraintToChildren(Constraint constraint)
583 GetImpl(*this).ApplyConstraintToChildren(constraint);
586 void ScrollView::RemoveConstraintsFromChildren()
588 GetImpl(*this).RemoveConstraintsFromChildren();
591 void ScrollView::ApplyEffect(ScrollViewEffect effect)
593 GetImpl(*this).ApplyEffect(effect);
596 ScrollViewEffect ScrollView::ApplyEffect(ScrollView::PageEffect effect)
598 return GetImpl(*this).ApplyEffect(effect);
601 void ScrollView::RemoveEffect(ScrollViewEffect effect)
603 GetImpl(*this).RemoveEffect(effect);
606 void ScrollView::RemoveAllEffects()
608 GetImpl(*this).RemoveAllEffects();
611 void ScrollView::BindActor(Actor child)
613 GetImpl(*this).BindActor(child);
616 void ScrollView::UnbindActor(Actor child)
618 GetImpl(*this).UnbindActor(child);
621 ScrollView::SnapStartedSignalV2& ScrollView::SnapStartedSignal()
623 return GetImpl(*this).SnapStartedSignal();
626 void ScrollView::SetScrollingDirection( Radian direction, Radian threshold )
628 GetImpl(*this).SetScrollingDirection( direction, threshold );
631 void ScrollView::RemoveScrollingDirection( Radian direction )
633 GetImpl(*this).RemoveScrollingDirection( direction );
636 } // namespace Toolkit