Fix scroll bar issue for TBT testing
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scroll-bar / scroll-bar-impl.cpp
index 85ff34e..7073754 100755 (executable)
@@ -46,6 +46,17 @@ const float DEFAULT_INDICATOR_FIXED_HEIGHT(80.0f);
 const float DEFAULT_INDICATOR_MINIMUM_HEIGHT(0.0f);
 const float DEFAULT_INDICATOR_START_PADDING(0.0f);
 const float DEFAULT_INDICATOR_END_PADDING(0.0f);
+const float DEFAULT_INDICATOR_TRANSIENT_DURATION(1.0f);
+
+// The following properties are not in the public-api yet.
+enum
+{
+  /**
+   * @brief The duration that transient indicators will remain fully visible.
+   * @details name "indicatorTransientDuration", type float.
+   */
+  INDICATOR_TRANSIENT_DURATION = Toolkit::ScrollBar::Property::INDICATOR_END_PADDING + 1
+};
 
 /**
  * Indicator size constraint
@@ -154,15 +165,18 @@ BaseHandle Create()
 // Setup properties, signals and actions using the type-registry.
 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ScrollBar, Toolkit::Control, Create );
 
-DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollDirection",                   STRING, SCROLL_DIRECTION          )
-DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHeightPolicy",             STRING, INDICATOR_HEIGHT_POLICY   )
-DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorFixedHeight",              FLOAT,  INDICATOR_FIXED_HEIGHT    )
-DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorShowDuration",             FLOAT,  INDICATOR_SHOW_DURATION   )
-DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHideDuration",             FLOAT,  INDICATOR_HIDE_DURATION   )
-DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervals",           ARRAY,  SCROLL_POSITION_INTERVALS )
-DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorMinimumHeight",            FLOAT,  INDICATOR_MINIMUM_HEIGHT  )
-DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorStartPadding",             FLOAT,  INDICATOR_START_PADDING   )
-DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorEndPadding",               FLOAT,  INDICATOR_END_PADDING     )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollDirection",                   STRING, SCROLL_DIRECTION             )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHeightPolicy",             STRING, INDICATOR_HEIGHT_POLICY      )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorFixedHeight",              FLOAT,  INDICATOR_FIXED_HEIGHT       )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorShowDuration",             FLOAT,  INDICATOR_SHOW_DURATION      )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHideDuration",             FLOAT,  INDICATOR_HIDE_DURATION      )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervals",           ARRAY,  SCROLL_POSITION_INTERVALS    )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorMinimumHeight",            FLOAT,  INDICATOR_MINIMUM_HEIGHT     )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorStartPadding",             FLOAT,  INDICATOR_START_PADDING      )
+DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorEndPadding",               FLOAT,  INDICATOR_END_PADDING        )
+
+Dali::PropertyRegistration manualProperty1( typeRegistration, "indicatorTransientDuration", INDICATOR_TRANSIENT_DURATION,
+    Property::FLOAT, Dali::Toolkit::Internal::ScrollBar::SetProperty, Dali::Toolkit::Internal::ScrollBar::GetProperty );
 
 DALI_SIGNAL_REGISTRATION(   Toolkit, ScrollBar, "panFinished",                       PAN_FINISHED_SIGNAL )
 DALI_SIGNAL_REGISTRATION(   Toolkit, ScrollBar, "scrollPositionIntervalReached",     SCROLL_POSITION_INTERVAL_REACHED_SIGNAL )
@@ -175,7 +189,7 @@ const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"Variable", "Fixed"};
 }
 
 ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction)
-: Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
   mIndicatorShowAlpha(1.0f),
   mDirection(direction),
   mScrollableObject(WeakHandleBase()),
@@ -185,6 +199,7 @@ ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction)
   mPropertyScrollContentSize(Property::INVALID_INDEX),
   mIndicatorShowDuration(DEFAULT_INDICATOR_SHOW_DURATION),
   mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION),
+  mTransientIndicatorDuration(DEFAULT_INDICATOR_TRANSIENT_DURATION),
   mScrollStart(0.0f),
   mCurrentScrollPosition(0.0f),
   mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable),
@@ -205,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 )
@@ -234,7 +250,8 @@ void ScrollBar::CreateDefaultIndicatorActor()
   Toolkit::ImageView indicator = Toolkit::ImageView::New( DEFAULT_INDICATOR_IMAGE_PATH );
   indicator.SetParentOrigin( ParentOrigin::TOP_LEFT );
   indicator.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-
+  indicator.SetStyleName( "ScrollBarIndicator" );
+  indicator.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
   SetScrollIndicator(indicator);
 }
 
@@ -402,6 +419,30 @@ void ScrollBar::HideIndicator()
   }
 }
 
+void ScrollBar::ShowTransientIndicator()
+{
+  // Cancel any animation
+  if(mAnimation)
+  {
+    mAnimation.Clear();
+    mAnimation.Reset();
+  }
+
+  mAnimation = Animation::New( mIndicatorShowDuration + mTransientIndicatorDuration + mIndicatorHideDuration );
+  if(mIndicatorShowDuration > 0.0f)
+  {
+    mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ),
+                          mIndicatorShowAlpha, AlphaFunction::EASE_IN, TimePeriod(0, mIndicatorShowDuration) );
+  }
+  else
+  {
+    mIndicator.SetOpacity(mIndicatorShowAlpha);
+  }
+  mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ),
+                        0.0f, AlphaFunction::EASE_IN, TimePeriod((mIndicatorShowDuration + mTransientIndicatorDuration), mIndicatorHideDuration) );
+  mAnimation.Play();
+}
+
 bool ScrollBar::OnPanGestureProcessTick()
 {
   // Update the scroll position property.
@@ -498,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
@@ -684,6 +779,11 @@ void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Pr
         scrollBarImpl.ApplyConstraints();
         break;
       }
+      case INDICATOR_TRANSIENT_DURATION:
+      {
+        scrollBarImpl.mTransientIndicatorDuration = value.Get<float>();
+        break;
+      }
     }
   }
 }
@@ -755,6 +855,11 @@ Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index inde
         value = scrollBarImpl.mIndicatorEndPadding;
         break;
       }
+      case INDICATOR_TRANSIENT_DURATION:
+      {
+        value = scrollBarImpl.mTransientIndicatorDuration;
+        break;
+      }
     }
   }
   return value;