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)
242 page = floor((position - mDomain.min) / mSpacing + 0.5f);
246 unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
247 page %= pagesPerVolume;
254 unsigned int FixedRuler::GetTotalPages() const
256 unsigned int pagesPerVolume = 1;
258 // spacing must be present.
259 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
261 pagesPerVolume = mDomain.GetSize() / mSpacing;
264 return pagesPerVolume;
267 ///////////////////////////////////////////////////////////////////////////////////////////////////
269 ///////////////////////////////////////////////////////////////////////////////////////////////////
271 const std::string ScrollView::SCROLL_PAGE_CURRENT( "scroll-page-current" );
272 const std::string ScrollView::SCROLL_TIME_PROPERTY_NAME( "scroll-time" );
273 const std::string ScrollView::SCROLL_POSITION_PROPERTY_NAME( "scroll-position" );
274 const std::string ScrollView::SCROLL_PRE_POSITION_PROPERTY_NAME( "scroll-pre-position" );
275 const std::string ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME( "scroll-overshoot-x" );
276 const std::string ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME( "scroll-overshoot-y" );
277 const std::string ScrollView::SCROLL_FINAL_PROPERTY_NAME( "scroll-final" );
278 const std::string ScrollView::SCROLL_X_PROPERTY_NAME( "scroll-x" );
279 const std::string ScrollView::SCROLL_Y_PROPERTY_NAME( "scroll-y" );
280 const std::string ScrollView::SCROLL_SCALE_PROPERTY_NAME( "scroll-scale" );
281 const std::string ScrollView::SCROLL_WRAP_PROPERTY_NAME( "scroll-wrap" );
282 const std::string ScrollView::SCROLL_PANNING_PROPERTY_NAME( "scroll-panning" );
283 const std::string ScrollView::SCROLL_SCROLLING_PROPERTY_NAME( "scroll-scrolling" );
284 const std::string ScrollView::SCROLL_POSITION_DELTA_PROPERTY_NAME( "scroll-position-delta" );
285 const std::string ScrollView::SCROLL_START_PAGE_POSITION_PROPERTY_NAME( "scroll-start-page-position" );
287 const float ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION(0.5f);
288 const float ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION(0.25f);
289 const float ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION(0.5f);
290 const float ScrollView::DEFAULT_MAX_OVERSHOOT(100.0f); // 100 pixels
292 const float ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT(0.36f);
293 const float ScrollView::DEFAULT_FRICTION_COEFFICIENT(1.0f);
294 const float ScrollView::DEFAULT_FLICK_SPEED_COEFFICIENT(1.0f);
295 const float ScrollView::DEFAULT_MAX_FLICK_SPEED(3.0f);
297 const char* const ScrollView::SIGNAL_SNAP_STARTED = "snap-started";
299 ScrollView::ScrollView()
303 ScrollView::ScrollView(Internal::ScrollView& implementation)
304 : Scrollable(implementation)
308 ScrollView::ScrollView( Dali::Internal::CustomActor* internal )
309 : Scrollable( internal )
311 VerifyCustomActorPointer<Internal::ScrollView>(internal);
314 ScrollView::ScrollView( const ScrollView& handle )
315 : Scrollable( handle )
319 ScrollView& ScrollView::operator=( const ScrollView& handle )
321 if( &handle != this )
323 Control::operator=( handle );
328 ScrollView ScrollView::New()
330 return Internal::ScrollView::New();
333 ScrollView::~ScrollView()
337 ScrollView ScrollView::DownCast( BaseHandle handle )
339 return Control::DownCast<ScrollView, Internal::ScrollView>(handle);
342 AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
344 return GetImpl(*this).GetScrollSnapAlphaFunction();
347 void ScrollView::SetScrollSnapAlphaFunction(AlphaFunction alpha)
349 GetImpl(*this).SetScrollSnapAlphaFunction(alpha);
352 AlphaFunction ScrollView::GetScrollFlickAlphaFunction() const
354 return GetImpl(*this).GetScrollFlickAlphaFunction();
357 void ScrollView::SetScrollFlickAlphaFunction(AlphaFunction alpha)
359 GetImpl(*this).SetScrollFlickAlphaFunction(alpha);
362 float ScrollView::GetScrollSnapDuration() const
364 return GetImpl(*this).GetScrollSnapDuration();
367 void ScrollView::SetScrollSnapDuration(float time)
369 GetImpl(*this).SetScrollSnapDuration(time);
372 float ScrollView::GetScrollFlickDuration() const
374 return GetImpl(*this).GetScrollFlickDuration();
377 void ScrollView::SetScrollFlickDuration(float time)
379 GetImpl(*this).SetScrollFlickDuration(time);
382 void ScrollView::SetRulerX(RulerPtr ruler)
384 GetImpl(*this).SetRulerX(ruler);
387 void ScrollView::SetRulerY(RulerPtr ruler)
389 GetImpl(*this).SetRulerY(ruler);
392 void ScrollView::SetRulerScaleX(RulerPtr ruler)
394 DALI_LOG_ERROR( "Deprecated" );
397 void ScrollView::SetRulerScaleY(RulerPtr ruler)
399 DALI_LOG_ERROR( "Deprecated" );
402 void ScrollView::SetScrollSensitive(bool sensitive)
404 GetImpl(*this).SetScrollSensitive(sensitive);
407 void ScrollView::SetMaxOvershoot(float overshootX, float overshootY)
409 GetImpl(*this).SetMaxOvershoot(overshootX, overshootY);
412 void ScrollView::SetSnapOvershootAlphaFunction(AlphaFunction alpha)
414 GetImpl(*this).SetSnapOvershootAlphaFunction(alpha);
417 void ScrollView::SetSnapOvershootDuration(float duration)
419 GetImpl(*this).SetSnapOvershootDuration(duration);
422 void ScrollView::SetTouchesRequiredForPanning(unsigned int minTouches, unsigned int maxTouches, bool endOutside)
424 GetImpl(*this).SetTouchesRequiredForPanning(minTouches, maxTouches, endOutside);
427 void ScrollView::SetActorAutoSnap(bool enable)
429 GetImpl(*this).SetActorAutoSnap(enable);
432 void ScrollView::SetWrapMode(bool enable)
434 GetImpl(*this).SetWrapMode(enable);
437 int ScrollView::GetRefreshInterval() const
439 return GetImpl(*this).GetRefreshInterval();
442 void ScrollView::SetRefreshInterval(int milliseconds)
444 GetImpl(*this).SetRefreshInterval(milliseconds);
447 int ScrollView::GetScrollUpdateDistance() const
449 return GetImpl(*this).GetScrollUpdateDistance();
452 void ScrollView::SetScrollUpdateDistance(int distance)
454 GetImpl(*this).SetScrollUpdateDistance(distance);
457 bool ScrollView::GetAxisAutoLock() const
459 return GetImpl(*this).GetAxisAutoLock();
462 void ScrollView::SetAxisAutoLock(bool enable)
464 GetImpl(*this).SetAxisAutoLock(enable);
467 float ScrollView::GetAxisAutoLockGradient() const
469 return GetImpl(*this).GetAxisAutoLockGradient();
472 void ScrollView::SetAxisAutoLockGradient(float gradient)
474 GetImpl(*this).SetAxisAutoLockGradient(gradient);
477 float ScrollView::GetFrictionCoefficient() const
479 return GetImpl(*this).GetFrictionCoefficient();
482 void ScrollView::SetFrictionCoefficient(float friction)
484 GetImpl(*this).SetFrictionCoefficient(friction);
487 float ScrollView::GetFlickSpeedCoefficient() const
489 return GetImpl(*this).GetFlickSpeedCoefficient();
492 void ScrollView::SetFlickSpeedCoefficient(float speed)
494 GetImpl(*this).SetFlickSpeedCoefficient(speed);
497 Vector2 ScrollView::GetMinimumDistanceForFlick() const
499 return GetImpl(*this).GetMinimumDistanceForFlick();
502 void ScrollView::SetMinimumDistanceForFlick( const Vector2& distance )
504 GetImpl(*this).SetMinimumDistanceForFlick(distance);
507 float ScrollView::GetMinimumSpeedForFlick() const
509 return GetImpl(*this).GetMinimumSpeedForFlick();
512 void ScrollView::SetMinimumSpeedForFlick( float speed )
514 GetImpl(*this).SetMinimumSpeedForFlick(speed);
517 float ScrollView::GetMaxFlickSpeed() const
519 return GetImpl(*this).GetMaxFlickSpeed();
522 void ScrollView::SetMaxFlickSpeed(float speed)
524 GetImpl(*this).SetMaxFlickSpeed(speed);
527 Vector2 ScrollView::GetMouseWheelScrollDistanceStep() const
529 return GetImpl(*this).GetMouseWheelScrollDistanceStep();
532 void ScrollView::SetMouseWheelScrollDistanceStep(Vector2 step)
534 GetImpl(*this).SetMouseWheelScrollDistanceStep(step);
537 Vector3 ScrollView::GetCurrentScrollPosition() const
539 return GetImpl(*this).GetCurrentScrollPosition();
542 void ScrollView::SetScrollPosition(const Vector3& position)
544 GetImpl(*this).SetScrollPosition(position);
547 Vector3 ScrollView::GetCurrentScrollScale() const
549 DALI_LOG_ERROR( "Deprecated" );
553 unsigned int ScrollView::GetCurrentPage() const
555 return GetImpl(*this).GetCurrentPage();
558 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation)
560 DALI_LOG_ERROR( "Deprecated" );
562 GetImpl(*this).TransformTo(position);
565 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration)
567 DALI_LOG_ERROR( "Deprecated" );
569 GetImpl(*this).TransformTo(position, duration);
572 void ScrollView::ScrollTo(const Vector3 &position)
574 GetImpl(*this).ScrollTo(position);
577 void ScrollView::ScrollTo(const Vector3 &position, float duration)
579 GetImpl(*this).ScrollTo(position, duration);
582 void ScrollView::ScrollTo(const Vector3 &position, float duration,
583 DirectionBias horizontalBias, DirectionBias verticalBias)
585 GetImpl(*this).ScrollTo(position, duration, horizontalBias, verticalBias);
588 void ScrollView::ScrollTo(unsigned int page)
590 GetImpl(*this).ScrollTo(page);
593 void ScrollView::ScrollTo(unsigned int page, float duration)
595 GetImpl(*this).ScrollTo(page, duration);
598 void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
600 GetImpl(*this).ScrollTo(page, duration, bias);
603 void ScrollView::ScrollTo(Actor &actor)
605 GetImpl(*this).ScrollTo(actor);
608 void ScrollView::ScrollTo(Actor &actor, float duration)
610 GetImpl(*this).ScrollTo(actor, duration);
613 bool ScrollView::ScrollToSnapPoint()
615 return GetImpl(*this).ScrollToSnapPoint();
618 void ScrollView::ScaleTo(const Vector3 &scale)
620 DALI_LOG_ERROR( "Deprecated" );
623 void ScrollView::ScaleTo(const Vector3 &scale, float duration)
625 DALI_LOG_ERROR( "Deprecated" );
628 void ScrollView::ApplyConstraintToChildren(Constraint constraint)
630 GetImpl(*this).ApplyConstraintToChildren(constraint);
633 void ScrollView::RemoveConstraintsFromChildren()
635 GetImpl(*this).RemoveConstraintsFromChildren();
638 void ScrollView::ApplyEffect(ScrollViewEffect effect)
640 GetImpl(*this).ApplyEffect(effect);
643 ScrollViewEffect ScrollView::ApplyEffect(ScrollView::PageEffect effect)
645 return GetImpl(*this).ApplyEffect(effect);
648 void ScrollView::RemoveEffect(ScrollViewEffect effect)
650 GetImpl(*this).RemoveEffect(effect);
653 void ScrollView::RemoveAllEffects()
655 GetImpl(*this).RemoveAllEffects();
658 void ScrollView::BindActor(Actor child)
660 GetImpl(*this).BindActor(child);
663 void ScrollView::UnbindActor(Actor child)
665 GetImpl(*this).UnbindActor(child);
668 ScrollView::SnapStartedSignalV2& ScrollView::SnapStartedSignal()
670 return GetImpl(*this).SnapStartedSignal();
673 void ScrollView::SetScrollingDirection( Radian direction, Radian threshold )
675 GetImpl(*this).SetScrollingDirection( direction, threshold );
678 void ScrollView::RemoveScrollingDirection( Radian direction )
680 GetImpl(*this).RemoveScrollingDirection( direction );
683 } // namespace Toolkit