From: Bowon Ryu Date: Wed, 10 Jul 2024 01:24:29 +0000 (+0900) Subject: Add RequestAsyncRenderWithFixedWidth to label X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a7abb794f14397a09e9170304325a7ac09ac4cb;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Add RequestAsyncRenderWithFixedWidth to label 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. Change-Id: I60b3d5355089aaaa1fb438ee963ade26ee8c050a Signed-off-by: Bowon Ryu --- 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 79c44d0..1e00325 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 @@ -95,6 +95,11 @@ void RequestAsyncRenderWithFixedSize(TextLabel textLabel, float width, float hei GetImpl(textLabel).RequestAsyncRenderWithFixedSize(width, height); } +void RequestAsyncRenderWithFixedWidth(TextLabel textLabel, float width) +{ + GetImpl(textLabel).RequestAsyncRenderWithFixedWidth(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 df8d7f4..e71ab82 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 @@ -391,6 +391,16 @@ DALI_TOOLKIT_API bool IsRemoveBackInset(TextLabel textLabel); DALI_TOOLKIT_API void RequestAsyncRenderWithFixedSize(TextLabel textLabel, 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] textLabel The instance of TextLabel. + * @param[in] width The width of text to render. + */ +DALI_TOOLKIT_API void RequestAsyncRenderWithFixedWidth(TextLabel textLabel, float width); + +/** * @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 8df21c7..e50212d 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -1595,7 +1595,12 @@ void TextLabel::AsyncLoadComplete(Text::AsyncTextRenderInfo renderInfo) // To avoid flickering issues, enable/disable the background visual when async load is completed. EnableControlBackground(!mController->IsTextCutout()); - EmitAsyncTextRenderedSignal(renderInfo.renderedSize.width, renderInfo.renderedSize.height); + Actor self = Self(); + + Extents padding; + padding = self.GetProperty(Toolkit::Control::Property::PADDING); + + EmitAsyncTextRenderedSignal(renderInfo.renderedSize.width + (padding.start + padding.end), renderInfo.renderedSize.height + (padding.top + padding.bottom)); } void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type) @@ -1737,35 +1742,69 @@ void TextLabel::EnableControlBackground(const bool enable) void TextLabel::RequestAsyncRenderWithFixedSize(float width, float height) { - if(mController->IsAsyncTextLoadEnabled()) - { - DALI_LOG_RELEASE_INFO("Request size : %f, %f\n", width, height); + DALI_LOG_RELEASE_INFO("Request size : %f, %f\n", width, height); - Actor self = Self(); + if(!mController->IsAsyncTextLoadEnabled()) + { + DALI_LOG_WARNING("IsAsyncTextLoadEnabled is false\n"); + return; + } - Extents padding; - padding = self.GetProperty(Toolkit::Control::Property::PADDING); + Actor self = Self(); - Vector2 contentSize(width - (padding.start + padding.end), height - (padding.top + padding.bottom)); + Extents padding; + padding = self.GetProperty(Toolkit::Control::Property::PADDING); - // Support Right-To-Left - Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self); + Vector2 contentSize(width - (padding.start + padding.end), height - (padding.top + padding.bottom)); - // Support Right-To-Left of padding - if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection) - { - std::swap(padding.start, padding.end); - } + // Support Right-To-Left + Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self); - AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection); - TextVisual::UpdateAsyncRenderer(mVisual, parameters); - mTextUpdateNeeded = false; - mIsPropertyUpdated = false; + // Support Right-To-Left of padding + if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection) + { + std::swap(padding.start, padding.end); } - else + + AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection); + TextVisual::UpdateAsyncRenderer(mVisual, parameters); + mTextUpdateNeeded = false; + mIsPropertyUpdated = false; +} + +void TextLabel::RequestAsyncRenderWithFixedWidth(float width) +{ + DALI_LOG_RELEASE_INFO("Request width : %f\n", width); + + 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(width - (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.isFixedSize = false; + parameters.isFixedWidth = true; + + TextVisual::UpdateAsyncRenderer(mVisual, parameters); + mTextUpdateNeeded = false; + mIsPropertyUpdated = false; } std::string TextLabel::TextLabelAccessible::GetNameRaw() const 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 8c1a198..efcf2e7 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -247,6 +247,14 @@ 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. + */ + void RequestAsyncRenderWithFixedWidth(float width); private: // From Control /** 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 0090d1b..7f1423b 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 @@ -1053,7 +1053,11 @@ AsyncTextRenderInfo AsyncTextLoader::Render(AsyncTextParameters& parameters) renderInfo.styleEnabled = styleEnabled; renderInfo.isOverlayStyle = isOverlayStyle; - if(parameters.isFixedSize) + if(cutoutEnabled) + { + renderInfo.renderedSize = Size(static_cast(renderInfo.width), static_cast(renderInfo.height)); + } + else if(parameters.isFixedSize || parameters.isFixedWidth) { renderInfo.renderedSize = Size(static_cast(parameters.textWidth), static_cast(parameters.textHeight)); } @@ -1065,19 +1069,50 @@ AsyncTextRenderInfo AsyncTextLoader::RenderText(AsyncTextParameters& parameters) { DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::RenderText\n"); - Initialize(); + if(parameters.isFixedWidth) + { + uint32_t height = ComputeHeightForWidth(parameters, parameters.textWidth); + parameters.textHeight = height; + mTextModel->mVisualModel->mControlSize = Size(parameters.textWidth, parameters.textHeight); + } + else + { + Initialize(); + Update(parameters); + bool layoutUpdated = false; + Layout(parameters, layoutUpdated); + } - Update(parameters); + return Render(parameters); +} + +uint32_t AsyncTextLoader::ComputeHeightForWidth(AsyncTextParameters& parameters, uint32_t width) +{ + DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::ComputeHeightForWidth\n"); + uint32_t actualWidth = parameters.textWidth; + uint32_t actualHeight = parameters.textHeight; + + parameters.textWidth = width; + parameters.textHeight = MAX_UINT32; + + Initialize(); + Update(parameters); bool layoutUpdated = false; - Layout(parameters, layoutUpdated); - return Render(parameters); + Size layoutSize = Layout(parameters, layoutUpdated); + + // Restore actual size. + parameters.textWidth = actualWidth; + parameters.textHeight = actualHeight; + mTextModel->mVisualModel->mControlSize = Size(parameters.textWidth, parameters.textHeight); + + return layoutSize.height; } -Size AsyncTextLoader::CalculateNaturalSize(AsyncTextParameters& parameters) +Size AsyncTextLoader::ComputeNaturalSize(AsyncTextParameters& parameters) { - DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::CalculateNaturalSize\n"); + DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::ComputeNaturalSize\n"); uint32_t actualWidth = parameters.textWidth; uint32_t actualHeight = parameters.textHeight; @@ -1104,13 +1139,22 @@ AsyncTextRenderInfo AsyncTextLoader::RenderAutoScroll(AsyncTextParameters& param { DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::RenderAutoScroll\n"); - const Size controlSize(static_cast(parameters.textWidth), static_cast(parameters.textHeight)); + Size controlSize(static_cast(parameters.textWidth), static_cast(parameters.textHeight)); // As relayout of text may not be done at this point natural size is used to get size. Single line scrolling only. - Size textNaturalSize = CalculateNaturalSize(parameters); + Size textNaturalSize = ComputeNaturalSize(parameters); textNaturalSize.width += (parameters.padding.start + parameters.padding.end); textNaturalSize.height += (parameters.padding.top + parameters.padding.bottom); + if(parameters.isFixedWidth) + { + // In case of a fixed width, textHeight is zero. + // The height calculated during layout should be set. + parameters.textHeight = static_cast(textNaturalSize.height) - static_cast(parameters.padding.top + parameters.padding.bottom); + controlSize.height = static_cast(parameters.textHeight); + mTextModel->mVisualModel->mControlSize = Size(parameters.textWidth, parameters.textHeight); + } + DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::RenderAutoScroll natural size : %f, %f, control size : %f, %f \n", textNaturalSize.x, textNaturalSize.y, controlSize.x, controlSize.y); // Calculate the actual gap before scrolling wraps. @@ -1180,6 +1224,12 @@ bool AsyncTextLoader::CheckForTextFit(AsyncTextParameters& parameters, float poi AsyncTextRenderInfo AsyncTextLoader::RenderTextFit(AsyncTextParameters& parameters) { + if(parameters.isFixedWidth) + { + uint32_t height = ComputeHeightForWidth(parameters, parameters.textWidth); + parameters.textHeight = height; + } + if(parameters.isTextFitArrayEnabled) { DALI_LOG_RELEASE_INFO("-->AsyncTextLoader::RenderTextFit -> TextFitArray\n"); 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 b72ec83..f7d80d9 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 @@ -128,13 +128,23 @@ private: AsyncTextRenderInfo Render(AsyncTextParameters& parameters); /** - * @brief Calculate natural size of text. + * @brief Compute natural size of text. * - * @param[in] parameters All options required to calculate size of text. + * @param[in] parameters All options required to compute size of text. * * @return The natural size of text. */ - Size CalculateNaturalSize(AsyncTextParameters& parameters); + Size ComputeNaturalSize(AsyncTextParameters& parameters); + + /** + * @brief Compute height for width of text. + * + * @param[in] parameters All options required to compute height of text. + * @param[in] width The width of text to compute. + * + * @return The height for width of text. + */ + uint32_t ComputeHeightForWidth(AsyncTextParameters& parameters, uint32_t width); /** * @brief Check if the text fits. 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 578fca5..86cb2fd 100644 --- a/dali-toolkit/internal/text/async-text/async-text-loader.h +++ b/dali-toolkit/internal/text/async-text/async-text-loader.h @@ -47,6 +47,7 @@ struct AsyncTextParameters { AsyncTextParameters() : isFixedSize{true}, + isFixedWidth{false}, maxTextureSize{0}, text{}, fontSize{0.f}, @@ -115,6 +116,7 @@ struct AsyncTextParameters } bool isFixedSize; + bool isFixedWidth; 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 dc29820..6643be1 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -945,6 +945,7 @@ void TextVisual::LoadComplete(bool loadingSuccess, TextInformation textInformati { mAsyncTextInterface->AsyncLoadComplete(renderInfo); } + } else { @@ -970,7 +971,7 @@ void TextVisual::UpdateAsyncRenderer(Text::AsyncTextParameters& parameters) return; } - if((fabsf(parameters.textWidth) < Math::MACHINE_EPSILON_1000) || (fabsf(parameters.textHeight) < Math::MACHINE_EPSILON_1000) || parameters.text.empty()) + if(!parameters.isFixedWidth && ((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);