[NUI] TextLayout can consider specified maximum width. (#2774)
authorJiyun Yang <ji.yang@samsung.com>
Tue, 23 Mar 2021 07:05:10 +0000 (16:05 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 30 Mar 2021 06:51:02 +0000 (15:51 +0900)
Previsouly, the Layout system did not reflect TextLabel's maximum size, so the following example did't work corrrectly,

```C#
  var view = new View()
  {
    Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, },
  };
  view.Add(new TextLabel() { MaximumSize = new Size2D(50, 50), Text = "Helloooooooooooooooooo!" });
  view.Add(new TextLabel() { MaximumSize = new Size2D(50, 50), Text = "Helloooooooooooooooooo!" });
  NUIApplication.GetDefaultWindow().Add(view);
```

The x-position of the second child was calculated based on the first child's natutal width,
but the first child's actual width was limited by MaximumSize(50).

So this patch update the TextLabel's layout to make it consider the maxmimum size of the view.

Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
Co-authored-by: huiyueun <35286162+huiyueun@users.noreply.github.com>
src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs

index d8271bf..a083b83 100755 (executable)
@@ -49,17 +49,20 @@ namespace Tizen.NUI.BaseComponents
                 }
                 else
                 {
+                    var minSize = Owner.MinimumSize;
+                    var maxSize = Owner.MaximumSize;
+                    var naturalSize = Owner.GetNaturalSize();
+
                     if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
                     {
                         // GetWidthForHeight is not implemented.
-                        totalWidth = Owner.GetNaturalSize().Width;
+                        totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
                         widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
                     }
                     else
                     {
-                        Vector3 naturalSize = Owner.GetNaturalSize();
-                        totalWidth = naturalSize.Width;
-                        totalHeight = naturalSize.Height;
+                        totalWidth = Math.Min(Math.Max(naturalSize.Width, minSize.Width), (maxSize.Width < 0 ? Int32.MaxValue : maxSize.Width));
+                        totalHeight = Math.Min(Math.Max(naturalSize.Height, minSize.Height), (maxSize.Height < 0 ? Int32.MaxValue : maxSize.Height));
 
                         heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
                         widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);