Add GetHeightForWidth for text visual model 36/299336/1
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 26 Sep 2023 06:50:50 +0000 (15:50 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Tue, 26 Sep 2023 06:56:31 +0000 (15:56 +0900)
Use visual model's GetHeightForWidth instead of GetLayoutSize.

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: I0494fb476964fb1207d35e3c8e6eb25ece972025
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
dali-toolkit/internal/text/controller/text-controller-relayouter.cpp
dali-toolkit/internal/text/visual-model-impl.cpp
dali-toolkit/internal/text/visual-model-impl.h

index d595d00..fafff2f 100644 (file)
@@ -349,9 +349,10 @@ float Controller::Relayouter::GetHeightForWidth(Controller& controller, float wi
   VisualModelPtr&   visualModel    = model->mVisualModel;
   TextUpdateInfo&   textUpdateInfo = impl.mTextUpdateInfo;
 
-  Size layoutSize;
+  // Get cached value.
+  Size layoutSize = visualModel->GetHeightForWidth();
 
-  if(fabsf(width - visualModel->mControlSize.width) > Math::MACHINE_EPSILON_1000 ||
+  if(fabsf(width - layoutSize.width) > Math::MACHINE_EPSILON_1000 ||
      textUpdateInfo.mFullRelayoutNeeded ||
      textUpdateInfo.mClearAll)
   {
@@ -361,11 +362,15 @@ float Controller::Relayouter::GetHeightForWidth(Controller& controller, float wi
 
     layoutSize = CalculateLayoutSizeOnRequiredControllerSize(controller, sizeRequestedWidthAndMaxHeight, requestedOperationsMask);
 
+    // The calculated layout width may not be the same as the requested width.
+    // For cache efficiency, the requested width is stored.
+    layoutSize.width = width;
+    visualModel->SetHeightForWidth(layoutSize);
+
     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth calculated %f\n", layoutSize.height);
   }
   else
   {
-    layoutSize = visualModel->GetLayoutSize();
     DALI_LOG_INFO(gLogFilter, Debug::Verbose, "<--Controller::GetHeightForWidth cached %f\n", layoutSize.height);
   }
 
index 490bae3..c79e5a9 100644 (file)
@@ -340,6 +340,16 @@ const Vector2& VisualModel::GetLayoutSize() const
   return mLayoutSize;
 }
 
+void VisualModel::SetHeightForWidth(const Vector2& size)
+{
+  mHeightForWidth = size;
+}
+
+const Vector2& VisualModel::GetHeightForWidth() const
+{
+  return mHeightForWidth;
+}
+
 void VisualModel::SetTextColor(const Vector4& textColor)
 {
   mTextColor = textColor;
@@ -664,6 +674,7 @@ VisualModel::VisualModel()
   mOutlineWidth(0u),
   mNaturalSize(),
   mLayoutSize(),
+  mHeightForWidth(0.0f, 0.0f),
   mCachedLineIndex(0u),
   mEllipsisPosition(DevelText::EllipsisPosition::END),
   mStartIndexOfElidedGlyphs(0u),
index eebbe18..9dae2cf 100644 (file)
@@ -218,6 +218,20 @@ public:
   const Vector2& GetLayoutSize() const;
 
   /**
+   * @brief Sets the size of height for width.
+   *
+   * @param[in] size The text's height for width size.
+   */
+  void SetHeightForWidth(const Vector2& size);
+
+  /**
+   * @brief Retrieves the height for width size.
+   *
+   * @return The text's height for width size.
+   */
+  const Vector2& GetHeightForWidth() const;
+
+  /**
    * @brief Set the text's color
    *
    * @param[in] textColor The text's color
@@ -670,8 +684,9 @@ public:
   Vector<CharacterSpacingGlyphRun> mCharacterSpacingRuns;   ///< Runs of glyphs that have character-spacing.
 
 private:
-  Size mNaturalSize; ///< Size of the text with no line wrapping.
-  Size mLayoutSize;  ///< Size of the laid-out text considering the layout properties set.
+  Size mNaturalSize;    ///< Size of the text with no line wrapping.
+  Size mLayoutSize;     ///< Size of the laid-out text considering the layout properties set.
+  Size mHeightForWidth; ///< Size of the text last calculated using GetHeightForWidth.
 
   // Caches to increase performance in some consecutive operations.
   LineIndex mCachedLineIndex; ///< Used to increase performance in consecutive calls to GetLineOfGlyph() or GetLineOfCharacter() with consecutive glyphs or characters.