Fix GetHeightForWidth for text controller 04/299204/3
authorBowon Ryu <bowon.ryu@samsung.com>
Thu, 21 Sep 2023 10:06:54 +0000 (19:06 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Mon, 25 Sep 2023 11:16:13 +0000 (20:16 +0900)
In the case of text label,
the height of the layout is used when returning the cached value of GetHeightForWidth.

But, this value is the height of the layout that has been Ellipsis processed.
It's not the height of the entire Text.

So, the intended height cannot be obtained.

This patch simply stores calculated values.

Change-Id: Ia5d06bdac39556776749de3e3078a3a7e230c36c
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
dali-toolkit/internal/text/controller/text-controller-impl.h
dali-toolkit/internal/text/controller/text-controller-relayouter.cpp

index 97010cc..0f910d0 100644 (file)
@@ -341,6 +341,7 @@ struct Controller::Impl
     mMaximumNumberOfCharacters(50u),
     mHiddenInput(NULL),
     mInputFilter(nullptr),
+    mLastHeightForWidth(0.0f, 0.0f),
     mRecalculateNaturalSize(true),
     mMarkupProcessorEnabled(false),
     mClipboardHideEnabled(true),
@@ -1024,6 +1025,7 @@ public:
   HiddenText*                  mHiddenInput;                ///< Avoid allocating this when the user does not specify hidden input mode.
   std::unique_ptr<InputFilter> mInputFilter;                ///< Avoid allocating this when the user does not specify input filter mode.
   Vector2                      mTextFitContentSize;         ///< Size of Text fit content
+  Vector2                      mLastHeightForWidth;         ///< Size of Text content from GetHeightForWidth
 
   bool               mRecalculateNaturalSize : 1;         ///< Whether the natural size needs to be recalculated.
   bool               mMarkupProcessorEnabled : 1;         ///< Whether the mark-up procesor is enabled.
index d595d00..c3711f3 100644 (file)
@@ -345,13 +345,11 @@ float Controller::Relayouter::GetHeightForWidth(Controller& controller, float wi
   EventHandler::ProcessModifyEvents(controller);
 
   Controller::Impl& impl           = *controller.mImpl;
-  ModelPtr&         model          = impl.mModel;
-  VisualModelPtr&   visualModel    = model->mVisualModel;
   TextUpdateInfo&   textUpdateInfo = impl.mTextUpdateInfo;
 
   Size layoutSize;
 
-  if(fabsf(width - visualModel->mControlSize.width) > Math::MACHINE_EPSILON_1000 ||
+  if(fabsf(width - impl.mLastHeightForWidth.width) > Math::MACHINE_EPSILON_1000 ||
      textUpdateInfo.mFullRelayoutNeeded ||
      textUpdateInfo.mClearAll)
   {
@@ -360,12 +358,14 @@ float Controller::Relayouter::GetHeightForWidth(Controller& controller, float wi
     Size           sizeRequestedWidthAndMaxHeight = Size(width, MAX_FLOAT);
 
     layoutSize = CalculateLayoutSizeOnRequiredControllerSize(controller, sizeRequestedWidthAndMaxHeight, requestedOperationsMask);
+    impl.mLastHeightForWidth.width  = width;
+    impl.mLastHeightForWidth.height = layoutSize.height;
 
     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height);
   }
   else
   {
-    layoutSize = visualModel->GetLayoutSize();
+    layoutSize = impl.mLastHeightForWidth;
     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height);
   }