From 0be39f538a909485d8d30e02911a011fa5f6868f Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Mon, 25 Jan 2021 20:10:57 +0900 Subject: [PATCH] Fixed scroll issue when use padding of TextField/TextEditor In OnRelayout, the size of mStencil, mActiveLayer should be calculated including padding. And the elements of text-decorator should also be positioned based on the size including padding. Change-Id: Iafc745a464b39560bb9707675878d3b47944653b Signed-off-by: Bowon Ryu --- .../internal/controls/text-controls/text-editor-impl.cpp | 12 +++++++++++- .../internal/controls/text-controls/text-editor-impl.h | 8 ++++++++ .../internal/controls/text-controls/text-field-impl.cpp | 12 +++++++++++- .../internal/controls/text-controls/text-field-impl.h | 8 ++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) 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 22880d3..42f9926 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -1381,6 +1381,14 @@ float TextEditor::GetHeightForWidth(float width) return mController->GetHeightForWidth(width) + padding.top + padding.bottom; } +void TextEditor::ResizeActor(Actor& actor, const Vector2& size) +{ + if (actor.GetProperty(Dali::Actor::Property::SIZE).GetVectorXY() != size) + { + actor.SetProperty(Actor::Property::SIZE, size); + } +} + void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container) { DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextEditor OnRelayout\n"); @@ -1410,10 +1418,12 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container) if(mStencil) { mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top)); + ResizeActor(mStencil, contentSize); } if(mActiveLayer) { mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top)); + ResizeActor(mActiveLayer, contentSize); } const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection); @@ -1426,7 +1436,7 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container) if(mDecorator && (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType))) { - mDecorator->Relayout(size); + mDecorator->Relayout(contentSize); } if(!mRenderer) 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 6be336b..ed8d039 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -356,6 +356,14 @@ private: // Implementation TextEditor& operator=(const TextEditor& rhs); /** + * @brief Resize actor to the given size. + * + * @param[in] actor The actor to be resized. + * @param[in] size Size to change. + */ + void ResizeActor( Actor& actor, const Vector2& size ); + + /** * @brief Render view, create and attach actor(s) to this text editor. */ void RenderText(Text::Controller::UpdateTextType updateTextType); diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 4cca3fd..9ad7a84 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -1333,6 +1333,14 @@ float TextField::GetHeightForWidth(float width) return mController->GetHeightForWidth(width) + padding.top + padding.bottom; } +void TextField::ResizeActor(Actor& actor, const Vector2& size) +{ + if (actor.GetProperty(Dali::Actor::Property::SIZE).GetVectorXY() != size) + { + actor.SetProperty(Actor::Property::SIZE, size); + } +} + void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container) { DALI_LOG_INFO(gLogFilter, Debug::Verbose, "TextField OnRelayout\n"); @@ -1362,10 +1370,12 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container) if(mStencil) { mStencil.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top)); + ResizeActor(mStencil, contentSize); } if(mActiveLayer) { mActiveLayer.SetProperty(Actor::Property::POSITION, Vector2(padding.start, padding.top)); + ResizeActor(mActiveLayer, contentSize); } const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection); @@ -1378,7 +1388,7 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container) if(mDecorator && (Text::Controller::NONE_UPDATED != (Text::Controller::DECORATOR_UPDATED & updateTextType))) { - mDecorator->Relayout(size); + mDecorator->Relayout(contentSize); } if(!mRenderer) diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index 87f4060..dbafa30 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -312,6 +312,14 @@ private: // Implementation TextField& operator=(const TextField& rhs); /** + * @brief Resize actor to the given size. + * + * @param[in] actor The actor to be resized. + * @param[in] size Size to change. + */ + void ResizeActor( Actor& actor, const Vector2& size ); + + /** * @brief Render view, create and attach actor(s) to this Text Field. */ void RenderText(Text::Controller::UpdateTextType updateTextType); -- 2.7.4