Text Selection Toolbar scrolling 64/41464/8
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Mon, 15 Jun 2015 15:55:53 +0000 (16:55 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Fri, 19 Jun 2015 16:09:11 +0000 (09:09 -0700)
Change-Id: I490f640f66c43ed98f8005e2e87f891cd77ceb90
Signed-off-by: Agnelo Vaz <agnelo.vaz@samsung.com>
dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.cpp
dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h

index 3ff40b3..cb1e205 100644 (file)
@@ -26,8 +26,6 @@
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/math/vector4.h>
 #include <dali/devel-api/object/type-registry-helper.h>
-#include <iostream>
-#include <libintl.h>
 #include <cfloat>
 
 namespace Dali
@@ -120,6 +118,13 @@ void TextSelectionToolbar::OnInitialize()
   SetUp();
 }
 
+void TextSelectionToolbar::OnRelayout( const Vector2& size, RelayoutContainer& container )
+{
+  float width = std::max ( mTableOfButtons.GetNaturalSize().width, size.width );
+  mRulerX->SetDomain( RulerDomain( 0.0, width, true ) );
+  mScrollView.SetRulerX( mRulerX );
+}
+
 void TextSelectionToolbar::SetPopupMaxSize( const Size& maxSize )
 {
   mMaxSize = maxSize;
@@ -130,16 +135,35 @@ const Dali::Vector2& TextSelectionToolbar::GetPopupMaxSize() const
   return mMaxSize;
 }
 
+void TextSelectionToolbar::SetUpScrollView( Toolkit::ScrollView& scrollView )
+{
+  scrollView.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
+  scrollView.SetParentOrigin( ParentOrigin::CENTER_LEFT );
+  scrollView.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
+  scrollView.SetMaximumSize( mMaxSize );
+
+  scrollView.SetScrollingDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 40.0f ) );
+  scrollView.SetAxisAutoLock( true );
+  scrollView.ScrollStartedSignal().Connect( this, &TextSelectionToolbar::OnScrollStarted );
+  scrollView.ScrollCompletedSignal().Connect( this, &TextSelectionToolbar::OnScrollCompleted );
+
+  mRulerX = new DefaultRuler();  // IntrusivePtr which is unreferenced when ScrollView is destroyed.
+
+  RulerPtr rulerY = new DefaultRuler();  // IntrusivePtr which is unreferenced when ScrollView is destroyed.
+  rulerY->Disable();
+  scrollView.SetRulerY( rulerY );
+}
+
 void TextSelectionToolbar::SetUp()
 {
   Actor self = Self();
   self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
 
-  // Create Layer and Stencil.
-  mStencilLayer = Layer::New();
-  mStencilLayer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
-  mStencilLayer.SetParentOrigin( ParentOrigin::CENTER );
-  mStencilLayer.SetMaximumSize( mMaxSize );
+  // Create Layer and Stencil.  Layer enable's clipping when content exceed maximum defined width.
+  Layer stencilLayer = Layer::New();
+  stencilLayer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
+  stencilLayer.SetParentOrigin( ParentOrigin::CENTER );
+  stencilLayer.SetMaximumSize( mMaxSize );
 
   ImageActor stencil = CreateSolidColorActor( Color::RED );
   stencil.SetDrawMode( DrawMode::STENCIL );
@@ -147,21 +171,32 @@ void TextSelectionToolbar::SetUp()
   stencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
   stencil.SetParentOrigin( ParentOrigin::CENTER );
 
-  Actor scrollview = Actor::New(); //todo make a scrollview
-  scrollview.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
-  scrollview.SetParentOrigin( ParentOrigin::CENTER );
+  mScrollView  = Toolkit::ScrollView::New();
+  SetUpScrollView( mScrollView );
 
-  // Toolbar needs at least one option, adding further options with increase it's size
+  // Toolbar must start with at least one option, adding further options with increase it's size
   mTableOfButtons = Dali::Toolkit::TableView::New( 1, 1 );
   mTableOfButtons.SetFitHeight( 0 );
-  mTableOfButtons.SetParentOrigin( ParentOrigin::CENTER );
+  mTableOfButtons.SetParentOrigin( ParentOrigin::CENTER_LEFT );
+  mTableOfButtons.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
+
+
+  stencilLayer.Add( stencil );
+  stencilLayer.Add( mScrollView );
+  mScrollView.Add( mTableOfButtons );
+  self.Add( stencilLayer );
+
+  stencilLayer.RaiseToTop();
+}
 
-  mStencilLayer.Add( stencil );
-  mStencilLayer.Add( scrollview );
-  scrollview.Add( mTableOfButtons );
-  self.Add( mStencilLayer );
+void TextSelectionToolbar::OnScrollStarted( const Vector2& position )
+{
+  mTableOfButtons.SetSensitive( false );
+}
 
-  mStencilLayer.RaiseToTop();
+void TextSelectionToolbar::OnScrollCompleted( const Vector2& position )
+{
+  mTableOfButtons.SetSensitive( true );
 }
 
 void TextSelectionToolbar::AddOption( Actor& option )
@@ -197,6 +232,7 @@ TextSelectionToolbar::TextSelectionToolbar()
 
 TextSelectionToolbar::~TextSelectionToolbar()
 {
+  mRulerX.Reset();
 }
 
 
index fb85e95..3593e79 100644 (file)
@@ -20,6 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
 #include <dali-toolkit/public-api/controls/table-view/table-view.h>
 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-toolbar.h>
 
@@ -88,9 +89,13 @@ private: // From Control
   /**
    * @copydoc Control::OnInitialize()
    */
- virtual void OnInitialize();
 virtual void OnInitialize();
 
   /**
+  * @copydoc Control::OnRelayout()
+  */
+  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
+  /**
    * @brief Set max size of Popup
    * @param[in] maxSize Size (Vector2)
    */
@@ -103,10 +108,28 @@ private: // From Control
   const Dali::Vector2& GetPopupMaxSize() const;
 
   /**
+   * @brief Set up scrollview to scroll Toolbar horizontally
+   * @param[out] scrollView scrollview to setup
+   */
+  void SetUpScrollView( Toolkit::ScrollView& scrollView );
+
+  /**
    * @brief Set up the parts that make the Toolbar
    */
   void SetUp();
 
+  /**
+   * Toolbar has started to scroll
+   * @param[in] position current scroll view position
+   */
+  void OnScrollStarted( const Vector2& position );
+
+  /**
+   * Toolbar has stopped scrolling
+   * @param[in] position current scroll view position
+   */
+  void OnScrollCompleted( const Vector2& position );
+
 private: // Implementation
 
   /**
@@ -127,9 +150,9 @@ private:
 
 private: // Data
 
-  Dali::Toolkit::TableView mTableOfButtons;           // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
-  Layer mStencilLayer;                                // Layer to enable clipping when buttons exceed popup
-
+  Toolkit::TableView mTableOfButtons;                 // Actor which holds all the buttons, sensitivity can be set on buttons via this actor
+  Toolkit::ScrollView mScrollView;                    // Provides scrolling of Toolbar when content does not fit.
+  RulerPtr mRulerX;                                   // Ruler to clamp horizontal scrolling. Updates on Relayout
   Size mMaxSize;                                      // Max size of the Toolbar
   unsigned int mIndexInTable;                         // Index in table to add option
   Dali::Vector< unsigned int > mDividerIndexes;       // Vector of indexes in the Toolbar that contain dividers.