[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>
Tue, 1 Apr 2025 11:52:37 +0000 (20:52 +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 05c5e5751dd142e5a48e7e0511103aeddb08afb6..8e8a3c96801654fdc4538ac300501bb7a6214e2f 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);
                     }
                 }
@@ -68,9 +69,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.Max(Math.Min(width, maxWidth < 0 ? Int32.MaxValue : maxWidth), minWidth);
+
+                        var padding = Owner.Padding;
+                        float height = Owner.GetHeightForWidth(totalWidth - (padding.Start + padding.End));
                         totalHeight = Math.Max(Math.Min(height, maxHeight < 0 ? Int32.MaxValue : maxHeight), minHeight);
 
                         heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);