+void TextEditor::UpdateScrollBar()
+{
+ using namespace Dali;
+
+ float scrollPosition;
+ float controlSize;
+ float layoutSize;
+ bool latestScrolled;
+
+ if ( !mScrollBarEnabled )
+ {
+ return;
+ }
+ latestScrolled = mController->GetTextScrollInfo( scrollPosition, controlSize, layoutSize );
+ if ( !latestScrolled || controlSize > layoutSize)
+ {
+ return;
+ }
+
+ CustomActor self = Self();
+ if( !mScrollBar )
+ {
+ mScrollBar = Toolkit::ScrollBar::New( Toolkit::ScrollBar::Vertical );
+ mScrollBar.SetIndicatorHeightPolicy( Toolkit::ScrollBar::Variable );
+ mScrollBar.SetParentOrigin( ParentOrigin::TOP_RIGHT );
+ mScrollBar.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
+ mScrollBar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
+ mScrollBar.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH );
+
+ // Register the scroll position property
+ Property::Index propertyScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION, scrollPosition );
+ // Register the minimum scroll position property
+ Property::Index propertyMinScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION_MIN, 0.0f );
+ // Register the maximum scroll position property
+ Property::Index propertyMaxScrollPosition = self.RegisterProperty( SCROLL_BAR_POSITION_MAX, (layoutSize - controlSize) );
+ // Register the scroll content size property
+ Property::Index propertyScrollContentSize = self.RegisterProperty( SCROLL_BAR_CONTENT_SIZE, layoutSize );
+
+ mScrollBar.SetScrollPropertySource(self, propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
+
+ // Set style name of ScrollBar for styling
+ mScrollBar.SetStyleName("TextEditorScrollBar");
+ Toolkit::Control scrollIndicator = Toolkit::Control::DownCast( mScrollBar.GetScrollIndicator() );
+ if( scrollIndicator )
+ {
+ // Set style name of ScrollBarIndicator for styling
+ scrollIndicator.SetStyleName("TextEditorScrollBarIndicator");
+ }
+
+ self.Add( mScrollBar );
+ }
+ else
+ {
+ Property::Index propertyScrollPosition = self.GetPropertyIndex( SCROLL_BAR_POSITION );
+ Property::Index propertyMaxScrollPosition = self.GetPropertyIndex( SCROLL_BAR_POSITION_MAX );
+ Property::Index propertyScrollContentSize = self.GetPropertyIndex( SCROLL_BAR_CONTENT_SIZE );
+
+ self.SetProperty( propertyScrollPosition, scrollPosition );
+ self.SetProperty( propertyMaxScrollPosition, (layoutSize - controlSize) );
+ self.SetProperty( propertyScrollContentSize, layoutSize );
+ }
+
+ // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
+ if( !mScrollStarted )
+ {
+ mScrollStarted = true;
+ Dali::Toolkit::TextEditor handle( GetOwner() );
+ mScrollStateChangedSignal.Emit( handle, DevelTextEditor::Scroll::STARTED );
+ }
+
+ Actor indicator = mScrollBar.GetScrollIndicator();
+ if( mAnimation )
+ {
+ mAnimation.Stop(); // Cancel any animation
+ }
+ else
+ {
+ mAnimation = Animation::New( mAnimationPeriod.durationSeconds );
+ }
+ indicator.SetOpacity(1.0f);
+ mAnimation.AnimateTo( Property( indicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod );
+ mAnimation.Play();
+ mAnimation.FinishedSignal().Connect( this, &TextEditor::OnScrollIndicatorAnimationFinished );
+}
+
+void TextEditor::OnScrollIndicatorAnimationFinished( Animation& animation )
+{
+ // If animation is successfully ended, then emit ScrollStateChangedSignal
+ if( animation.GetCurrentProgress() == 0.0f )
+ {
+ mScrollStarted = false;
+ Dali::Toolkit::TextEditor handle( GetOwner() );
+ mScrollStateChangedSignal.Emit( handle, DevelTextEditor::Scroll::FINISHED );
+ }
+}
+