From 9f547926fb51d814c2d13ee59c548249dd1031ca Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Tue, 23 Mar 2021 16:05:10 +0900 Subject: [PATCH] [NUI] TextLayout can consider specified maximum width. (#2774) 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 Co-authored-by: huiyueun <35286162+huiyueun@users.noreply.github.com> --- src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs index d8271bf..a083b83 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs @@ -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); -- 2.7.4