From df3751db31283c05bfadf2f0963b5052ff2de462 Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Thu, 25 Jul 2024 13:00:24 +0900 Subject: [PATCH] Prevent negative content size in async text method Change-Id: If2ec8498fc071c83f0571cee3ad81d7ba822fa32 Signed-off-by: Bowon Ryu --- .../controls/text-controls/text-label-impl.cpp | 42 ++++++++++------------ 1 file changed, 18 insertions(+), 24 deletions(-) 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 d5599ed..d94339d 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -1884,9 +1884,9 @@ void TextLabel::EnableControlBackground(const bool enable) void TextLabel::RequestAsyncNaturalSize() { - Actor self = Self(); - Extents padding(0u, 0u, 0u, 0u); - Vector2 contentSize(0.0f, 0.0f); + Actor self = Self(); + Extents padding; + Size contentSize = Size::ZERO; Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self); AsyncTextParameters parameters = GetAsyncTextParameters(Async::COMPUTE_NATURAL_SIZE, contentSize, padding, layoutDirection); @@ -1895,9 +1895,9 @@ void TextLabel::RequestAsyncNaturalSize() void TextLabel::RequestAsyncHeightForWidth(float width) { - Actor self = Self(); - Extents padding(0u, 0u, 0u, 0u); - Vector2 contentSize(width, 0.0f); + Actor self = Self(); + Extents padding; + Size contentSize(width, 0.0f); Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self); AsyncTextParameters parameters = GetAsyncTextParameters(Async::COMPUTE_HEIGHT_FOR_WIDTH, contentSize, padding, layoutDirection); @@ -1914,17 +1914,15 @@ void TextLabel::RequestAsyncRenderWithFixedSize(float width, float height) return; } - Actor self = Self(); - + Actor self = Self(); Extents padding; padding = self.GetProperty(Toolkit::Control::Property::PADDING); - Vector2 contentSize(width - (padding.start + padding.end), height - (padding.top + padding.bottom)); + float contentWidth = std::max(width - (padding.start + padding.end), 0.0f); + float contentHeight = std::max(height - (padding.top + padding.bottom), 0.0f); + Size contentSize(contentWidth, contentHeight); - // 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); @@ -1948,17 +1946,15 @@ void TextLabel::RequestAsyncRenderWithFixedWidth(float width, float heightConstr return; } - Actor self = Self(); - + Actor self = Self(); Extents padding; padding = self.GetProperty(Toolkit::Control::Property::PADDING); - Vector2 contentSize(width - (padding.start + padding.end), heightConstraint - (padding.top + padding.bottom)); + float contentWidth = std::max(width - (padding.start + padding.end), 0.0f); + float contentHeightConstraint = std::max(heightConstraint - (padding.top + padding.bottom), 0.0f); + Size contentSize(contentWidth, contentHeightConstraint); - // 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); @@ -1982,17 +1978,15 @@ void TextLabel::RequestAsyncRenderWithConstraint(float widthConstraint, float he return; } - Actor self = Self(); - + Actor self = Self(); Extents padding; padding = self.GetProperty(Toolkit::Control::Property::PADDING); - Vector2 contentSize(widthConstraint - (padding.start + padding.end), heightConstraint - (padding.top + padding.bottom)); + float contentWidthConstraint = std::max(widthConstraint - (padding.start + padding.end), 0.0f); + float contentHeightConstraint = std::max(heightConstraint - (padding.top + padding.bottom), 0.0f); + Size contentSize(contentWidthConstraint, contentHeightConstraint); - // 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); -- 2.7.4