2 * Copyright (c) 2020 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/internal/controls/scroll-bar/scroll-bar-impl.h>
22 #include <cstring> // for strcmp
23 #include <dali/public-api/animation/constraint.h>
24 #include <dali/public-api/animation/constraints.h>
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/public-api/object/property-array.h>
27 #include <dali/public-api/object/type-registry-helper.h>
28 #include <dali/integration-api/debug.h>
29 #include <dali/devel-api/object/property-helper-devel.h>
30 #include <dali/devel-api/actors/actor-devel.h>
33 #include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
34 #include <dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h>
35 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
42 const char* DEFAULT_INDICATOR_IMAGE_FILE_NAME = "popup_scroll.9.png";
43 const float DEFAULT_SLIDER_DEPTH(1.0f);
44 const float DEFAULT_INDICATOR_SHOW_DURATION(0.5f);
45 const float DEFAULT_INDICATOR_HIDE_DURATION(0.5f);
46 const float DEFAULT_PAN_GESTURE_PROCESS_TIME(16.7f); // 16.7 milliseconds, i.e. one frame
47 const float DEFAULT_INDICATOR_FIXED_HEIGHT(80.0f);
48 const float DEFAULT_INDICATOR_MINIMUM_HEIGHT(0.0f);
49 const float DEFAULT_INDICATOR_START_PADDING(0.0f);
50 const float DEFAULT_INDICATOR_END_PADDING(0.0f);
51 const float DEFAULT_INDICATOR_TRANSIENT_DURATION(1.0f);
54 * Indicator size constraint
55 * Indicator size depends on both indicator's parent size and the scroll content size
57 struct IndicatorSizeConstraint
60 * @param[in] minimumHeight The minimum height for the indicator
61 * @param[in] padding The sum of the padding at the start & end of the indicator
63 IndicatorSizeConstraint( float minimumHeight, float padding )
64 : mMinimumHeight( minimumHeight ),
71 * @param[in] current The current indicator size
72 * @param[in] parentSizeProperty The parent size of scroll indicator.
73 * @return The new scroll indicator size.
75 void operator()( Vector3& current, const PropertyInputContainer& inputs )
77 const Vector3& parentSize = inputs[0]->GetVector3();
78 const float contentSize = inputs[1]->GetFloat();
80 // Take into account padding that may exist at the beginning and end of the indicator.
81 const float parentHeightMinusPadding = parentSize.height - mPadding;
83 float height = contentSize > parentHeightMinusPadding ?
84 parentHeightMinusPadding * ( parentHeightMinusPadding / contentSize ) :
85 parentHeightMinusPadding * ( ( parentHeightMinusPadding - contentSize * 0.5f ) / parentHeightMinusPadding );
87 current.y = std::max( mMinimumHeight, height );
95 * Indicator position constraint
96 * Positions the indicator to reflect the current scroll position within the scroll domain.
98 struct IndicatorPositionConstraint
101 * @param[in] startPadding The padding at the start of the indicator
102 * @param[in] endPadding The padding at the end of the indicator
104 IndicatorPositionConstraint( float startPadding, float endPadding )
105 : mStartPadding( startPadding ),
106 mEndPadding( endPadding )
111 * Constraint operator
112 * @param[in,out] current The current indicator position
113 * @param[in] inputs Contains the size of indicator, the size of indicator's parent, and the scroll position of the scrollable container (from 0.0 -> 1.0 in each axis)
114 * @return The new indicator position is returned.
116 void operator()( Vector3& current, const PropertyInputContainer& inputs )
118 const Vector3& indicatorSize = inputs[0]->GetVector3();
119 const Vector3& parentSize = inputs[1]->GetVector3();
120 const float scrollPosition = -inputs[2]->GetFloat();
121 const float minimumScrollPosition = inputs[3]->GetFloat();
122 const float maximumScrollPosition = inputs[4]->GetFloat();
124 // Take into account padding that may exist at the beginning and end of the indicator.
125 const float parentHeightMinusPadding = parentSize.height - ( mStartPadding + mEndPadding );
127 float relativePosition = std::max( 0.0f, std::min( 1.0f, ( scrollPosition - minimumScrollPosition ) / ( maximumScrollPosition - minimumScrollPosition ) ) );
128 current.y = mStartPadding + ( parentHeightMinusPadding - indicatorSize.height ) * relativePosition;
129 current.z = DEFAULT_SLIDER_DEPTH;
136 } // unnamed namespace
150 using namespace Dali;
154 return Toolkit::ScrollBar::New();
157 // Setup properties, signals and actions using the type-registry.
158 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ScrollBar, Toolkit::Control, Create );
160 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollDirection", STRING, SCROLL_DIRECTION )
161 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHeightPolicy", STRING, INDICATOR_HEIGHT_POLICY )
162 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorFixedHeight", FLOAT, INDICATOR_FIXED_HEIGHT )
163 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorShowDuration", FLOAT, INDICATOR_SHOW_DURATION )
164 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHideDuration", FLOAT, INDICATOR_HIDE_DURATION )
165 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervals", ARRAY, SCROLL_POSITION_INTERVALS )
166 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorMinimumHeight", FLOAT, INDICATOR_MINIMUM_HEIGHT )
167 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorStartPadding", FLOAT, INDICATOR_START_PADDING )
168 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorEndPadding", FLOAT, INDICATOR_END_PADDING )
169 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorTransientDuration", FLOAT, INDICATOR_TRANSIENT_DURATION )
171 DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "panFinished", PAN_FINISHED_SIGNAL )
172 DALI_SIGNAL_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervalReached", SCROLL_POSITION_INTERVAL_REACHED_SIGNAL )
174 DALI_ACTION_REGISTRATION( Toolkit, ScrollBar, "ShowIndicator", ACTION_SHOW_INDICATOR )
175 DALI_ACTION_REGISTRATION( Toolkit, ScrollBar, "HideIndicator", ACTION_HIDE_INDICATOR )
176 DALI_ACTION_REGISTRATION( Toolkit, ScrollBar, "ShowTransientIndicator", ACTION_SHOW_TRANSIENT_INDICATOR )
178 DALI_TYPE_REGISTRATION_END()
180 const char* SCROLL_DIRECTION_NAME[] = {"VERTICAL", "HORIZONTAL"};
181 const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"VARIABLE", "FIXED"};
185 ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction)
186 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
187 mIndicatorShowAlpha(1.0f),
188 mDirection(direction),
189 mScrollableObject(WeakHandle<Handle>()),
190 mPropertyScrollPosition(Property::INVALID_INDEX),
191 mPropertyMinScrollPosition(Property::INVALID_INDEX),
192 mPropertyMaxScrollPosition(Property::INVALID_INDEX),
193 mPropertyScrollContentSize(Property::INVALID_INDEX),
194 mIndicatorShowDuration(DEFAULT_INDICATOR_SHOW_DURATION),
195 mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION),
196 mTransientIndicatorDuration(DEFAULT_INDICATOR_TRANSIENT_DURATION),
198 mGestureDisplacement( Vector2::ZERO ),
199 mCurrentScrollPosition(0.0f),
200 mIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE),
201 mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT),
202 mIndicatorMinimumHeight(DEFAULT_INDICATOR_MINIMUM_HEIGHT),
203 mIndicatorStartPadding(DEFAULT_INDICATOR_START_PADDING),
204 mIndicatorEndPadding(DEFAULT_INDICATOR_END_PADDING),
206 mIndicatorFirstShow(true)
208 DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) {
209 return std::unique_ptr< Dali::Accessibility::Accessible >(
210 new AccessibleImpl( actor, Dali::Accessibility::Role::SCROLL_BAR ) );
214 ScrollBar::~ScrollBar()
218 void ScrollBar::OnInitialize()
220 CreateDefaultIndicatorActor();
221 Self().SetProperty( Actor::Property::DRAW_MODE,DrawMode::OVERLAY_2D);
224 void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize )
227 && propertyScrollPosition != Property::INVALID_INDEX
228 && propertyMinScrollPosition != Property::INVALID_INDEX
229 && propertyMaxScrollPosition != Property::INVALID_INDEX
230 && propertyScrollContentSize != Property::INVALID_INDEX )
232 mScrollableObject = WeakHandle<Handle>(handle);
233 mPropertyScrollPosition = propertyScrollPosition;
234 mPropertyMinScrollPosition = propertyMinScrollPosition;
235 mPropertyMaxScrollPosition = propertyMaxScrollPosition;
236 mPropertyScrollContentSize = propertyScrollContentSize;
242 DALI_LOG_ERROR("Can not set empty handle of source object or invalid source property index\n");
246 void ScrollBar::CreateDefaultIndicatorActor()
248 const std::string imageDirPath = AssetManager::GetDaliImagePath();
249 Toolkit::ImageView indicator = Toolkit::ImageView::New( imageDirPath + DEFAULT_INDICATOR_IMAGE_FILE_NAME );
250 indicator.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
251 indicator.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
252 indicator.SetStyleName( "ScrollBarIndicator" );
253 indicator.SetProperty( Actor::Property::COLOR_MODE, USE_OWN_MULTIPLY_PARENT_COLOR );
254 SetScrollIndicator(indicator);
257 void ScrollBar::SetScrollIndicator( Actor indicator )
259 // Don't allow empty handle
262 // Remove current Indicator
265 Self().Remove( mIndicator );
267 mIndicator = indicator;
269 mIndicatorFirstShow = true;
270 Self().Add( mIndicator );
272 EnableGestureDetection( GestureType::Value( GestureType::PAN ) );
274 PanGestureDetector detector( GetPanGestureDetector() );
275 detector.DetachAll();
276 detector.Attach( mIndicator );
278 unsigned int childCount = mIndicator.GetChildCount();
279 for ( unsigned int index = 0; index < childCount; index++ )
281 Actor child = mIndicator.GetChildAt( index );
284 detector.Attach( child );
290 DALI_LOG_ERROR("Empty handle of scroll indicator\n");
294 Actor ScrollBar::GetScrollIndicator()
299 void ScrollBar::ApplyConstraints()
301 Handle scrollableHandle = mScrollableObject.GetHandle();
303 if( scrollableHandle )
305 if(mIndicatorSizeConstraint)
307 mIndicatorSizeConstraint.Remove();
310 // Set indicator height according to the indicator's height policy
311 if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED)
313 mIndicator.SetProperty( Actor::Property::SIZE, Vector2( Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).width, mIndicatorFixedHeight) );
317 mIndicatorSizeConstraint = Constraint::New<Vector3>( mIndicator, Actor::Property::SIZE,
318 IndicatorSizeConstraint( mIndicatorMinimumHeight, mIndicatorStartPadding + mIndicatorEndPadding ) );
319 mIndicatorSizeConstraint.AddSource( ParentSource( Actor::Property::SIZE ) );
320 mIndicatorSizeConstraint.AddSource( Source( scrollableHandle, mPropertyScrollContentSize ) );
321 mIndicatorSizeConstraint.Apply();
324 if(mIndicatorPositionConstraint)
326 mIndicatorPositionConstraint.Remove();
329 mIndicatorPositionConstraint = Constraint::New<Vector3>( mIndicator, Actor::Property::POSITION,
330 IndicatorPositionConstraint( mIndicatorStartPadding, mIndicatorEndPadding ) );
331 mIndicatorPositionConstraint.AddSource( LocalSource( Actor::Property::SIZE ) );
332 mIndicatorPositionConstraint.AddSource( ParentSource( Actor::Property::SIZE ) );
333 mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyScrollPosition ) );
334 mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMinScrollPosition ) );
335 mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMaxScrollPosition ) );
336 mIndicatorPositionConstraint.Apply();
340 void ScrollBar::SetScrollPositionIntervals( const Dali::Vector<float>& positions )
342 mScrollPositionIntervals = positions;
344 Handle scrollableHandle = mScrollableObject.GetHandle();
346 if( scrollableHandle )
348 if( mPositionNotification )
350 scrollableHandle.RemovePropertyNotification(mPositionNotification);
353 mPositionNotification = scrollableHandle.AddPropertyNotification( mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals) );
354 mPositionNotification.NotifySignal().Connect( this, &ScrollBar::OnScrollPositionIntervalReached );
358 Dali::Vector<float> ScrollBar::GetScrollPositionIntervals() const
360 return mScrollPositionIntervals;
363 void ScrollBar::OnScrollPositionIntervalReached(PropertyNotification& source)
365 // Emit the signal to notify the scroll position crossing
366 Handle scrollableHandle = mScrollableObject.GetHandle();
369 mScrollPositionIntervalReachedSignal.Emit( scrollableHandle.GetCurrentProperty< float >( mPropertyScrollPosition ) );
373 void ScrollBar::ShowIndicator()
375 // Cancel any animation
382 if( mIndicatorFirstShow )
384 // Preserve the alpha value from the stylesheet
385 mIndicatorShowAlpha = Self().GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a;
386 mIndicatorFirstShow = false;
389 if(mIndicatorShowDuration > 0.0f)
391 mAnimation = Animation::New( mIndicatorShowDuration );
392 mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), mIndicatorShowAlpha, AlphaFunction::EASE_IN );
397 mIndicator.SetProperty( Actor::Property::OPACITY,mIndicatorShowAlpha);
401 void ScrollBar::HideIndicator()
403 // Cancel any animation
410 if(mIndicatorHideDuration > 0.0f)
412 mAnimation = Animation::New( mIndicatorHideDuration );
413 mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN );
418 mIndicator.SetProperty( Actor::Property::OPACITY,0.0f);
422 void ScrollBar::ShowTransientIndicator()
424 // Cancel any animation
431 mAnimation = Animation::New( mIndicatorShowDuration + mTransientIndicatorDuration + mIndicatorHideDuration );
432 if(mIndicatorShowDuration > 0.0f)
434 mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ),
435 mIndicatorShowAlpha, AlphaFunction::EASE_IN, TimePeriod(0, mIndicatorShowDuration) );
439 mIndicator.SetProperty( Actor::Property::OPACITY,mIndicatorShowAlpha);
441 mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ),
442 0.0f, AlphaFunction::EASE_IN, TimePeriod((mIndicatorShowDuration + mTransientIndicatorDuration), mIndicatorHideDuration) );
446 bool ScrollBar::OnPanGestureProcessTick()
448 // Update the scroll position property.
449 Handle scrollableHandle = mScrollableObject.GetHandle();
450 if( scrollableHandle )
452 scrollableHandle.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition);
458 void ScrollBar::OnPan( const PanGesture& gesture )
460 Handle scrollableHandle = mScrollableObject.GetHandle();
464 Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(scrollableHandle);
466 switch(gesture.GetState())
468 case Dali::GestureState::STARTED:
470 if( !mPanProcessTimer )
472 // Make sure the pan gesture is only being processed once per frame.
473 mPanProcessTimer = Timer::New( DEFAULT_PAN_GESTURE_PROCESS_TIME );
474 mPanProcessTimer.TickSignal().Connect( this, &ScrollBar::OnPanGestureProcessTick );
475 mPanProcessTimer.Start();
479 mScrollStart = scrollableHandle.GetCurrentProperty< float >( mPropertyScrollPosition );
480 mGestureDisplacement = Vector2::ZERO;
485 case Dali::GestureState::CONTINUING:
487 mGestureDisplacement += gesture.GetDisplacement();
489 float minScrollPosition = scrollableHandle.GetCurrentProperty<float>( mPropertyMinScrollPosition );
490 float maxScrollPosition = scrollableHandle.GetCurrentProperty<float>( mPropertyMaxScrollPosition );
492 // The domain size is the internal range
493 float domainSize = maxScrollPosition - minScrollPosition;
494 float logicalSize = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).y - ( mIndicator.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).y + mIndicatorStartPadding + mIndicatorEndPadding );
496 mCurrentScrollPosition = mScrollStart - ( ( mGestureDisplacement.y * domainSize ) / logicalSize );
497 mCurrentScrollPosition = -std::min( maxScrollPosition, std::max( -mCurrentScrollPosition, minScrollPosition ) );
505 if( mPanProcessTimer )
507 // Destroy the timer when pan gesture is finished.
508 mPanProcessTimer.Stop();
509 mPanProcessTimer.TickSignal().Disconnect( this, &ScrollBar::OnPanGestureProcessTick );
510 mPanProcessTimer.Reset();
515 // Refresh the ItemView cache with extra items
516 GetImpl(itemView).DoRefresh(mCurrentScrollPosition, true);
519 mPanFinishedSignal.Emit();
527 // Disable automatic refresh in ItemView during fast scrolling
528 GetImpl(itemView).SetRefreshEnabled(!mIsPanning);
533 void ScrollBar::OnSizeSet( const Vector3& size )
535 if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED)
537 mIndicator.SetProperty( Actor::Property::SIZE, Vector2( size.width, mIndicatorFixedHeight ) );
540 Control::OnSizeSet( size );
543 void ScrollBar::SetScrollDirection( Toolkit::ScrollBar::Direction direction )
545 mDirection = direction;
548 Toolkit::ScrollBar::Direction ScrollBar::GetScrollDirection() const
553 void ScrollBar::SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy )
555 if( policy != mIndicatorHeightPolicy )
557 mIndicatorHeightPolicy = policy;
562 Toolkit::ScrollBar::IndicatorHeightPolicy ScrollBar::GetIndicatorHeightPolicy() const
564 return mIndicatorHeightPolicy;
567 void ScrollBar::SetIndicatorFixedHeight( float height )
569 mIndicatorFixedHeight = height;
571 if(mIndicatorHeightPolicy == Toolkit::ScrollBar::FIXED)
573 mIndicator.SetProperty( Actor::Property::SIZE, Vector2( Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE ).width, mIndicatorFixedHeight) );
577 float ScrollBar::GetIndicatorFixedHeight() const
579 return mIndicatorFixedHeight;
582 void ScrollBar::SetIndicatorShowDuration( float durationSeconds )
584 mIndicatorShowDuration = durationSeconds;
587 float ScrollBar::GetIndicatorShowDuration() const
589 return mIndicatorShowDuration;
592 void ScrollBar::SetIndicatorHideDuration( float durationSeconds )
594 mIndicatorHideDuration = durationSeconds;
597 float ScrollBar::GetIndicatorHideDuration() const
599 return mIndicatorHideDuration;
602 void ScrollBar::OnScrollDirectionPropertySet( Property::Value propertyValue )
604 std::string directionName( propertyValue.Get<std::string>() );
605 if(directionName == "VERTICAL")
607 SetScrollDirection(Toolkit::ScrollBar::VERTICAL);
609 else if(directionName == "HORIZONTAL")
611 SetScrollDirection(Toolkit::ScrollBar::HORIZONTAL);
615 DALI_ASSERT_ALWAYS( !"ScrollBar::OnScrollDirectionPropertySet(). Invalid Property value." );
619 void ScrollBar::OnIndicatorHeightPolicyPropertySet( Property::Value propertyValue )
621 std::string policyName( propertyValue.Get<std::string>() );
622 if(policyName == "VARIABLE")
624 SetIndicatorHeightPolicy(Toolkit::ScrollBar::VARIABLE);
626 else if(policyName == "FIXED")
628 SetIndicatorHeightPolicy(Toolkit::ScrollBar::FIXED);
632 DALI_ASSERT_ALWAYS( !"ScrollBar::OnIndicatorHeightPolicyPropertySet(). Invalid Property value." );
636 bool ScrollBar::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
638 Dali::BaseHandle handle( object );
640 bool connected( true );
641 Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( handle );
643 if( 0 == strcmp( signalName.c_str(), PAN_FINISHED_SIGNAL ) )
645 scrollBar.PanFinishedSignal().Connect( tracker, functor );
647 else if( 0 == strcmp( signalName.c_str(), SCROLL_POSITION_INTERVAL_REACHED_SIGNAL ) )
649 scrollBar.ScrollPositionIntervalReachedSignal().Connect( tracker, functor );
653 // signalName does not match any signal
660 void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
662 Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) );
666 ScrollBar& scrollBarImpl( GetImpl( scrollBar ) );
669 case Toolkit::ScrollBar::Property::SCROLL_DIRECTION:
671 scrollBarImpl.OnScrollDirectionPropertySet( value );
674 case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY:
676 scrollBarImpl.OnIndicatorHeightPolicyPropertySet( value );
679 case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT:
681 scrollBarImpl.SetIndicatorFixedHeight(value.Get<float>());
684 case Toolkit::ScrollBar::Property::INDICATOR_SHOW_DURATION:
686 scrollBarImpl.SetIndicatorShowDuration(value.Get<float>());
689 case Toolkit::ScrollBar::Property::INDICATOR_HIDE_DURATION:
691 scrollBarImpl.SetIndicatorHideDuration(value.Get<float>());
694 case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS:
696 const Property::Array* array = value.GetArray();
699 Dali::Vector<float> positions;
700 size_t positionCount = array->Count();
701 positions.Resize( positionCount );
702 for( size_t i = 0; i != positionCount; ++i )
704 array->GetElementAt( i ).Get( positions[i] );
707 scrollBarImpl.SetScrollPositionIntervals(positions);
711 case Toolkit::ScrollBar::Property::INDICATOR_MINIMUM_HEIGHT:
713 scrollBarImpl.mIndicatorMinimumHeight = value.Get<float>();
714 scrollBarImpl.ApplyConstraints();
717 case Toolkit::ScrollBar::Property::INDICATOR_START_PADDING:
719 scrollBarImpl.mIndicatorStartPadding = value.Get<float>();
720 scrollBarImpl.ApplyConstraints();
723 case Toolkit::ScrollBar::Property::INDICATOR_END_PADDING:
725 scrollBarImpl.mIndicatorEndPadding = value.Get<float>();
726 scrollBarImpl.ApplyConstraints();
729 case Toolkit::ScrollBar::Property::INDICATOR_TRANSIENT_DURATION:
731 scrollBarImpl.mTransientIndicatorDuration = value.Get<float>();
738 Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index index )
740 Property::Value value;
742 Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) );
746 ScrollBar& scrollBarImpl( GetImpl( scrollBar ) );
749 case Toolkit::ScrollBar::Property::SCROLL_DIRECTION:
751 value = SCROLL_DIRECTION_NAME[ scrollBarImpl.GetScrollDirection() ];
754 case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY:
756 value = INDICATOR_HEIGHT_POLICY_NAME[ scrollBarImpl.GetIndicatorHeightPolicy() ];
759 case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT:
761 value = scrollBarImpl.GetIndicatorFixedHeight();
764 case Toolkit::ScrollBar::Property::INDICATOR_SHOW_DURATION:
766 value = scrollBarImpl.GetIndicatorShowDuration();
769 case Toolkit::ScrollBar::Property::INDICATOR_HIDE_DURATION:
771 value = scrollBarImpl.GetIndicatorHideDuration();
774 case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS:
776 Property::Value tempValue( Property::ARRAY );
777 Property::Array* array = tempValue.GetArray();
781 Dali::Vector<float> positions = scrollBarImpl.GetScrollPositionIntervals();
782 size_t positionCount( positions.Count() );
784 for( size_t i( 0 ); i != positionCount; ++i )
786 array->PushBack( positions[i] );
793 case Toolkit::ScrollBar::Property::INDICATOR_MINIMUM_HEIGHT:
795 value = scrollBarImpl.mIndicatorMinimumHeight;
798 case Toolkit::ScrollBar::Property::INDICATOR_START_PADDING:
800 value = scrollBarImpl.mIndicatorStartPadding;
803 case Toolkit::ScrollBar::Property::INDICATOR_END_PADDING:
805 value = scrollBarImpl.mIndicatorEndPadding;
808 case Toolkit::ScrollBar::Property::INDICATOR_TRANSIENT_DURATION:
810 value = scrollBarImpl.mTransientIndicatorDuration;
818 bool ScrollBar::DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes )
822 Dali::BaseHandle handle( object );
824 Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( handle );
826 DALI_ASSERT_DEBUG( scrollBar );
830 if( 0 == strcmp( actionName.c_str(), ACTION_SHOW_INDICATOR ) )
832 GetImpl( scrollBar ).ShowIndicator();
835 else if( 0 == strcmp( actionName.c_str(), ACTION_HIDE_INDICATOR ) )
837 GetImpl( scrollBar ).HideIndicator();
840 else if( 0 == strcmp( actionName.c_str(), ACTION_SHOW_TRANSIENT_INDICATOR ) )
842 GetImpl( scrollBar ).ShowTransientIndicator();
850 Toolkit::ScrollBar ScrollBar::New(Toolkit::ScrollBar::Direction direction)
852 // Create the implementation, temporarily owned by this handle on stack
853 IntrusivePtr< ScrollBar > impl = new ScrollBar(direction);
855 // Pass ownership to CustomActor handle
856 Toolkit::ScrollBar handle( *impl );
858 // Second-phase init of the implementation
859 // This can only be done after the CustomActor connection has been made...
865 double ScrollBar::AccessibleImpl::GetMinimum()
867 auto p = Toolkit::ScrollBar::DownCast( self );
868 Handle scrollableHandle = GetImpl( p ).mScrollableObject.GetHandle();
869 return scrollableHandle ? scrollableHandle.GetCurrentProperty< float >( GetImpl( p ).mPropertyMinScrollPosition ) : 0.0f;
872 double ScrollBar::AccessibleImpl::GetCurrent()
874 auto p = Toolkit::ScrollBar::DownCast( self );
875 Handle scrollableHandle = GetImpl( p ).mScrollableObject.GetHandle();
876 return scrollableHandle ? scrollableHandle.GetCurrentProperty< float >( GetImpl( p ).mPropertyScrollPosition ) : 0.0f;
879 double ScrollBar::AccessibleImpl::GetMaximum()
881 auto p = Toolkit::ScrollBar::DownCast( self );
882 Handle scrollableHandle = GetImpl( p ).mScrollableObject.GetHandle();
883 return scrollableHandle ? scrollableHandle.GetCurrentProperty< float >( GetImpl( p ).mPropertyMaxScrollPosition ) : 1.0f;
886 bool ScrollBar::AccessibleImpl::SetCurrent( double current )
888 if( current < GetMinimum() || current > GetMaximum() )
891 auto value_before = GetCurrent();
893 auto p = Toolkit::ScrollBar::DownCast( self );
894 Handle scrollableHandle = GetImpl( p ).mScrollableObject.GetHandle();
895 if( !scrollableHandle )
897 scrollableHandle.SetProperty( GetImpl( p ).mPropertyScrollPosition, static_cast< float >( current ) );
899 auto value_after = GetCurrent();
901 if( ( current != value_before ) && ( value_before == value_after ) )
907 double ScrollBar::AccessibleImpl::GetMinimumIncrement() { return 1.0; }
909 } // namespace Internal
911 } // namespace Toolkit