Prevent negative content size in async text method
authorBowon Ryu <bowon.ryu@samsung.com>
Thu, 25 Jul 2024 04:00:24 +0000 (13:00 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Thu, 25 Jul 2024 04:00:24 +0000 (13:00 +0900)
Change-Id: If2ec8498fc071c83f0571cee3ad81d7ba822fa32
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp

index d5599ed..d94339d 100644 (file)
@@ -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<Extents>(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<Extents>(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<Extents>(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);