From 69dbd7fd8b950e41acaaba3b470a3d89f8935223 Mon Sep 17 00:00:00 2001 From: ANZ1217 Date: Thu, 11 Jan 2024 20:36:48 +0900 Subject: [PATCH] [Tizen] Fix Text Anchor don't work properly When the text component is vertical aligned as center or bottom, The y offset was not calculated at anchor event. Now, it works properly. Change-Id: I31f2530122d28e07a32c8a75875a77bcc69353ee --- dali-toolkit/internal/controls/text-controls/text-label-impl.cpp | 2 ++ .../internal/text/controller/text-controller-event-handler.cpp | 5 ++++- dali-toolkit/internal/text/controller/text-controller.cpp | 5 +++++ dali-toolkit/internal/text/controller/text-controller.h | 7 +++++++ dali-toolkit/internal/text/text-model.h | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index 5126758..262c5cc 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -1162,6 +1162,8 @@ void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container) visualTransformOffset.x = roundf(padding.start + alignmentOffset.x); visualTransformOffset.y = roundf(padding.top + alignmentOffset.y); + mController->SetVisualTransformOffset(visualTransformOffset); + Property::Map visualTransform; visualTransform.Add(Toolkit::Visual::Transform::Property::SIZE, layoutSize) .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE)) diff --git a/dali-toolkit/internal/text/controller/text-controller-event-handler.cpp b/dali-toolkit/internal/text/controller/text-controller-event-handler.cpp index 8d6d556..8044923 100644 --- a/dali-toolkit/internal/text/controller/text-controller-event-handler.cpp +++ b/dali-toolkit/internal/text/controller/text-controller-event-handler.cpp @@ -379,16 +379,19 @@ void Controller::EventHandler::AnchorEvent(Controller& controller, float x, floa CharacterIndex cursorPosition = 0u; // Convert from control's coords to text's coords. + const float xPosition = x - controller.mImpl->mModel->mScrollPosition.x; const float yPosition = y - controller.mImpl->mModel->mScrollPosition.y; + Vector2 visualTransformOffset = controller.mImpl->mModel->mVisualTransformOffset; + // Whether to touch point hits on a glyph. bool matchedCharacter = false; cursorPosition = Text::GetClosestCursorIndex(controller.mImpl->mModel->mVisualModel, controller.mImpl->mModel->mLogicalModel, controller.mImpl->mMetrics, xPosition, - yPosition, + yPosition - visualTransformOffset.y, CharacterHitTest::TAP, matchedCharacter); diff --git a/dali-toolkit/internal/text/controller/text-controller.cpp b/dali-toolkit/internal/text/controller/text-controller.cpp index 469c273..203d242 100644 --- a/dali-toolkit/internal/text/controller/text-controller.cpp +++ b/dali-toolkit/internal/text/controller/text-controller.cpp @@ -1474,6 +1474,11 @@ const float Controller::GetCharacterSpacing() const return mImpl->mModel->mVisualModel->GetCharacterSpacing(); } +void Controller::SetVisualTransformOffset(Vector2 offset) +{ + mImpl->mModel->mVisualTransformOffset = offset; +} + Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection) { return Relayouter::Relayout(*this, size, layoutDirection); diff --git a/dali-toolkit/internal/text/controller/text-controller.h b/dali-toolkit/internal/text/controller/text-controller.h index fcd6166..ad37df0 100644 --- a/dali-toolkit/internal/text/controller/text-controller.h +++ b/dali-toolkit/internal/text/controller/text-controller.h @@ -1634,6 +1634,13 @@ public: // Default style & Input style */ const float GetCharacterSpacing() const; + /** + * @brief Sets the visual transform offset. + * + * @param[in] offset The offset. + */ + void SetVisualTransformOffset(Vector2 offset); + public: // Queries & retrieves. /** * @brief Return the layout engine. diff --git a/dali-toolkit/internal/text/text-model.h b/dali-toolkit/internal/text/text-model.h index d21dbc7..012c86f 100644 --- a/dali-toolkit/internal/text/text-model.h +++ b/dali-toolkit/internal/text/text-model.h @@ -400,6 +400,7 @@ public: bool mIgnoreSpacesAfterText : 1; ///< Whether ignoring spaces after text or not. Default is true. DevelText::MatchLayoutDirection mMatchLayoutDirection; ///< Whether to match text alignment with layout direction or not. DevelText::EllipsisPosition::Type mEllipsisPosition; ///< Where is the location the text elide + Vector2 mVisualTransformOffset; ///< The offset of the layout based on the controller due to alignment. }; } // namespace Text -- 2.7.4