From e8cdd7517db4a66cdfd5ac5f51d0558d1f427c6e Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Fri, 12 Jul 2024 20:48:34 +0900 Subject: [PATCH] Add async text height for width RequestAsyncHeightForWidth : Requests asynchronous computation of the height of the text based on the given width. AsyncHeightForWidthComputedSignal : signal is emitted when the async height for width computed. Change-Id: I5029d7e61cd77f31948eaaf39aa9cf2bd7002596 Signed-off-by: Bowon Ryu --- .../controls/text-controls/text-label-devel.cpp | 10 +++++ .../controls/text-controls/text-label-devel.h | 29 ++++++++++++++ .../controls/text-controls/text-label-impl.cpp | 46 +++++++++++++++++++--- .../controls/text-controls/text-label-impl.h | 18 +++++++++ .../text/async-text/async-text-loader-impl.cpp | 11 ++++++ .../text/async-text/async-text-loader-impl.h | 5 +++ .../internal/text/async-text/async-text-loader.cpp | 5 +++ .../internal/text/async-text/async-text-loader.h | 9 +++++ .../internal/text/async-text/text-loading-task.cpp | 3 +- 9 files changed, 130 insertions(+), 6 deletions(-) diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp index 8766f01..12c16af 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp @@ -45,6 +45,11 @@ AsyncNaturalSizeComputedSignalType& AsyncNaturalSizeComputedSignal(TextLabel tex return GetImpl(textLabel).AsyncNaturalSizeComputedSignal(); } +AsyncHeightForWidthComputedSignalType& AsyncHeightForWidthComputedSignal(TextLabel textLabel) +{ + return GetImpl(textLabel).AsyncHeightForWidthComputedSignal(); +} + Vector GetTextSize(TextLabel textLabel, const uint32_t startIndex, const uint32_t endIndex) { return GetImpl(textLabel).GetTextSize(startIndex, endIndex); @@ -115,6 +120,11 @@ void RequestAsyncNaturalSize(TextLabel textLabel) GetImpl(textLabel).RequestAsyncNaturalSize(); } +void RequestAsyncHeightForWidth(TextLabel textLabel, float width) +{ + GetImpl(textLabel).RequestAsyncHeightForWidth(width); +} + } // namespace DevelTextLabel } // namespace Toolkit diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h index a62255e..ee303e8 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h @@ -434,6 +434,14 @@ DALI_TOOLKIT_API void RequestAsyncRenderWithConstraint(TextLabel textLabel, floa DALI_TOOLKIT_API void RequestAsyncNaturalSize(TextLabel textLabel); /** + * @brief Requests asynchronous computation of the height of the text based on the given width. + * + * @param[in] textLabel The instance of TextLabel. + * @param[in] width The width of text to compute. + */ +DALI_TOOLKIT_API void RequestAsyncHeightForWidth(TextLabel textLabel, float width); + +/** * @brief Anchor clicked signal type. * * @note Signal @@ -466,6 +474,15 @@ using AsyncTextRenderedSignalType = Signal; using AsyncNaturalSizeComputedSignalType = Signal; /** + * @brief Async height for width computed signal type. + * + * @note Signal + * - float : computed width. + * - float : computed height. + */ +using AsyncHeightForWidthComputedSignalType = Signal; + +/** * @brief This signal is emitted when the anchor is clicked. * * A callback of the following type may be connected: @@ -513,6 +530,18 @@ DALI_TOOLKIT_API AsyncTextRenderedSignalType& AsyncTextRenderedSignal(TextLabel */ DALI_TOOLKIT_API AsyncNaturalSizeComputedSignalType& AsyncNaturalSizeComputedSignal(TextLabel textLabel); +/** + * @brief This signal is emitted when the async height for width computed. + * + * A callback of the following type may be connected: + * @code + * void YourCallbackName(TextLabel textLabel); + * @endcode + * @param[in] textLabel The instance of TextLabel. + * @return The signal to connect to. + */ +DALI_TOOLKIT_API AsyncHeightForWidthComputedSignalType& AsyncHeightForWidthComputedSignal(TextLabel textLabel); + } // namespace DevelTextLabel } // namespace Toolkit 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 386bdc4..b348f4e 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -157,10 +157,11 @@ DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColo DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorBlue", TEXT_COLOR_BLUE, TEXT_COLOR, 2) DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION(Toolkit, TextLabel, "textColorAlpha", TEXT_COLOR_ALPHA, TEXT_COLOR, 3) -DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "anchorClicked", SIGNAL_ANCHOR_CLICKED) -DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "textFitChanged", SIGNAL_TEXT_FIT_CHANGED) -DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "asyncTextRendered", SIGNAL_ASYNC_TEXT_RENDERED) -DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "asyncNaturalSizeComputed", SIGNAL_ASYNC_NATURAL_SIZE_COMPUTED) +DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "anchorClicked", SIGNAL_ANCHOR_CLICKED ) +DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "textFitChanged", SIGNAL_TEXT_FIT_CHANGED ) +DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "asyncTextRendered", SIGNAL_ASYNC_TEXT_RENDERED ) +DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "asyncNaturalSizeComputed", SIGNAL_ASYNC_NATURAL_SIZE_COMPUTED ) +DALI_SIGNAL_REGISTRATION(Toolkit, TextLabel, "asyncHeightForWidthComputed", SIGNAL_ASYNC_HEIGHT_FOR_WIDTH_COMPUTED) DALI_TYPE_REGISTRATION_END() // clang-format on @@ -1009,6 +1010,14 @@ bool TextLabel::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* labelImpl.AsyncNaturalSizeComputedSignal().Connect(tracker, functor); } } + else if(0 == strcmp(signalName.c_str(), SIGNAL_ASYNC_HEIGHT_FOR_WIDTH_COMPUTED)) + { + if(label) + { + Internal::TextLabel& labelImpl(GetImpl(label)); + labelImpl.AsyncHeightForWidthComputedSignal().Connect(tracker, functor); + } + } else { // signalName does not match any signal @@ -1038,6 +1047,11 @@ DevelTextLabel::AsyncNaturalSizeComputedSignalType& TextLabel::AsyncNaturalSizeC return mAsyncNaturalSizeComputedSignal; } +DevelTextLabel::AsyncHeightForWidthComputedSignalType& TextLabel::AsyncHeightForWidthComputedSignal() +{ + return mAsyncHeightForWidthComputedSignal; +} + void TextLabel::OnInitialize() { Actor self = Self(); @@ -1644,7 +1658,8 @@ void TextLabel::AsyncSizeComputed(Text::AsyncTextRenderInfo renderInfo) case Async::COMPUTE_HEIGHT_FOR_WIDTH: { - // TODO + DALI_LOG_RELEASE_INFO("Height for width : %f, %f\n", renderInfo.renderedSize.width, renderInfo.renderedSize.height); + EmitAsyncHeightForWidthComputedSignal(renderInfo.renderedSize.width, renderInfo.renderedSize.height); } break; @@ -1725,6 +1740,14 @@ void TextLabel::EmitAsyncNaturalSizeComputedSignal(float width, float height) mAsyncNaturalSizeComputedSignal.Emit(handle, width + (padding.start + padding.end), height + (padding.top + padding.bottom)); } +void TextLabel::EmitAsyncHeightForWidthComputedSignal(float width, float height) +{ + Dali::Toolkit::TextLabel handle(GetOwner()); + Extents padding; + padding = Self().GetProperty(Toolkit::Control::Property::PADDING); + mAsyncHeightForWidthComputedSignal.Emit(handle, width, height + (padding.top + padding.bottom)); +} + void TextLabel::OnAccessibilityStatusChanged() { CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors); @@ -1849,6 +1872,19 @@ void TextLabel::RequestAsyncNaturalSize() TextVisual::RequestAsyncSizeComputation(mVisual, parameters); } +void TextLabel::RequestAsyncHeightForWidth(float width) +{ + Actor self = Self(); + Extents padding(0u, 0u, 0u, 0u); + Vector2 contentSize(width, 0.0f); + Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self); + + AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection); + parameters.requestType = Async::COMPUTE_HEIGHT_FOR_WIDTH; + + TextVisual::RequestAsyncSizeComputation(mVisual, parameters); +} + void TextLabel::RequestAsyncRenderWithFixedSize(float width, float height) { DALI_LOG_RELEASE_INFO("Request size : %f, %f\n", width, height); diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.h b/dali-toolkit/internal/controls/text-controls/text-label-impl.h index 3cd8c6e..9cb16c4 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -97,6 +97,11 @@ public: DevelTextLabel::AsyncNaturalSizeComputedSignalType& AsyncNaturalSizeComputedSignal(); /** + * @copydoc Dali::Toollkit::TextLabel::AsyncHeightForWidthComputedSignal() + */ + DevelTextLabel::AsyncHeightForWidthComputedSignalType& AsyncHeightForWidthComputedSignal(); + + /** * Connects a callback function with the object's signals. * @param[in] object The object providing the signal. * @param[in] tracker Used to disconnect the signal. @@ -281,6 +286,12 @@ public: */ void RequestAsyncNaturalSize(); + /** + * @brief Requests asynchronous computation of the height of the text based on the given width. + * @param[in] width The width of text to compute. + */ + void RequestAsyncHeightForWidth(float width); + private: // From Control /** @@ -450,6 +461,11 @@ private: */ void EmitAsyncNaturalSizeComputedSignal(float width, float height); + /** + * @brief Emits AsyncHeightForWidthComputed signal. + */ + void EmitAsyncHeightForWidthComputedSignal(float width, float height); + void OnAccessibilityStatusChanged(); private: // Data @@ -465,6 +481,8 @@ private: // Data Toolkit::DevelTextLabel::TextFitChangedSignalType mTextFitChangedSignal; Toolkit::DevelTextLabel::AsyncTextRenderedSignalType mAsyncTextRenderedSignal; Toolkit::DevelTextLabel::AsyncNaturalSizeComputedSignalType mAsyncNaturalSizeComputedSignal; + Toolkit::DevelTextLabel::AsyncHeightForWidthComputedSignalType mAsyncHeightForWidthComputedSignal; + std::string mLocale; Vector2 mSize; diff --git a/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp b/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp index 22e9c23..14aaff2 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp +++ b/dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp @@ -1166,6 +1166,17 @@ Size AsyncTextLoader::ComputeNaturalSize(AsyncTextParameters& parameters) return naturalSize; } +AsyncTextRenderInfo AsyncTextLoader::GetHeightForWidth(AsyncTextParameters& parameters) +{ + float height = ComputeHeightForWidth(parameters, parameters.textWidth, false); + AsyncTextRenderInfo renderInfo; + renderInfo.renderedSize.width = parameters.textWidth; + renderInfo.renderedSize.height = height; + renderInfo.requestType = Async::COMPUTE_HEIGHT_FOR_WIDTH; + + return renderInfo; +} + AsyncTextRenderInfo AsyncTextLoader::GetNaturalSize(AsyncTextParameters& parameters) { Size textNaturalSize = ComputeNaturalSize(parameters); diff --git a/dali-toolkit/internal/text/async-text/async-text-loader-impl.h b/dali-toolkit/internal/text/async-text/async-text-loader-impl.h index f1cefb5..a17b5dc 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader-impl.h +++ b/dali-toolkit/internal/text/async-text/async-text-loader-impl.h @@ -94,6 +94,11 @@ public: */ AsyncTextRenderInfo GetNaturalSize(AsyncTextParameters& parameters); + /** + * @copydoc Dali::AsyncTextLoader::GetHeightForWidth() + */ + AsyncTextRenderInfo GetHeightForWidth(AsyncTextParameters& parameters); + private: // Worker thread /** diff --git a/dali-toolkit/internal/text/async-text/async-text-loader.cpp b/dali-toolkit/internal/text/async-text/async-text-loader.cpp index 4143af7..a024ac8 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader.cpp +++ b/dali-toolkit/internal/text/async-text/async-text-loader.cpp @@ -82,6 +82,11 @@ AsyncTextRenderInfo AsyncTextLoader::GetNaturalSize(AsyncTextParameters& paramet return GetImplementation(*this).GetNaturalSize(parameters); } +AsyncTextRenderInfo AsyncTextLoader::GetHeightForWidth(AsyncTextParameters& parameters) +{ + return GetImplementation(*this).GetHeightForWidth(parameters); +} + Text::AsyncTextModule& AsyncTextLoader::GetModule() { return GetImplementation(*this).GetModule(); diff --git a/dali-toolkit/internal/text/async-text/async-text-loader.h b/dali-toolkit/internal/text/async-text/async-text-loader.h index c370b98..4935b9b 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader.h +++ b/dali-toolkit/internal/text/async-text/async-text-loader.h @@ -348,6 +348,15 @@ public: AsyncTextRenderInfo GetNaturalSize(AsyncTextParameters& parameters); /** + * @brief Gets the height for width of text. + * + * @param[in] parameters All options required to compute text. + * + * @return An AsyncTextRenderInfo. + */ + AsyncTextRenderInfo GetHeightForWidth(AsyncTextParameters& parameters); + + /** * @brief Get AsyncTextModule to used in text visual. * * @return An AsyncTextModule. diff --git a/dali-toolkit/internal/text/async-text/text-loading-task.cpp b/dali-toolkit/internal/text/async-text/text-loading-task.cpp index 5e20227..ef62f33 100644 --- a/dali-toolkit/internal/text/async-text/text-loading-task.cpp +++ b/dali-toolkit/internal/text/async-text/text-loading-task.cpp @@ -122,7 +122,8 @@ void TextLoadingTask::Load() case Text::Async::COMPUTE_HEIGHT_FOR_WIDTH: { - // TODO + DALI_LOG_RELEASE_INFO("-->TextLoadingTask::Load GetHeightForWidth\n"); + mRenderInfo = mLoader.GetHeightForWidth(mParameters); } break; -- 2.7.4