From 06e7c804d4e4461aa5e10609ff3769aae8ca9766 Mon Sep 17 00:00:00 2001 From: ali198724 Date: Sun, 18 Oct 2020 21:32:31 +0300 Subject: [PATCH] [dali-toolkit]: add texteditor scrolling functionality Add support for: 1- ScrollBy(Vector2) function: scroll texteditor by horizontal,vertical amount 2- HorizontalScroll property: get/set horizontal scroll position 3- VerticalScrolll property: get/set vertical scroll position Change-Id: I42afa6fc0b6ce5911d084d8499c0277e716a1149 --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 47 ++++++++++++++++++ .../controls/text-controls/text-editor-devel.cpp | 5 ++ .../controls/text-controls/text-editor-devel.h | 20 ++++++++ .../controls/text-controls/text-editor-impl.cpp | 58 ++++++++++++++++++++++ .../controls/text-controls/text-editor-impl.h | 19 +++++++ dali-toolkit/internal/text/text-controller.cpp | 50 +++++++++++++++++++ dali-toolkit/internal/text/text-controller.h | 15 ++++++ 7 files changed, 214 insertions(+) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 7a3ce4c..d511883 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -3036,3 +3036,50 @@ int UtcDaliTextEditorEnableEditing(void) END_TEST; } + +int UtcDaliTextEditorScrolling(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorScrolling "); + + TextEditor textEditor = TextEditor::New(); + DALI_TEST_CHECK( textEditor ); + + application.GetScene().Add( textEditor ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + application.SendNotification(); + application.Render(); + + textEditor.SetProperty(TextEditor::Property::TEXT, "Tex1\nTex2\nTex3\nTex4\nTex5\nTex6\nTex7\nTex8"); + textEditor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + textEditor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + textEditor.SetProperty(Actor::Property::SIZE, Vector2(60.0f, 160.0f)); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + + + DevelTextEditor::ScrollBy(textEditor, Vector2(1.0f, 1.0f)); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get(), 1.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + + DevelTextEditor::ScrollBy(textEditor, Vector2(0.0f, 1000.0f)); + + DALI_TEST_NOT_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get(), 1.0f, 0.1f, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + + textEditor.SetProperty(DevelTextEditor::Property::VERTICAL_SCROLL_POSITION , 0.0f); + textEditor.SetProperty(DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION , 0.0f); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp index adcff4c..abe3389 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp @@ -45,6 +45,11 @@ void SelectNone(TextEditor textEditor) GetImpl(textEditor).SelectNone(); } +void ScrollBy(TextEditor textEditor, Vector2 scroll) +{ + GetImpl(textEditor).ScrollBy(scroll); +} + } // namespace DevelTextEditor } // namespace Toolkit diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h index 0db66e5..6cb473c 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -140,6 +140,18 @@ enum Type SELECTED_TEXT_END, /** + * @brief The horizontal scroll position in pixels. + * @details Name "horizontalScrollPosition", type Property::FLOAT. + */ + HORIZONTAL_SCROLL_POSITION, + + /** + * @brief The vertical scroll position in pixels. + * @details Name "verticalScrollPosition", type Property::FLOAT. + */ + VERTICAL_SCROLL_POSITION, + + /** * @brief The Editable state of control. * @details Name "enableEditing", type Property::BOOLEAN. */ @@ -194,6 +206,14 @@ DALI_TOOLKIT_API void SelectWholeText(TextEditor textEditor); */ DALI_TOOLKIT_API void SelectNone(TextEditor textEditor); +/** + * @brief Scroll the TextEditor by specific amount. + * + * @param[in] textEditor The instance of TextEditor. + * @param[in] scroll amount (in pixels) of scrolling in horizontal & vectical directions. + */ +DALI_TOOLKIT_API void ScrollBy(TextEditor textEditor, Vector2 scroll); + } // namespace DevelTextEditor } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index 60db674..75f6d6f 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -142,6 +142,8 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "maxLength", INTEGER, MAX_LENGTH ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectedTextStart", INTEGER, SELECTED_TEXT_START ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectedTextEnd", INTEGER, SELECTED_TEXT_END ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalScrollPosition", FLOAT, HORIZONTAL_SCROLL_POSITION ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "verticalScrollPosition", INTEGER, VERTICAL_SCROLL_POSITION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableEditing", BOOLEAN, ENABLE_EDITING ) DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT ) @@ -721,6 +723,26 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P impl.SetEditable( editable ); break; } + case Toolkit::DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION: + { + float horizontalScroll = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_SCROLL_POSITION %d\n", impl.mController.Get(), horizontalScroll ); + if (horizontalScroll >= 0.0f) + { + impl.ScrollBy( Vector2(horizontalScroll - impl.GetHorizontalScrollPosition(), 0 )); + } + break; + } + case Toolkit::DevelTextEditor::Property::VERTICAL_SCROLL_POSITION: + { + float verticalScroll = value.Get< float >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p VERTICAL_SCROLL_POSITION %d\n", impl.mController.Get(), verticalScroll ); + if (verticalScroll >= 0.0f) + { + impl.ScrollBy( Vector2(0, verticalScroll - impl.GetVerticalScrollPosition() )); + } + break; + } } // switch } // texteditor } @@ -1057,6 +1079,16 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind value = impl.IsEditable(); break; } + case Toolkit::DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION: + { + value = impl.GetHorizontalScrollPosition(); + break; + } + case Toolkit::DevelTextEditor::Property::VERTICAL_SCROLL_POSITION: + { + value = impl.GetVerticalScrollPosition(); + break; + } } //switch } @@ -1080,6 +1112,32 @@ void TextEditor::SelectNone() } } +void TextEditor::ScrollBy(Vector2 scroll) +{ + if( mController && mController->IsShowingRealText() ) + { + mController->ScrollBy(scroll); + } +} + +float TextEditor::GetHorizontalScrollPosition() +{ + if( mController && mController->IsShowingRealText() ) + { + return mController->GetHorizontalScrollPosition(); + } + return 0; +} + +float TextEditor::GetVerticalScrollPosition() +{ + if( mController && mController->IsShowingRealText() ) + { + return mController->GetVerticalScrollPosition(); + } + return 0; +} + string TextEditor::GetSelectedText() const { string selectedText = ""; diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h index 2aca941..0cb7204 100755 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -226,6 +226,25 @@ public: void SelectNone() override; /** + * @copydoc Dali::Toolkit::DevelTextEditor::ScrollBy() + */ + void ScrollBy(Vector2 Scroll); + + /** + * @brief Get Horizontal scroll position of TextEditor. + * + * @return Horizontal scroll position (in pixels) of TextEditor. + */ + float GetHorizontalScrollPosition(); + + /** + * @brief Get Vertical scroll position of TextEditor. + * + * @return Vertical scroll position (in pixels) of TextEditor. + */ + float GetVerticalScrollPosition(); + + /** * @copydoc Text::SelectableControlInterface::GetSelectedText() */ string GetSelectedText() const override; diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 31c1edf..6fe0d0c 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -2239,6 +2239,56 @@ void Controller::SetEditable( bool editable ) } } +void Controller::ScrollBy( Vector2 scroll ) +{ + if( mImpl->mEventData && (fabs(scroll.x) > Math::MACHINE_EPSILON_0 || fabs(scroll.y) > Math::MACHINE_EPSILON_0)) + { + const Vector2& layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize(); + const Vector2 currentScroll = mImpl->mModel->mScrollPosition; + + scroll.x = -scroll.x; + scroll.y = -scroll.y; + + if( fabs(scroll.x) > Math::MACHINE_EPSILON_0 ) + { + mImpl->mModel->mScrollPosition.x += scroll.x; + mImpl->ClampHorizontalScroll( layoutSize ); + } + + if( fabs(scroll.y) > Math::MACHINE_EPSILON_0 ) + { + mImpl->mModel->mScrollPosition.y += scroll.y; + mImpl->ClampVerticalScroll( layoutSize ); + } + + if (mImpl->mModel->mScrollPosition != currentScroll) + { + mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - currentScroll ); + mImpl->RequestRelayout(); + } + } +} + +float Controller::GetHorizontalScrollPosition() +{ + if( mImpl->mEventData ) + { + //scroll values are negative internally so we convert them to positive numbers + return -mImpl->mModel->mScrollPosition.x; + } + return 0; +} + +float Controller::GetVerticalScrollPosition() +{ + if( mImpl->mEventData ) + { + //scroll values are negative internally so we convert them to positive numbers + return -mImpl->mModel->mScrollPosition.y; + } + return 0; +} + void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y ) { EventHandler::DecorationEvent(*this, handleType, state, x, y); diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 54444b1..6bd8706 100755 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -1531,6 +1531,21 @@ public: // Text-input Event Queuing. virtual void SetEditable( bool editable ); /** + * @copydoc Dali::Toolkit::Internal::TextEditor::ScrollBy() + */ + virtual void ScrollBy( Vector2 scroll ); + + /** + * @copydoc Dali::Toolkit::Internal::TextEditor::GetHorizontalScrollPosition() + */ + float GetHorizontalScrollPosition(); + + /** + * @copydoc Dali::Toolkit::Internal::TextEditor::GetVerticalScrollPosition() + */ + float GetVerticalScrollPosition(); + + /** * @brief Event received from input method context * * @param[in] inputMethodContext The input method context. -- 2.7.4