From: Bowon Ryu Date: Tue, 26 Sep 2023 06:50:50 +0000 (+0900) Subject: Add GetHeightForWidth for text visual model X-Git-Tag: dali_2.2.46~2^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=2497507eefb2ff82eb5a18ba875eae8cd8b6b346 Add GetHeightForWidth for text visual model 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 --- diff --git a/dali-toolkit/internal/text/controller/text-controller-relayouter.cpp b/dali-toolkit/internal/text/controller/text-controller-relayouter.cpp index d595d00..fafff2f 100644 --- a/dali-toolkit/internal/text/controller/text-controller-relayouter.cpp +++ b/dali-toolkit/internal/text/controller/text-controller-relayouter.cpp @@ -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); } diff --git a/dali-toolkit/internal/text/visual-model-impl.cpp b/dali-toolkit/internal/text/visual-model-impl.cpp index 490bae3..c79e5a9 100644 --- a/dali-toolkit/internal/text/visual-model-impl.cpp +++ b/dali-toolkit/internal/text/visual-model-impl.cpp @@ -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), diff --git a/dali-toolkit/internal/text/visual-model-impl.h b/dali-toolkit/internal/text/visual-model-impl.h index eebbe18..9dae2cf 100644 --- a/dali-toolkit/internal/text/visual-model-impl.h +++ b/dali-toolkit/internal/text/visual-model-impl.h @@ -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 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.