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-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
22 #include <dali/integration-api/debug.h>
25 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
26 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h>
36 ///////////////////////////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////////////////////////
40 RulerDomain::RulerDomain(float min, float max, bool enabled)
47 float RulerDomain::Clamp(float x, float length, float scale) const
51 return Clamp(x, length, scale, clamped);
54 float RulerDomain::Clamp(float x, float length, float scale, ClampState &clamped) const
62 const float minExtent = min * scale;
63 const float maxExtent = max * scale - length;
66 clamped = ClampedToMin;
69 else if(x > maxExtent)
71 clamped = ClampedToMax;
79 float RulerDomain::GetSize() const
84 ///////////////////////////////////////////////////////////////////////////////////////////////////
86 ///////////////////////////////////////////////////////////////////////////////////////////////////
91 mDomain(RulerDomain(0.0f,1.0f,false))
99 Ruler::RulerType Ruler::GetType() const
104 bool Ruler::IsEnabled() const
114 void Ruler::Disable()
119 void Ruler::SetDomain(RulerDomain domain)
124 const RulerDomain &Ruler::GetDomain() const
129 void Ruler::DisableDomain()
131 mDomain = RulerDomain(0.0f,1.0f,false);
134 float Ruler::Clamp(float x, float length, float scale) const
136 return mDomain.Clamp(x, length, scale);
139 float Ruler::Clamp(float x, float length, float scale, ClampState &clamped) const
141 return mDomain.Clamp(x, length, scale, clamped);
144 float Ruler::SnapAndClamp(float x, float bias, float length, float scale) const
146 return Clamp(Snap(x, bias), length, scale);
149 float Ruler::SnapAndClamp(float x, float bias, float length, float scale, ClampState &clamped) const
151 return Clamp(Snap(x, bias), length, scale, clamped);
154 ///////////////////////////////////////////////////////////////////////////////////////////////////
156 ///////////////////////////////////////////////////////////////////////////////////////////////////
158 DefaultRuler::DefaultRuler()
163 float DefaultRuler::Snap(float x, float bias) const
168 float DefaultRuler::GetPositionFromPage(unsigned int page, unsigned int &volume, bool wrap) const
174 unsigned int DefaultRuler::GetPageFromPosition(float position, bool wrap) const
179 unsigned int DefaultRuler::GetTotalPages() const
184 ///////////////////////////////////////////////////////////////////////////////////////////////////
186 ///////////////////////////////////////////////////////////////////////////////////////////////////
188 FixedRuler::FixedRuler(float spacing)
194 float FixedRuler::Snap(float x, float bias) const
196 return floor(x / mSpacing + bias) * mSpacing;
199 float FixedRuler::GetPositionFromPage(unsigned int page, unsigned int &volume, bool wrap) const
201 float position = mDomain.min;
205 // spacing must be present.
206 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
208 unsigned int column = page;
210 // In carry mode, a volume (carry) is produced when page exceeds limit within domain
213 unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
216 column += pagesPerVolume;
217 column %= pagesPerVolume;
218 volume = page/pagesPerVolume;
222 position = mDomain.min + column * mSpacing;
224 else // Domain (or Spacing) is not present, carry page to volume.
235 unsigned int FixedRuler::GetPageFromPosition(float position, bool wrap) const
237 unsigned int page = 0;
239 // spacing must be present.
240 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
244 position = WrapInDomain(position, mDomain.min, mDomain.max);
246 page = floor((position - mDomain.min) / mSpacing + 0.5f);
250 unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
251 page %= pagesPerVolume;
258 unsigned int FixedRuler::GetTotalPages() const
260 unsigned int pagesPerVolume = 1;
262 // spacing must be present.
263 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
265 pagesPerVolume = mDomain.GetSize() / mSpacing;
268 return pagesPerVolume;
271 ///////////////////////////////////////////////////////////////////////////////////////////////////
273 ///////////////////////////////////////////////////////////////////////////////////////////////////
275 const std::string ScrollView::SCROLL_PAGE_CURRENT( "scroll-page-current" );
276 const std::string ScrollView::SCROLL_TIME_PROPERTY_NAME( "scroll-time" );
277 const std::string ScrollView::SCROLL_POSITION_PROPERTY_NAME( "scroll-position" );
278 const std::string ScrollView::SCROLL_PRE_POSITION_PROPERTY_NAME( "scroll-pre-position" );
279 const std::string ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME( "scroll-overshoot-x" );
280 const std::string ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME( "scroll-overshoot-y" );
281 const std::string ScrollView::SCROLL_FINAL_PROPERTY_NAME( "scroll-final" );
282 const std::string ScrollView::SCROLL_X_PROPERTY_NAME( "scroll-x" );
283 const std::string ScrollView::SCROLL_Y_PROPERTY_NAME( "scroll-y" );
284 const std::string ScrollView::SCROLL_SCALE_PROPERTY_NAME( "scroll-scale" );
285 const std::string ScrollView::SCROLL_WRAP_PROPERTY_NAME( "scroll-wrap" );
286 const std::string ScrollView::SCROLL_PANNING_PROPERTY_NAME( "scroll-panning" );
287 const std::string ScrollView::SCROLL_SCROLLING_PROPERTY_NAME( "scroll-scrolling" );
288 const std::string ScrollView::SCROLL_POSITION_DELTA_PROPERTY_NAME( "scroll-position-delta" );
289 const std::string ScrollView::SCROLL_START_PAGE_POSITION_PROPERTY_NAME( "scroll-start-page-position" );
291 const float ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION(0.5f);
292 const float ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION(0.25f);
293 const float ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION(0.5f);
294 const float ScrollView::DEFAULT_MAX_OVERSHOOT(100.0f); // 100 pixels
296 const float ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT(0.36f);
297 const float ScrollView::DEFAULT_FRICTION_COEFFICIENT(1.0f);
298 const float ScrollView::DEFAULT_FLICK_SPEED_COEFFICIENT(1.0f);
299 const float ScrollView::DEFAULT_MAX_FLICK_SPEED(3.0f);
301 const char* const ScrollView::SIGNAL_SNAP_STARTED = "snap-started";
303 ScrollView::ScrollView()
307 ScrollView::ScrollView(Internal::ScrollView& implementation)
308 : Scrollable(implementation)
312 ScrollView::ScrollView( Dali::Internal::CustomActor* internal )
313 : Scrollable( internal )
315 VerifyCustomActorPointer<Internal::ScrollView>(internal);
318 ScrollView::ScrollView( const ScrollView& handle )
319 : Scrollable( handle )
323 ScrollView& ScrollView::operator=( const ScrollView& handle )
325 if( &handle != this )
327 Control::operator=( handle );
332 ScrollView ScrollView::New()
334 return Internal::ScrollView::New();
337 ScrollView::~ScrollView()
341 ScrollView ScrollView::DownCast( BaseHandle handle )
343 return Control::DownCast<ScrollView, Internal::ScrollView>(handle);
346 AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
348 return GetImpl(*this).GetScrollSnapAlphaFunction();
351 void ScrollView::SetScrollSnapAlphaFunction(AlphaFunction alpha)
353 GetImpl(*this).SetScrollSnapAlphaFunction(alpha);
356 AlphaFunction ScrollView::GetScrollFlickAlphaFunction() const
358 return GetImpl(*this).GetScrollFlickAlphaFunction();
361 void ScrollView::SetScrollFlickAlphaFunction(AlphaFunction alpha)
363 GetImpl(*this).SetScrollFlickAlphaFunction(alpha);
366 float ScrollView::GetScrollSnapDuration() const
368 return GetImpl(*this).GetScrollSnapDuration();
371 void ScrollView::SetScrollSnapDuration(float time)
373 GetImpl(*this).SetScrollSnapDuration(time);
376 float ScrollView::GetScrollFlickDuration() const
378 return GetImpl(*this).GetScrollFlickDuration();
381 void ScrollView::SetScrollFlickDuration(float time)
383 GetImpl(*this).SetScrollFlickDuration(time);
386 void ScrollView::SetRulerX(RulerPtr ruler)
388 GetImpl(*this).SetRulerX(ruler);
391 void ScrollView::SetRulerY(RulerPtr ruler)
393 GetImpl(*this).SetRulerY(ruler);
396 void ScrollView::SetRulerScaleX(RulerPtr ruler)
398 DALI_LOG_ERROR( "Deprecated" );
401 void ScrollView::SetRulerScaleY(RulerPtr ruler)
403 DALI_LOG_ERROR( "Deprecated" );
406 void ScrollView::SetScrollSensitive(bool sensitive)
408 GetImpl(*this).SetScrollSensitive(sensitive);
411 void ScrollView::SetMaxOvershoot(float overshootX, float overshootY)
413 GetImpl(*this).SetMaxOvershoot(overshootX, overshootY);
416 void ScrollView::SetSnapOvershootAlphaFunction(AlphaFunction alpha)
418 GetImpl(*this).SetSnapOvershootAlphaFunction(alpha);
421 void ScrollView::SetSnapOvershootDuration(float duration)
423 GetImpl(*this).SetSnapOvershootDuration(duration);
426 void ScrollView::SetTouchesRequiredForPanning(unsigned int minTouches, unsigned int maxTouches, bool endOutside)
428 GetImpl(*this).SetTouchesRequiredForPanning(minTouches, maxTouches, endOutside);
431 void ScrollView::SetActorAutoSnap(bool enable)
433 GetImpl(*this).SetActorAutoSnap(enable);
436 void ScrollView::SetWrapMode(bool enable)
438 GetImpl(*this).SetWrapMode(enable);
441 int ScrollView::GetRefreshInterval() const
443 return GetImpl(*this).GetRefreshInterval();
446 void ScrollView::SetRefreshInterval(int milliseconds)
448 GetImpl(*this).SetRefreshInterval(milliseconds);
451 int ScrollView::GetScrollUpdateDistance() const
453 return GetImpl(*this).GetScrollUpdateDistance();
456 void ScrollView::SetScrollUpdateDistance(int distance)
458 GetImpl(*this).SetScrollUpdateDistance(distance);
461 bool ScrollView::GetAxisAutoLock() const
463 return GetImpl(*this).GetAxisAutoLock();
466 void ScrollView::SetAxisAutoLock(bool enable)
468 GetImpl(*this).SetAxisAutoLock(enable);
471 float ScrollView::GetAxisAutoLockGradient() const
473 return GetImpl(*this).GetAxisAutoLockGradient();
476 void ScrollView::SetAxisAutoLockGradient(float gradient)
478 GetImpl(*this).SetAxisAutoLockGradient(gradient);
481 float ScrollView::GetFrictionCoefficient() const
483 return GetImpl(*this).GetFrictionCoefficient();
486 void ScrollView::SetFrictionCoefficient(float friction)
488 GetImpl(*this).SetFrictionCoefficient(friction);
491 float ScrollView::GetFlickSpeedCoefficient() const
493 return GetImpl(*this).GetFlickSpeedCoefficient();
496 void ScrollView::SetFlickSpeedCoefficient(float speed)
498 GetImpl(*this).SetFlickSpeedCoefficient(speed);
501 Vector2 ScrollView::GetMinimumDistanceForFlick() const
503 return GetImpl(*this).GetMinimumDistanceForFlick();
506 void ScrollView::SetMinimumDistanceForFlick( const Vector2& distance )
508 GetImpl(*this).SetMinimumDistanceForFlick(distance);
511 float ScrollView::GetMinimumSpeedForFlick() const
513 return GetImpl(*this).GetMinimumSpeedForFlick();
516 void ScrollView::SetMinimumSpeedForFlick( float speed )
518 GetImpl(*this).SetMinimumSpeedForFlick(speed);
521 float ScrollView::GetMaxFlickSpeed() const
523 return GetImpl(*this).GetMaxFlickSpeed();
526 void ScrollView::SetMaxFlickSpeed(float speed)
528 GetImpl(*this).SetMaxFlickSpeed(speed);
531 Vector2 ScrollView::GetMouseWheelScrollDistanceStep() const
533 return GetImpl(*this).GetMouseWheelScrollDistanceStep();
536 void ScrollView::SetMouseWheelScrollDistanceStep(Vector2 step)
538 GetImpl(*this).SetMouseWheelScrollDistanceStep(step);
541 Vector3 ScrollView::GetCurrentScrollPosition() const
543 return GetImpl(*this).GetCurrentScrollPosition();
546 void ScrollView::SetScrollPosition(const Vector3& position)
548 GetImpl(*this).SetScrollPosition(position);
551 Vector3 ScrollView::GetCurrentScrollScale() const
553 DALI_LOG_ERROR( "Deprecated" );
557 unsigned int ScrollView::GetCurrentPage() const
559 return GetImpl(*this).GetCurrentPage();
562 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation)
564 DALI_LOG_ERROR( "Deprecated" );
566 GetImpl(*this).TransformTo(position);
569 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration)
571 DALI_LOG_ERROR( "Deprecated" );
573 GetImpl(*this).TransformTo(position, duration);
576 void ScrollView::ScrollTo(const Vector3 &position)
578 GetImpl(*this).ScrollTo(position);
581 void ScrollView::ScrollTo(const Vector3 &position, float duration)
583 GetImpl(*this).ScrollTo(position, duration);
586 void ScrollView::ScrollTo(const Vector3 &position, float duration,
587 DirectionBias horizontalBias, DirectionBias verticalBias)
589 GetImpl(*this).ScrollTo(position, duration, horizontalBias, verticalBias);
592 void ScrollView::ScrollTo(unsigned int page)
594 GetImpl(*this).ScrollTo(page);
597 void ScrollView::ScrollTo(unsigned int page, float duration)
599 GetImpl(*this).ScrollTo(page, duration);
602 void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
604 GetImpl(*this).ScrollTo(page, duration, bias);
607 void ScrollView::ScrollTo(Actor &actor)
609 GetImpl(*this).ScrollTo(actor);
612 void ScrollView::ScrollTo(Actor &actor, float duration)
614 GetImpl(*this).ScrollTo(actor, duration);
617 bool ScrollView::ScrollToSnapPoint()
619 return GetImpl(*this).ScrollToSnapPoint();
622 void ScrollView::ScaleTo(const Vector3 &scale)
624 DALI_LOG_ERROR( "Deprecated" );
627 void ScrollView::ScaleTo(const Vector3 &scale, float duration)
629 DALI_LOG_ERROR( "Deprecated" );
632 void ScrollView::ApplyConstraintToChildren(Constraint constraint)
634 GetImpl(*this).ApplyConstraintToChildren(constraint);
637 void ScrollView::RemoveConstraintsFromChildren()
639 GetImpl(*this).RemoveConstraintsFromChildren();
642 void ScrollView::ApplyEffect(ScrollViewEffect effect)
644 GetImpl(*this).ApplyEffect(effect);
647 ScrollViewEffect ScrollView::ApplyEffect(ScrollView::PageEffect effect)
649 return GetImpl(*this).ApplyEffect(effect);
652 void ScrollView::RemoveEffect(ScrollViewEffect effect)
654 GetImpl(*this).RemoveEffect(effect);
657 void ScrollView::RemoveAllEffects()
659 GetImpl(*this).RemoveAllEffects();
662 void ScrollView::BindActor(Actor child)
664 GetImpl(*this).BindActor(child);
667 void ScrollView::UnbindActor(Actor child)
669 GetImpl(*this).UnbindActor(child);
672 ScrollView::SnapStartedSignalV2& ScrollView::SnapStartedSignal()
674 return GetImpl(*this).SnapStartedSignal();
677 void ScrollView::SetScrollingDirection( Radian direction, Radian threshold )
679 GetImpl(*this).SetScrollingDirection( direction, threshold );
682 void ScrollView::RemoveScrollingDirection( Radian direction )
684 GetImpl(*this).RemoveScrollingDirection( direction );
687 } // namespace Toolkit