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_SCALE_PROPERTY_NAME( "scroll-scale" );
283 const std::string ScrollView::SCROLL_WRAP_PROPERTY_NAME( "scroll-wrap" );
284 const std::string ScrollView::SCROLL_PANNING_PROPERTY_NAME( "scroll-panning" );
285 const std::string ScrollView::SCROLL_SCROLLING_PROPERTY_NAME( "scroll-scrolling" );
286 const std::string ScrollView::SCROLL_POSITION_DELTA_PROPERTY_NAME( "scroll-position-delta" );
287 const std::string ScrollView::SCROLL_START_PAGE_POSITION_PROPERTY_NAME( "scroll-start-page-position" );
289 const float ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION(0.5f);
290 const float ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION(0.25f);
291 const float ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION(0.5f);
292 const float ScrollView::DEFAULT_MAX_OVERSHOOT(100.0f); // 100 pixels
294 const float ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT(0.36f);
295 const float ScrollView::DEFAULT_FRICTION_COEFFICIENT(1.0f);
296 const float ScrollView::DEFAULT_FLICK_SPEED_COEFFICIENT(1.0f);
297 const float ScrollView::DEFAULT_MAX_FLICK_SPEED(3.0f);
299 const char* const ScrollView::SIGNAL_SNAP_STARTED = "snap-started";
301 ScrollView::ScrollView()
305 ScrollView::ScrollView(Internal::ScrollView& implementation)
306 : Scrollable(implementation)
310 ScrollView::ScrollView( Dali::Internal::CustomActor* internal )
311 : Scrollable( internal )
313 VerifyCustomActorPointer<Internal::ScrollView>(internal);
316 ScrollView::ScrollView( const ScrollView& handle )
317 : Scrollable( handle )
321 ScrollView& ScrollView::operator=( const ScrollView& handle )
323 if( &handle != this )
325 Control::operator=( handle );
330 ScrollView ScrollView::New()
332 return Internal::ScrollView::New();
335 ScrollView::~ScrollView()
339 ScrollView ScrollView::DownCast( BaseHandle handle )
341 return Control::DownCast<ScrollView, Internal::ScrollView>(handle);
344 AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
346 return GetImpl(*this).GetScrollSnapAlphaFunction();
349 void ScrollView::SetScrollSnapAlphaFunction(AlphaFunction alpha)
351 GetImpl(*this).SetScrollSnapAlphaFunction(alpha);
354 AlphaFunction ScrollView::GetScrollFlickAlphaFunction() const
356 return GetImpl(*this).GetScrollFlickAlphaFunction();
359 void ScrollView::SetScrollFlickAlphaFunction(AlphaFunction alpha)
361 GetImpl(*this).SetScrollFlickAlphaFunction(alpha);
364 float ScrollView::GetScrollSnapDuration() const
366 return GetImpl(*this).GetScrollSnapDuration();
369 void ScrollView::SetScrollSnapDuration(float time)
371 GetImpl(*this).SetScrollSnapDuration(time);
374 float ScrollView::GetScrollFlickDuration() const
376 return GetImpl(*this).GetScrollFlickDuration();
379 void ScrollView::SetScrollFlickDuration(float time)
381 GetImpl(*this).SetScrollFlickDuration(time);
384 void ScrollView::SetRulerX(RulerPtr ruler)
386 GetImpl(*this).SetRulerX(ruler);
389 void ScrollView::SetRulerY(RulerPtr ruler)
391 GetImpl(*this).SetRulerY(ruler);
394 void ScrollView::SetRulerScaleX(RulerPtr ruler)
396 DALI_LOG_ERROR( "Deprecated" );
399 void ScrollView::SetRulerScaleY(RulerPtr ruler)
401 DALI_LOG_ERROR( "Deprecated" );
404 void ScrollView::SetScrollSensitive(bool sensitive)
406 GetImpl(*this).SetScrollSensitive(sensitive);
409 void ScrollView::SetMaxOvershoot(float overshootX, float overshootY)
411 GetImpl(*this).SetMaxOvershoot(overshootX, overshootY);
414 void ScrollView::SetSnapOvershootAlphaFunction(AlphaFunction alpha)
416 GetImpl(*this).SetSnapOvershootAlphaFunction(alpha);
419 void ScrollView::SetSnapOvershootDuration(float duration)
421 GetImpl(*this).SetSnapOvershootDuration(duration);
424 void ScrollView::SetTouchesRequiredForPanning(unsigned int minTouches, unsigned int maxTouches, bool endOutside)
426 GetImpl(*this).SetTouchesRequiredForPanning(minTouches, maxTouches, endOutside);
429 void ScrollView::SetActorAutoSnap(bool enable)
431 GetImpl(*this).SetActorAutoSnap(enable);
434 void ScrollView::SetWrapMode(bool enable)
436 GetImpl(*this).SetWrapMode(enable);
439 int ScrollView::GetRefreshInterval() const
441 return GetImpl(*this).GetRefreshInterval();
444 void ScrollView::SetRefreshInterval(int milliseconds)
446 GetImpl(*this).SetRefreshInterval(milliseconds);
449 int ScrollView::GetScrollUpdateDistance() const
451 return GetImpl(*this).GetScrollUpdateDistance();
454 void ScrollView::SetScrollUpdateDistance(int distance)
456 GetImpl(*this).SetScrollUpdateDistance(distance);
459 bool ScrollView::GetAxisAutoLock() const
461 return GetImpl(*this).GetAxisAutoLock();
464 void ScrollView::SetAxisAutoLock(bool enable)
466 GetImpl(*this).SetAxisAutoLock(enable);
469 float ScrollView::GetAxisAutoLockGradient() const
471 return GetImpl(*this).GetAxisAutoLockGradient();
474 void ScrollView::SetAxisAutoLockGradient(float gradient)
476 GetImpl(*this).SetAxisAutoLockGradient(gradient);
479 float ScrollView::GetFrictionCoefficient() const
481 return GetImpl(*this).GetFrictionCoefficient();
484 void ScrollView::SetFrictionCoefficient(float friction)
486 GetImpl(*this).SetFrictionCoefficient(friction);
489 float ScrollView::GetFlickSpeedCoefficient() const
491 return GetImpl(*this).GetFlickSpeedCoefficient();
494 void ScrollView::SetFlickSpeedCoefficient(float speed)
496 GetImpl(*this).SetFlickSpeedCoefficient(speed);
499 Vector2 ScrollView::GetMinimumDistanceForFlick() const
501 return GetImpl(*this).GetMinimumDistanceForFlick();
504 void ScrollView::SetMinimumDistanceForFlick( const Vector2& distance )
506 GetImpl(*this).SetMinimumDistanceForFlick(distance);
509 float ScrollView::GetMinimumSpeedForFlick() const
511 return GetImpl(*this).GetMinimumSpeedForFlick();
514 void ScrollView::SetMinimumSpeedForFlick( float speed )
516 GetImpl(*this).SetMinimumSpeedForFlick(speed);
519 float ScrollView::GetMaxFlickSpeed() const
521 return GetImpl(*this).GetMaxFlickSpeed();
524 void ScrollView::SetMaxFlickSpeed(float speed)
526 GetImpl(*this).SetMaxFlickSpeed(speed);
529 Vector2 ScrollView::GetMouseWheelScrollDistanceStep() const
531 return GetImpl(*this).GetMouseWheelScrollDistanceStep();
534 void ScrollView::SetMouseWheelScrollDistanceStep(Vector2 step)
536 GetImpl(*this).SetMouseWheelScrollDistanceStep(step);
539 Vector3 ScrollView::GetCurrentScrollPosition() const
541 return GetImpl(*this).GetCurrentScrollPosition();
544 void ScrollView::SetScrollPosition(const Vector3& position)
546 GetImpl(*this).SetScrollPosition(position);
549 Vector3 ScrollView::GetCurrentScrollScale() const
551 DALI_LOG_ERROR( "Deprecated" );
555 unsigned int ScrollView::GetCurrentPage() const
557 return GetImpl(*this).GetCurrentPage();
560 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation)
562 DALI_LOG_ERROR( "Deprecated" );
564 GetImpl(*this).TransformTo(position);
567 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration)
569 DALI_LOG_ERROR( "Deprecated" );
571 GetImpl(*this).TransformTo(position, duration);
574 void ScrollView::ScrollTo(const Vector3 &position)
576 GetImpl(*this).ScrollTo(position);
579 void ScrollView::ScrollTo(const Vector3 &position, float duration)
581 GetImpl(*this).ScrollTo(position, duration);
584 void ScrollView::ScrollTo(const Vector3 &position, float duration,
585 DirectionBias horizontalBias, DirectionBias verticalBias)
587 GetImpl(*this).ScrollTo(position, duration, horizontalBias, verticalBias);
590 void ScrollView::ScrollTo(unsigned int page)
592 GetImpl(*this).ScrollTo(page);
595 void ScrollView::ScrollTo(unsigned int page, float duration)
597 GetImpl(*this).ScrollTo(page, duration);
600 void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
602 GetImpl(*this).ScrollTo(page, duration, bias);
605 void ScrollView::ScrollTo(Actor &actor)
607 GetImpl(*this).ScrollTo(actor);
610 void ScrollView::ScrollTo(Actor &actor, float duration)
612 GetImpl(*this).ScrollTo(actor, duration);
615 bool ScrollView::ScrollToSnapPoint()
617 return GetImpl(*this).ScrollToSnapPoint();
620 void ScrollView::ScaleTo(const Vector3 &scale)
622 DALI_LOG_ERROR( "Deprecated" );
625 void ScrollView::ScaleTo(const Vector3 &scale, float duration)
627 DALI_LOG_ERROR( "Deprecated" );
630 void ScrollView::ApplyConstraintToChildren(Constraint constraint)
632 GetImpl(*this).ApplyConstraintToChildren(constraint);
635 void ScrollView::RemoveConstraintsFromChildren()
637 GetImpl(*this).RemoveConstraintsFromChildren();
640 void ScrollView::ApplyEffect(ScrollViewEffect effect)
642 GetImpl(*this).ApplyEffect(effect);
645 ScrollViewEffect ScrollView::ApplyEffect(ScrollView::PageEffect effect)
647 return GetImpl(*this).ApplyEffect(effect);
650 void ScrollView::RemoveEffect(ScrollViewEffect effect)
652 GetImpl(*this).RemoveEffect(effect);
655 void ScrollView::RemoveAllEffects()
657 GetImpl(*this).RemoveAllEffects();
660 void ScrollView::BindActor(Actor child)
662 GetImpl(*this).BindActor(child);
665 void ScrollView::UnbindActor(Actor child)
667 GetImpl(*this).UnbindActor(child);
670 ScrollView::SnapStartedSignalV2& ScrollView::SnapStartedSignal()
672 return GetImpl(*this).SnapStartedSignal();
675 void ScrollView::SetScrollingDirection( Radian direction, Radian threshold )
677 GetImpl(*this).SetScrollingDirection( direction, threshold );
680 void ScrollView::RemoveScrollingDirection( Radian direction )
682 GetImpl(*this).RemoveScrollingDirection( direction );
685 } // namespace Toolkit