[NUI] Fix height calculation of TextLabelLayout
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 1 Apr 2025 09:45:38 +0000 (18:45 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Thu, 12 Jun 2025 07:37:40 +0000 (16:37 +0900)
When the label's HeightSpecification is wrap content,
the result of GetHeightForWidth() is used to calculate the text height.

The previous behavior simply used NaturalSize,
so it could not guarantee the behavior of the case below.

```
var label = new TextLabel
{
    Text = "Something long long text...",
    WidthSpecification = LayoutParamPolicies.WrapContent,
    HeightSpecification = LayoutParamPolicies.WrapContent,
    MaximumSize = new Size(400, 400),
    Padding = new Extents(25, 25, 10, 10),
    MultiLine = true,
};
```

Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs

index 6adbc05a52e51209cfbd50e290cbf9c30bbbb409..8db0644856e7462c4cbb721f6cbc0e2e63ae62f3 100755 (executable)
@@ -45,7 +45,8 @@ namespace Tizen.NUI.BaseComponents
                 {
                     if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
                     {
-                        totalHeight = Owner.GetHeightForWidth(totalWidth);
+                        var padding = Owner.Padding;
+                        totalHeight = Owner.GetHeightForWidth(totalWidth - (padding.Start + padding.End));
                         heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
                     }
                 }
@@ -65,8 +66,11 @@ namespace Tizen.NUI.BaseComponents
                     else
                     {
                         float width = naturalSize != null ? naturalSize.Width : 0;
-                        float height = naturalSize != null ? naturalSize.Height : 0;
+                        // Since priority of MinimumSize is higher than MaximumSize in DALi, here follows it.
                         totalWidth = Math.Min(Math.Max(width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
+
+                        var padding = Owner.Padding;
+                        float height = Owner.GetHeightForWidth(totalWidth - (padding.Start + padding.End));
                         totalHeight = Math.Min(Math.Max(height, minSize.Height), (maxSize.Height < 0 ? Int32.MaxValue : maxSize.Height));
 
                         heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);