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.
18 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
19 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
20 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h>
30 ///////////////////////////////////////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////////////////////////////////////
34 RulerDomain::RulerDomain(float min, float max, bool enabled)
41 float RulerDomain::Clamp(float x, float length, float scale) const
45 return Clamp(x, length, scale, clamped);
48 float RulerDomain::Clamp(float x, float length, float scale, ClampState &clamped) const
56 const float minExtent = min * scale;
57 const float maxExtent = max * scale - length;
60 clamped = ClampedToMin;
63 else if(x > maxExtent)
65 clamped = ClampedToMax;
73 float RulerDomain::GetSize() const
78 ///////////////////////////////////////////////////////////////////////////////////////////////////
80 ///////////////////////////////////////////////////////////////////////////////////////////////////
85 mDomain(RulerDomain(0.0f,1.0f,false))
93 Ruler::RulerType Ruler::GetType() const
98 bool Ruler::IsEnabled() const
108 void Ruler::Disable()
113 void Ruler::SetDomain(RulerDomain domain)
118 const RulerDomain &Ruler::GetDomain() const
123 void Ruler::DisableDomain()
125 mDomain = RulerDomain(0.0f,1.0f,false);
128 float Ruler::Clamp(float x, float length, float scale) const
130 return mDomain.Clamp(x, length, scale);
133 float Ruler::Clamp(float x, float length, float scale, ClampState &clamped) const
135 return mDomain.Clamp(x, length, scale, clamped);
138 float Ruler::SnapAndClamp(float x, float bias, float length, float scale) const
140 return Clamp(Snap(x, bias), length, scale);
143 float Ruler::SnapAndClamp(float x, float bias, float length, float scale, ClampState &clamped) const
145 return Clamp(Snap(x, bias), length, scale, clamped);
148 ///////////////////////////////////////////////////////////////////////////////////////////////////
150 ///////////////////////////////////////////////////////////////////////////////////////////////////
152 DefaultRuler::DefaultRuler()
157 float DefaultRuler::Snap(float x, float bias) const
162 float DefaultRuler::GetPositionFromPage(unsigned int page, unsigned int &volume, bool wrap) const
168 unsigned int DefaultRuler::GetPageFromPosition(float position, bool wrap) const
173 unsigned int DefaultRuler::GetTotalPages() const
178 ///////////////////////////////////////////////////////////////////////////////////////////////////
180 ///////////////////////////////////////////////////////////////////////////////////////////////////
182 FixedRuler::FixedRuler(float spacing)
188 float FixedRuler::Snap(float x, float bias) const
190 return floor(x / mSpacing + bias) * mSpacing;
193 float FixedRuler::GetPositionFromPage(unsigned int page, unsigned int &volume, bool wrap) const
195 float position = mDomain.min;
199 // spacing must be present.
200 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
202 unsigned int column = page;
204 // In carry mode, a volume (carry) is produced when page exceeds limit within domain
207 unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
210 column += pagesPerVolume;
211 column %= pagesPerVolume;
212 volume = page/pagesPerVolume;
216 position = mDomain.min + column * mSpacing;
218 else // Domain (or Spacing) is not present, carry page to volume.
229 unsigned int FixedRuler::GetPageFromPosition(float position, bool wrap) const
231 unsigned int page = 0;
233 // spacing must be present.
234 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
236 page = floor((position - mDomain.min) / mSpacing + 0.5f);
240 unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
241 page %= pagesPerVolume;
248 unsigned int FixedRuler::GetTotalPages() const
250 unsigned int pagesPerVolume = 1;
252 // spacing must be present.
253 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
255 pagesPerVolume = mDomain.GetSize() / mSpacing;
258 return pagesPerVolume;
261 ///////////////////////////////////////////////////////////////////////////////////////////////////
263 ///////////////////////////////////////////////////////////////////////////////////////////////////
265 const std::string ScrollView::SCROLL_PAGE_CURRENT( "scroll-page-current" );
266 const std::string ScrollView::SCROLL_TIME_PROPERTY_NAME( "scroll-time" );
267 const std::string ScrollView::SCROLL_POSITION_PROPERTY_NAME( "scroll-position" );
268 const std::string ScrollView::SCROLL_PRE_POSITION_PROPERTY_NAME( "scroll-pre-position" );
269 const std::string ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME( "scroll-overshoot-x" );
270 const std::string ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME( "scroll-overshoot-y" );
271 const std::string ScrollView::SCROLL_FINAL_PROPERTY_NAME( "scroll-final" );
272 const std::string ScrollView::SCROLL_X_PROPERTY_NAME( "scroll-x" );
273 const std::string ScrollView::SCROLL_Y_PROPERTY_NAME( "scroll-y" );
274 const std::string ScrollView::SCROLL_SCALE_PROPERTY_NAME( "scroll-scale" );
275 const std::string ScrollView::SCROLL_WRAP_PROPERTY_NAME( "scroll-wrap" );
276 const std::string ScrollView::SCROLL_PANNING_PROPERTY_NAME( "scroll-panning" );
277 const std::string ScrollView::SCROLL_SCROLLING_PROPERTY_NAME( "scroll-scrolling" );
278 const std::string ScrollView::SCROLL_POSITION_DELTA_PROPERTY_NAME( "scroll-position-delta" );
279 const std::string ScrollView::SCROLL_START_PAGE_POSITION_PROPERTY_NAME( "scroll-start-page-position" );
281 const float ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION(0.5f);
282 const float ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION(0.25f);
283 const float ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION(0.5f);
284 const float ScrollView::DEFAULT_MAX_OVERSHOOT(100.0f); // 100 pixels
286 const float ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT(0.36f);
287 const float ScrollView::DEFAULT_FRICTION_COEFFICIENT(1.0f);
288 const float ScrollView::DEFAULT_FLICK_SPEED_COEFFICIENT(1.0f);
289 const float ScrollView::DEFAULT_MAX_FLICK_SPEED(3.0f);
291 const char* const ScrollView::SIGNAL_SNAP_STARTED = "snap-started";
293 ScrollView::ScrollView()
297 ScrollView::ScrollView(Internal::ScrollView& implementation)
298 : Scrollable(implementation)
302 ScrollView::ScrollView( Dali::Internal::CustomActor* internal )
303 : Scrollable( internal )
305 VerifyCustomActorPointer<Internal::ScrollView>(internal);
308 ScrollView::ScrollView( const ScrollView& handle )
309 : Scrollable( handle )
313 ScrollView& ScrollView::operator=( const ScrollView& handle )
315 if( &handle != this )
317 Control::operator=( handle );
322 ScrollView ScrollView::New()
324 return Internal::ScrollView::New();
327 ScrollView::~ScrollView()
331 ScrollView ScrollView::DownCast( BaseHandle handle )
333 return Control::DownCast<ScrollView, Internal::ScrollView>(handle);
336 AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
338 return GetImpl(*this).GetScrollSnapAlphaFunction();
341 void ScrollView::SetScrollSnapAlphaFunction(AlphaFunction alpha)
343 GetImpl(*this).SetScrollSnapAlphaFunction(alpha);
346 AlphaFunction ScrollView::GetScrollFlickAlphaFunction() const
348 return GetImpl(*this).GetScrollFlickAlphaFunction();
351 void ScrollView::SetScrollFlickAlphaFunction(AlphaFunction alpha)
353 GetImpl(*this).SetScrollFlickAlphaFunction(alpha);
356 float ScrollView::GetScrollSnapDuration() const
358 return GetImpl(*this).GetScrollSnapDuration();
361 void ScrollView::SetScrollSnapDuration(float time)
363 GetImpl(*this).SetScrollSnapDuration(time);
366 float ScrollView::GetScrollFlickDuration() const
368 return GetImpl(*this).GetScrollFlickDuration();
371 void ScrollView::SetScrollFlickDuration(float time)
373 GetImpl(*this).SetScrollFlickDuration(time);
376 void ScrollView::SetRulerX(RulerPtr ruler)
378 GetImpl(*this).SetRulerX(ruler);
381 void ScrollView::SetRulerY(RulerPtr ruler)
383 GetImpl(*this).SetRulerY(ruler);
386 void ScrollView::SetRulerScaleX(RulerPtr ruler)
388 GetImpl(*this).SetRulerScaleX(ruler);
391 void ScrollView::SetRulerScaleY(RulerPtr ruler)
393 GetImpl(*this).SetRulerScaleY(ruler);
396 void ScrollView::SetScrollSensitive(bool sensitive)
398 GetImpl(*this).SetScrollSensitive(sensitive);
401 void ScrollView::SetMaxOvershoot(float overshootX, float overshootY)
403 GetImpl(*this).SetMaxOvershoot(overshootX, overshootY);
406 void ScrollView::SetSnapOvershootAlphaFunction(AlphaFunction alpha)
408 GetImpl(*this).SetSnapOvershootAlphaFunction(alpha);
411 void ScrollView::SetSnapOvershootDuration(float duration)
413 GetImpl(*this).SetSnapOvershootDuration(duration);
416 void ScrollView::SetTouchesRequiredForPanning(unsigned int minTouches, unsigned int maxTouches, bool endOutside)
418 GetImpl(*this).SetTouchesRequiredForPanning(minTouches, maxTouches, endOutside);
421 void ScrollView::SetActorAutoSnap(bool enable)
423 GetImpl(*this).SetActorAutoSnap(enable);
426 void ScrollView::SetWrapMode(bool enable)
428 GetImpl(*this).SetWrapMode(enable);
431 int ScrollView::GetRefreshInterval() const
433 return GetImpl(*this).GetRefreshInterval();
436 void ScrollView::SetRefreshInterval(int milliseconds)
438 GetImpl(*this).SetRefreshInterval(milliseconds);
441 int ScrollView::GetScrollUpdateDistance() const
443 return GetImpl(*this).GetScrollUpdateDistance();
446 void ScrollView::SetScrollUpdateDistance(int distance)
448 GetImpl(*this).SetScrollUpdateDistance(distance);
451 bool ScrollView::GetAxisAutoLock() const
453 return GetImpl(*this).GetAxisAutoLock();
456 void ScrollView::SetAxisAutoLock(bool enable)
458 GetImpl(*this).SetAxisAutoLock(enable);
461 float ScrollView::GetAxisAutoLockGradient() const
463 return GetImpl(*this).GetAxisAutoLockGradient();
466 void ScrollView::SetAxisAutoLockGradient(float gradient)
468 GetImpl(*this).SetAxisAutoLockGradient(gradient);
471 float ScrollView::GetFrictionCoefficient() const
473 return GetImpl(*this).GetFrictionCoefficient();
476 void ScrollView::SetFrictionCoefficient(float friction)
478 GetImpl(*this).SetFrictionCoefficient(friction);
481 float ScrollView::GetFlickSpeedCoefficient() const
483 return GetImpl(*this).GetFlickSpeedCoefficient();
486 void ScrollView::SetFlickSpeedCoefficient(float speed)
488 GetImpl(*this).SetFlickSpeedCoefficient(speed);
491 float ScrollView::GetMaxFlickSpeed() const
493 return GetImpl(*this).GetMaxFlickSpeed();
496 void ScrollView::SetMaxFlickSpeed(float speed)
498 GetImpl(*this).SetMaxFlickSpeed(speed);
501 Vector2 ScrollView::GetMouseWheelScrollDistanceStep() const
503 return GetImpl(*this).GetMouseWheelScrollDistanceStep();
506 void ScrollView::SetMouseWheelScrollDistanceStep(Vector2 step)
508 GetImpl(*this).SetMouseWheelScrollDistanceStep(step);
511 Vector3 ScrollView::GetCurrentScrollPosition() const
513 return GetImpl(*this).GetCurrentScrollPosition();
516 void ScrollView::SetScrollPosition(const Vector3& position)
518 GetImpl(*this).SetScrollPosition(position);
521 Vector3 ScrollView::GetCurrentScrollScale() const
523 return GetImpl(*this).GetCurrentScrollScale();
526 unsigned int ScrollView::GetCurrentPage() const
528 return GetImpl(*this).GetCurrentPage();
531 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation)
533 GetImpl(*this).TransformTo(position, scale, rotation);
536 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration)
538 GetImpl(*this).TransformTo(position, scale, rotation, duration);
541 void ScrollView::ScrollTo(const Vector3 &position)
543 GetImpl(*this).ScrollTo(position);
546 void ScrollView::ScrollTo(const Vector3 &position, float duration)
548 GetImpl(*this).ScrollTo(position, duration);
551 void ScrollView::ScrollTo(const Vector3 &position, float duration,
552 DirectionBias horizontalBias, DirectionBias verticalBias)
554 GetImpl(*this).ScrollTo(position, duration, horizontalBias, verticalBias);
557 void ScrollView::ScrollTo(unsigned int page)
559 GetImpl(*this).ScrollTo(page);
562 void ScrollView::ScrollTo(unsigned int page, float duration)
564 GetImpl(*this).ScrollTo(page, duration);
567 void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
569 GetImpl(*this).ScrollTo(page, duration, bias);
572 void ScrollView::ScrollTo(Actor &actor)
574 GetImpl(*this).ScrollTo(actor);
577 void ScrollView::ScrollTo(Actor &actor, float duration)
579 GetImpl(*this).ScrollTo(actor, duration);
582 bool ScrollView::ScrollToSnapPoint()
584 return GetImpl(*this).ScrollToSnapPoint();
587 void ScrollView::ScaleTo(const Vector3 &scale)
589 GetImpl(*this).ScaleTo(scale);
592 void ScrollView::ScaleTo(const Vector3 &scale, float duration)
594 GetImpl(*this).ScaleTo(scale, duration);
597 void ScrollView::ApplyConstraintToChildren(Constraint constraint)
599 GetImpl(*this).ApplyConstraintToChildren(constraint);
602 void ScrollView::RemoveConstraintsFromChildren()
604 GetImpl(*this).RemoveConstraintsFromChildren();
607 void ScrollView::ApplyEffect(ScrollViewEffect effect)
609 GetImpl(*this).ApplyEffect(effect);
612 ScrollViewEffect ScrollView::ApplyEffect(ScrollView::PageEffect effect)
614 return GetImpl(*this).ApplyEffect(effect);
617 void ScrollView::RemoveEffect(ScrollViewEffect effect)
619 GetImpl(*this).RemoveEffect(effect);
622 void ScrollView::RemoveAllEffects()
624 GetImpl(*this).RemoveAllEffects();
627 void ScrollView::BindActor(Actor child)
629 GetImpl(*this).BindActor(child);
632 void ScrollView::UnbindActor(Actor child)
634 GetImpl(*this).UnbindActor(child);
637 ScrollView::SnapStartedSignalV2& ScrollView::SnapStartedSignal()
639 return GetImpl(*this).SnapStartedSignal();
642 void ScrollView::SetScrollingDirection( Radian direction, Radian threshold )
644 GetImpl(*this).SetScrollingDirection( direction, threshold );
647 void ScrollView::RemoveScrollingDirection( Radian direction )
649 GetImpl(*this).RemoveScrollingDirection( direction );
652 } // namespace Toolkit