[Tizen] Fix Text Anchor don't work properly 01/304201/2 accepted/tizen/7.0/unified/20240115.170644
authorANZ1217 <chihun.jeong@samsung.com>
Thu, 11 Jan 2024 11:36:48 +0000 (20:36 +0900)
committerANZ1217 <chihun.jeong@samsung.com>
Fri, 12 Jan 2024 03:41:23 +0000 (12:41 +0900)
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
dali-toolkit/internal/text/controller/text-controller-event-handler.cpp
dali-toolkit/internal/text/controller/text-controller.cpp
dali-toolkit/internal/text/controller/text-controller.h
dali-toolkit/internal/text/text-model.h

index fbebd86..b787366 100644 (file)
@@ -1138,6 +1138,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))
index dddb7da..9708844 100644 (file)
@@ -377,16 +377,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);
 
index 399e871..d4082fb 100644 (file)
@@ -1416,6 +1416,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);
index 38b1e98..b6f0aff 100644 (file)
@@ -1574,6 +1574,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.
index a3a42a2..92a514a 100644 (file)
@@ -380,6 +380,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