From a7cb948e46e3531a1bf12bb681c0d2dc595b5183 Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Wed, 10 Jul 2024 14:38:23 +0900 Subject: [PATCH] Add RequestAsyncRenderWithConstraint to text label Requests asynchronous rendering with the maximum available width using the given widthConstraint. If the width of the text content is smaller than the widthConstraint, the width will be determined by the width of the text. If the width of the text content is larger than the widthConstraint, the width will be determined by the widthConstraint. The height is determined by the content of the text when rendered with the given width. In this case, the result will be the same as the height returned by GetHeightForWidth. Change-Id: I375b70172267d24468eb9c9bbfd60e98ce80d190 Signed-off-by: Bowon Ryu --- .../controls/text-controls/text-label-devel.cpp | 5 +++ .../controls/text-controls/text-label-devel.h | 13 ++++++++ .../controls/text-controls/text-label-impl.cpp | 39 ++++++++++++++++++++-- .../controls/text-controls/text-label-impl.h | 27 +++++++++++---- .../text/async-text/async-text-loader-impl.cpp | 28 +++++++++++++--- .../internal/text/async-text/async-text-loader.h | 13 +++++--- dali-toolkit/internal/visuals/text/text-visual.cpp | 10 +++++- 7 files changed, 117 insertions(+), 18 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 1e00325..5dbbd79 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 @@ -100,6 +100,11 @@ void RequestAsyncRenderWithFixedWidth(TextLabel textLabel, float width) GetImpl(textLabel).RequestAsyncRenderWithFixedWidth(width); } +void RequestAsyncRenderWithConstraint(TextLabel textLabel, float widthConstraint) +{ + GetImpl(textLabel).RequestAsyncRenderWithConstraint(widthConstraint); +} + } // 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 e71ab82..bb2cc64 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 @@ -401,6 +401,19 @@ DALI_TOOLKIT_API void RequestAsyncRenderWithFixedSize(TextLabel textLabel, float DALI_TOOLKIT_API void RequestAsyncRenderWithFixedWidth(TextLabel textLabel, float width); /** + * @brief Requests asynchronous rendering with the maximum available width using the given widthConstraint. + * + * If the width of the text content is smaller than the widthConstraint, the width will be determined by the width of the text. + * If the width of the text content is larger than the widthConstraint, the width will be determined by the widthConstraint. + * The height is determined by the content of the text when rendered with the given width. + * In this case, the result will be the same as the height returned by GetHeightForWidth. + * + * @param[in] textLabel The instance of TextLabel. + * @param[in] widthConstraint The maximum available width of text to render. + */ +DALI_TOOLKIT_API void RequestAsyncRenderWithConstraint(TextLabel textLabel, float widthConstraint); + +/** * @brief Anchor clicked signal type. * * @note Signal 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 e50212d..fd2ea64 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -1767,6 +1767,8 @@ void TextLabel::RequestAsyncRenderWithFixedSize(float width, float height) } AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection); + parameters.renderType = AsyncTextParameters::FIXED_SIZE; + TextVisual::UpdateAsyncRenderer(mVisual, parameters); mTextUpdateNeeded = false; mIsPropertyUpdated = false; @@ -1799,8 +1801,41 @@ void TextLabel::RequestAsyncRenderWithFixedWidth(float width) } AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection); - parameters.isFixedSize = false; - parameters.isFixedWidth = true; + parameters.renderType = AsyncTextParameters::FIXED_WIDTH; + + TextVisual::UpdateAsyncRenderer(mVisual, parameters); + mTextUpdateNeeded = false; + mIsPropertyUpdated = false; +} + +void TextLabel::RequestAsyncRenderWithConstraint(float widthConstraint) +{ + DALI_LOG_RELEASE_INFO("Request width constraint : %f\n", widthConstraint); + + if(!mController->IsAsyncTextLoadEnabled()) + { + DALI_LOG_WARNING("IsAsyncTextLoadEnabled is false\n"); + return; + } + + Actor self = Self(); + + Extents padding; + padding = self.GetProperty(Toolkit::Control::Property::PADDING); + + Vector2 contentSize(widthConstraint - (padding.start + padding.end), 0.0f); + + // Support Right-To-Left + Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self); + + // Support Right-To-Left of padding + if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection) + { + std::swap(padding.start, padding.end); + } + + AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection); + parameters.renderType = AsyncTextParameters::CONSTRAINT; TextVisual::UpdateAsyncRenderer(mVisual, parameters); mTextUpdateNeeded = false; 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 efcf2e7..d94c49e 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -247,15 +247,28 @@ public: */ void RequestAsyncRenderWithFixedSize(float width, float height); -/** - * @brief Requests asynchronous text rendering with a fixed width. - * The height is determined by the content of the text when rendered with the given width. - * The result will be the same as the height returned by GetHeightForWidth. - * - * @param[in] width The width of text to render. - */ + /** + * @brief Requests asynchronous text rendering with a fixed width. + * The height is determined by the content of the text when rendered with the given width. + * The result will be the same as the height returned by GetHeightForWidth. + * + * @param[in] width The width of text to render. + */ void RequestAsyncRenderWithFixedWidth(float width); + /** + * @brief Requests asynchronous rendering with the maximum available width using the given widthConstraint. + * + * If the width of the text content is smaller than the widthConstraint, the width will be determined by the width of the text. + * If the width of the text content is larger than the widthConstraint, the width will be determined by the widthConstraint. + * The height is determined by the content of the text when rendered with the given width. + * In this case, the result will be the same as the height returned by GetHeightForWidth. + * + * @param[in] widthConstraint The maximum available width of text to render. + */ + void RequestAsyncRenderWithConstraint(float widthConstraint); + + private: // From Control /** * @copydoc Control::OnInitialize() 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 7f1423b..52ba9db 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 @@ -1057,7 +1057,7 @@ AsyncTextRenderInfo AsyncTextLoader::Render(AsyncTextParameters& parameters) { renderInfo.renderedSize = Size(static_cast(renderInfo.width), static_cast(renderInfo.height)); } - else if(parameters.isFixedSize || parameters.isFixedWidth) + else { renderInfo.renderedSize = Size(static_cast(parameters.textWidth), static_cast(parameters.textHeight)); } @@ -1069,7 +1069,17 @@ AsyncTextRenderInfo AsyncTextLoader::RenderText(AsyncTextParameters& parameters) { DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::RenderText\n"); - if(parameters.isFixedWidth) + if(parameters.renderType == AsyncTextParameters::CONSTRAINT) + { + Size textNaturalSize = ComputeNaturalSize(parameters); + // textWidth is widthConstraint + if(parameters.textWidth > textNaturalSize.width) + { + parameters.textWidth = static_cast(textNaturalSize.width); + } + } + + if(parameters.renderType == AsyncTextParameters::FIXED_WIDTH || parameters.renderType == AsyncTextParameters::CONSTRAINT) { uint32_t height = ComputeHeightForWidth(parameters, parameters.textWidth); parameters.textHeight = height; @@ -1146,7 +1156,7 @@ AsyncTextRenderInfo AsyncTextLoader::RenderAutoScroll(AsyncTextParameters& param textNaturalSize.width += (parameters.padding.start + parameters.padding.end); textNaturalSize.height += (parameters.padding.top + parameters.padding.bottom); - if(parameters.isFixedWidth) + if(parameters.renderType == AsyncTextParameters::FIXED_WIDTH || parameters.renderType == AsyncTextParameters::CONSTRAINT) { // In case of a fixed width, textHeight is zero. // The height calculated during layout should be set. @@ -1224,7 +1234,17 @@ bool AsyncTextLoader::CheckForTextFit(AsyncTextParameters& parameters, float poi AsyncTextRenderInfo AsyncTextLoader::RenderTextFit(AsyncTextParameters& parameters) { - if(parameters.isFixedWidth) + if(parameters.renderType == AsyncTextParameters::CONSTRAINT) + { + Size textNaturalSize = ComputeNaturalSize(parameters); + // textWidth is widthConstraint + if(parameters.textWidth > textNaturalSize.width) + { + parameters.textWidth = static_cast(textNaturalSize.width); + } + } + + if(parameters.renderType == AsyncTextParameters::FIXED_WIDTH || parameters.renderType == AsyncTextParameters::CONSTRAINT) { uint32_t height = ComputeHeightForWidth(parameters, parameters.textWidth); parameters.textHeight = height; 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 86cb2fd..9603dc0 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader.h +++ b/dali-toolkit/internal/text/async-text/async-text-loader.h @@ -45,9 +45,15 @@ class AsyncTextLoader; struct AsyncTextParameters { + enum RenderType + { + FIXED_SIZE, + FIXED_WIDTH, + CONSTRAINT + }; + AsyncTextParameters() - : isFixedSize{true}, - isFixedWidth{false}, + : renderType{FIXED_SIZE}, maxTextureSize{0}, text{}, fontSize{0.f}, @@ -115,8 +121,7 @@ struct AsyncTextParameters { } - bool isFixedSize; - bool isFixedWidth; + RenderType renderType; int maxTextureSize; ///< The maximum size of texture. diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index 6643be1..ccb02c6 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -946,6 +946,13 @@ void TextVisual::LoadComplete(bool loadingSuccess, TextInformation textInformati mAsyncTextInterface->AsyncLoadComplete(renderInfo); } + // Ignore current result when user re-request async load during load complete callback. + if(mIsTaskRunning) + { + // Remove the texture set and any renderer previously set. + RemoveRenderer(control, true); + return; + } } else { @@ -971,7 +978,8 @@ void TextVisual::UpdateAsyncRenderer(Text::AsyncTextParameters& parameters) return; } - if(!parameters.isFixedWidth && ((fabsf(parameters.textWidth) < Math::MACHINE_EPSILON_1000) || (fabsf(parameters.textHeight) < Math::MACHINE_EPSILON_1000) || parameters.text.empty())) + if(parameters.renderType == Text::AsyncTextParameters::FIXED_SIZE && + ((fabsf(parameters.textWidth) < Math::MACHINE_EPSILON_1000) || (fabsf(parameters.textHeight) < Math::MACHINE_EPSILON_1000) || parameters.text.empty())) { // Remove the texture set and any renderer previously set. RemoveRenderer(control, true); -- 2.7.4