Fix scroll bar issue for TBT testing 81/120681/6
authorRichard Huang <r.huang@samsung.com>
Thu, 23 Mar 2017 19:08:43 +0000 (19:08 +0000)
committerRichard Huang <r.huang@samsung.com>
Fri, 24 Mar 2017 14:54:57 +0000 (14:54 +0000)
1. Fixed the scroll bar visibility isue
2. Increased scroll indicator size and duration to hide indicator to make it easier to grab
3. Fixed orientation of scroll bar to match its direction

Change-Id: I98d7d79ed7f83eec5733e8566ea10708e0f9768b

dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.cpp
dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.h
dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.cpp
dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h
dali-toolkit/styles/images-common/popup_scroll.9.png [changed mode: 0644->0755]

index 5a4beea..7073754 100755 (executable)
@@ -220,6 +220,7 @@ void ScrollBar::OnInitialize()
 {
   CreateDefaultIndicatorActor();
   Self().SetDrawMode(DrawMode::OVERLAY_2D);
+  SetScrollDirection(mDirection);
 }
 
 void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize )
@@ -538,9 +539,63 @@ void ScrollBar::OnSizeSet( const Vector3& size )
   }
 }
 
+void ScrollBar::OnStageConnection( int depth )
+{
+  Actor parent = Self().GetParent();
+  if (parent && mDirection == Toolkit::ScrollBar::Horizontal)
+  {
+    parent.OnRelayoutSignal().Connect( this, &ScrollBar::OnParentRelayout );
+  }
+
+  Control::OnStageConnection( depth );
+}
+
+void ScrollBar::OnStageDisconnection()
+{
+  Actor parent = Self().GetParent();
+  if (parent && mDirection == Toolkit::ScrollBar::Horizontal)
+  {
+    parent.OnRelayoutSignal().Disconnect( this, &ScrollBar::OnParentRelayout );
+  }
+
+  Control::OnStageDisconnection();
+}
+
+void ScrollBar::OnParentRelayout(Actor actor)
+{
+  // Make the height of the horizontal scroll bar to be the same as the width of its parent.
+  // The parent size only set during relayout.
+  Self().SetSize(Vector2(0.0f, actor.GetRelayoutSize( Dimension::WIDTH) ));
+}
+
 void ScrollBar::SetScrollDirection( Toolkit::ScrollBar::Direction direction )
 {
   mDirection = direction;
+
+  Actor self = Self();
+
+  if(mDirection == Toolkit::ScrollBar::Horizontal)
+  {
+    // Rotate the scroll bar and align it to the bottom of its parent
+    self.SetParentOrigin(ParentOrigin::BOTTOM_LEFT);
+    self.SetAnchorPoint(AnchorPoint::TOP_LEFT);
+    self.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::WIDTH);
+    self.SetOrientation(Quaternion(Radian( 1.5f * Math::PI ), Vector3::ZAXIS));
+
+    Actor parent = self.GetParent();
+    if (parent && mDirection == Toolkit::ScrollBar::Horizontal)
+    {
+      parent.OnRelayoutSignal().Connect( this, &ScrollBar::OnParentRelayout );
+    }
+  }
+  else
+  {
+    // Align the scroll bar to the right of its parent
+    self.SetParentOrigin(ParentOrigin::TOP_RIGHT);
+    self.SetAnchorPoint(AnchorPoint::TOP_RIGHT);
+    self.SetResizePolicy(Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::HEIGHT);
+    self.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::WIDTH);
+  }
 }
 
 Toolkit::ScrollBar::Direction ScrollBar::GetScrollDirection() const
index da398b6..7f0bd18 100755 (executable)
@@ -215,6 +215,16 @@ private: // from Control
    */
   virtual void OnSizeSet( const Vector3& size );
 
+  /**
+   * @copydoc CustomActorImpl::OnStageConnection()
+   */
+  virtual void OnStageConnection( int depth );
+
+  /**
+   * @copydoc CustomActorImpl::OnStageDisconnection()
+   */
+  virtual void OnStageDisconnection();
+
 private:
 
   /**
@@ -253,6 +263,12 @@ private:
    */
   void OnIndicatorHeightPolicyPropertySet(Property::Value propertyValue);
 
+  /**
+   * Callback when the size has been set on the parent during relayout
+   * @param[in] actor The actor that has been relaid out.
+   */
+  void OnParentRelayout(Actor actor);
+
 private:
 
   /**
index c953947..82fc206 100644 (file)
@@ -1184,12 +1184,9 @@ void ScrollView::SetTransientScrollBar( bool transient )
   {
     mTransientScrollBar = transient;
 
-    Toolkit::ScrollBar scrollBar = mScrollBar.GetHandle();
-    if( mTransientScrollBar && scrollBar )
+    if( mTransientScrollBar )
     {
-      // Show the scroll-indicator for a brief period
-      scrollBar.SetVisible( true );
-      GetImpl(scrollBar).ShowTransientIndicator();
+      ShowScrollIndicator(true);
     }
   }
 }
@@ -1783,6 +1780,9 @@ bool ScrollView::AnimateTo(const Vector2& position, const Vector2& positionDurat
   DALI_LOG_SCROLL_STATE("[0x%X] mSnapStartedSignal [%.2f, %.2f]", this, snapEvent.position.x, snapEvent.position.y);
   mSnapStartedSignal.Emit( snapEvent );
 
+  // Make indicator visible during scrolling
+  ShowScrollIndicator(false);
+
   return (mScrollStateFlags & SCROLL_ANIMATION_FLAGS) != 0;
 }
 
@@ -1905,6 +1905,11 @@ void ScrollView::HandleSnapAnimationFinished()
   mDomainOffset += deltaPosition - mScrollPostPosition;
   self.SetProperty(Toolkit::ScrollView::Property::SCROLL_DOMAIN_OFFSET, mDomainOffset);
   HandleStoppedAnimation();
+
+  if( mTransientScrollBar )
+  {
+    HideScrollIndicator();
+  }
 }
 
 void ScrollView::SetScrollUpdateNotification( bool enabled )
@@ -2000,12 +2005,12 @@ void ScrollView::OnChildAdd(Actor& child)
   Dali::Toolkit::ScrollBar scrollBar = Dali::Toolkit::ScrollBar::DownCast(child);
   if( scrollBar )
   {
-    mScrollBar = scrollBar;
     scrollBar.SetName("ScrollBar");
 
     mInternalActor.Add( scrollBar );
     if( scrollBar.GetScrollDirection() == Toolkit::ScrollBar::Horizontal )
     {
+      mHorizontalScrollBar = scrollBar;
       scrollBar.SetScrollPropertySource( Self(),
                                          Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_X,
                                          Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_X,
@@ -2014,6 +2019,7 @@ void ScrollView::OnChildAdd(Actor& child)
     }
     else
     {
+      mVerticalScrollBar = scrollBar;
       scrollBar.SetScrollPropertySource( Self(),
                                          Toolkit::ScrollView::Property::SCROLL_PRE_POSITION_Y,
                                          Toolkit::Scrollable::Property::SCROLL_POSITION_MIN_Y,
@@ -2028,7 +2034,7 @@ void ScrollView::OnChildAdd(Actor& child)
     }
     else
     {
-      scrollBar.SetVisible( false );
+      scrollBar.SetVisible(false);
       scrollBar.HideIndicator();
     }
   }
@@ -2528,19 +2534,10 @@ void ScrollView::OnPan( const PanGesture& gesture )
       self.SetProperty( Toolkit::ScrollView::Property::START_PAGE_POSITION, Vector3(gesture.position.x, gesture.position.y, 0.0f) );
 
       UpdateMainInternalConstraint();
-      Toolkit::ScrollBar scrollBar = mScrollBar.GetHandle();
-      if( scrollBar && mTransientScrollBar )
-      {
-        Vector3 size = Self().GetCurrentSize();
-        const Toolkit::RulerDomain& rulerDomainX = mRulerX->GetDomain();
-        const Toolkit::RulerDomain& rulerDomainY = mRulerY->GetDomain();
 
-        if( ( rulerDomainX.max > size.width ) || ( rulerDomainY.max > size.height ) )
-        {
-          scrollBar.SetVisible( true );
-          scrollBar.ShowIndicator();
-        }
-      }
+      // Make scroll indicator visible as soon as the panning starts
+      ShowScrollIndicator(false);
+
       break;
     }
 
@@ -2575,12 +2572,6 @@ void ScrollView::OnPan( const PanGesture& gesture )
         {
           mScrollMainInternalPrePositionConstraint.Remove();
         }
-
-        Toolkit::ScrollBar scrollBar = mScrollBar.GetHandle();
-        if( scrollBar && mTransientScrollBar )
-        {
-          scrollBar.HideIndicator();
-        }
       }
       else
       {
@@ -2940,6 +2931,64 @@ bool ScrollView::IsPanningOrScrolling() const
   return panningOrScrolling;
 }
 
+void ScrollView::ShowScrollIndicator(bool transient)
+{
+  Vector3 scrollViewSize = Self().GetCurrentSize();
+
+  Toolkit::ScrollBar scrollBar = mHorizontalScrollBar.GetHandle();
+  if( scrollBar)
+  {
+    const Toolkit::RulerDomain& rulerDomainX = mRulerX->GetDomain();
+
+    if( rulerDomainX.max > scrollViewSize.width )
+    {
+      scrollBar.SetVisible(true);
+      if( transient )
+      {
+        GetImpl(scrollBar).ShowTransientIndicator();
+      }
+      else
+      {
+        scrollBar.ShowIndicator();
+      }
+    }
+  }
+
+  scrollBar = mVerticalScrollBar.GetHandle();
+  if( scrollBar)
+  {
+    const Toolkit::RulerDomain& rulerDomainY = mRulerY->GetDomain();
+
+    if( rulerDomainY.max > scrollViewSize.height )
+    {
+      scrollBar.SetVisible(true);
+      if( transient )
+      {
+        GetImpl(scrollBar).ShowTransientIndicator();
+      }
+      else
+      {
+        scrollBar.ShowIndicator();
+      }
+    }
+  }
+}
+
+void ScrollView::HideScrollIndicator()
+{
+  Toolkit::ScrollBar scrollBar = mHorizontalScrollBar.GetHandle();
+  if( scrollBar )
+  {
+    scrollBar.HideIndicator();
+  }
+
+  scrollBar = mVerticalScrollBar.GetHandle();
+  if( scrollBar )
+  {
+    scrollBar.HideIndicator();
+  }
+}
+
 void ScrollView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
 {
   Toolkit::ScrollView scrollView = Toolkit::ScrollView::DownCast( Dali::BaseHandle( object ) );
index d2abd05..9268e58 100644 (file)
@@ -813,6 +813,18 @@ private:
    */
   bool IsPanningOrScrolling() const;
 
+  /**
+   * @brief Make scroll indicator visible.
+   *
+   * @param[in] transient True if scroll-bar should be automatically show/hidden during/after panning
+   */
+  void ShowScrollIndicator(bool transient);
+
+  /**
+   * @brief Make scroll indicator invisible.
+   */
+  void HideScrollIndicator();
+
 protected:
 
   /**
@@ -953,7 +965,8 @@ private:
   Constraint mScrollMainInternalPrePositionMaxConstraint;
 
   ScrollOvershootIndicatorPtr mOvershootIndicator;
-  WeakHandle<Toolkit::ScrollBar> mScrollBar;
+  WeakHandle<Toolkit::ScrollBar> mHorizontalScrollBar;
+  WeakHandle<Toolkit::ScrollBar> mVerticalScrollBar;
 
   Toolkit::ScrollView::SnapStartedSignalType mSnapStartedSignal;
 
old mode 100644 (file)
new mode 100755 (executable)
index 2ffc3a7..3738eb2
Binary files a/dali-toolkit/styles/images-common/popup_scroll.9.png and b/dali-toolkit/styles/images-common/popup_scroll.9.png differ