[NUI] Fix RelativeLayout to calculate ellipsis text from line target
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Mon, 2 May 2022 09:42:20 +0000 (18:42 +0900)
committerTaehyub Kim <taehyub.kim@samsung.com>
Tue, 3 May 2022 09:00:21 +0000 (02:00 -0700)
It is commonly used that child view is positioned with its size from
line target in RelativeLayout.

If ellipsis text was positioned from line target in RelativeLayout, then
it was not positioned to the place where users intended.

e.g. Position textLabel at the bottom of parent.
     The target is the bottom line of the parent.
RelativeLayout.SetTopTarget(textLabel, parent);
RelativeLayout.SetTopRelativeOffset(textLabel, 1.0f);
RelativeLayout.SetBottomTarget(textLabel, parent);
RelativeLayout.SetBottomRelativeOffset(textLabel, 1.0f);
RelativeLayout.SetVerticalAlignment(textLabel, RelativeLayout.Alignment.End);

Previously, in the above situation, RelativeLayout could not position
ellipsis text at the bottom of the parent.
Instead, the ellipsis text was positioned outside of the parent.

Now, in the above situation, RelativeLayout position ellipsis text at
the bottom of the parent.

src/Tizen.NUI/src/public/Layouting/RelativeLayout.cs

index 08f57a8..84fcb78 100755 (executable)
@@ -393,67 +393,80 @@ namespace Tizen.NUI
                 LayoutItem childLayout = LayoutChildren[i];
                 if (childLayout != null)
                 {
-                    bool ellipsisText = false;
+                    bool ellipsisTextWidth = false;
+                    bool ellipsisTextHeight = false;
                     bool needMeasuredWidth = false;
                     bool needMeasuredHeight = false;
 
                     if (((childLayout.Owner is TextLabel textLabel) && textLabel.Ellipsis) || ((childLayout.Owner is TextField textField) && textField.Ellipsis))
                     {
-                        ellipsisText = true;
-                        needClearCache = true;
-                    }
-                    else
-                    {
-                        if (RelativeLayout.GetFillHorizontal(childLayout.Owner))
+                        Geometry horizontalSpace = GetHorizontalSpace(childLayout.Owner);
+                        if (!horizontalSpace.Size.Equals(0))
                         {
-                            needMeasuredWidth = true;
+                            ellipsisTextWidth = true;
                             needClearCache = true;
                         }
 
-                        if (RelativeLayout.GetFillVertical(childLayout.Owner))
+                        Geometry verticalSpace = GetVerticalSpace(childLayout.Owner);
+                        if (!verticalSpace.Size.Equals(0))
                         {
-                            needMeasuredHeight = true;
+                            ellipsisTextHeight = true;
                             needClearCache = true;
                         }
                     }
 
-                    if ((ellipsisText == false) && (needMeasuredWidth == false) && (needMeasuredHeight == false))
+                    if (!ellipsisTextWidth && RelativeLayout.GetFillHorizontal(childLayout.Owner))
+                    {
+                        needMeasuredWidth = true;
+                        needClearCache = true;
+                    }
+
+                    if (!ellipsisTextHeight && RelativeLayout.GetFillVertical(childLayout.Owner))
+                    {
+                        needMeasuredHeight = true;
+                        needClearCache = true;
+                    }
+
+                    if ((ellipsisTextWidth == false) && (ellipsisTextHeight == false) && (needMeasuredWidth == false) && (needMeasuredHeight == false))
                     {
                         continue;
                     }
 
                     float width = childLayout.MeasuredWidth.Size.AsDecimal();
-                    float height = childLayout.MeasuredWidth.Size.AsDecimal();
+                    float height = childLayout.MeasuredHeight.Size.AsDecimal();
 
-                    if (ellipsisText)
+                    if (ellipsisTextWidth)
                     {
                         Geometry horizontalSpace = GetHorizontalSpace(childLayout.Owner);
-
-                        if ((width > horizontalSpace.Size) || ((width < horizontalSpace.Size) && RelativeLayout.GetFillVertical(childLayout.Owner)))
+                        if (!horizontalSpace.Size.Equals(0))
                         {
-                            width = horizontalSpace.Size;
+                            if ((width > horizontalSpace.Size) || ((width < horizontalSpace.Size) && RelativeLayout.GetFillVertical(childLayout.Owner)))
+                            {
+                                width = horizontalSpace.Size;
+                            }
                         }
+                    }
+                    else if (needMeasuredWidth)
+                    {
+                        Geometry horizontalGeometry = GetHorizontalLayout(childLayout.Owner);
+                        width = horizontalGeometry.Size;
+                    }
 
+                    if (ellipsisTextHeight)
+                    {
                         Geometry verticalSpace = GetVerticalSpace(childLayout.Owner);
-
-                        if ((height > verticalSpace.Size) || ((height < verticalSpace.Size) && RelativeLayout.GetFillHorizontal(childLayout.Owner)))
+                        if (!verticalSpace.Size.Equals(0))
                         {
-                            height = verticalSpace.Size;
+                            if ((height > verticalSpace.Size) || ((height < verticalSpace.Size) && RelativeLayout.GetFillHorizontal(childLayout.Owner)))
+                            {
+                                height = verticalSpace.Size;
+                            }
                         }
                     }
-                    else
+                    else if (needMeasuredHeight)
                     {
-                        if (needMeasuredWidth)
-                        {
-                            Geometry horizontalGeometry = GetHorizontalLayout(childLayout.Owner);
-                            width = horizontalGeometry.Size;
-                        }
-
-                        if (needMeasuredHeight)
-                        {
-                            Geometry verticalGeometry = GetVerticalLayout(childLayout.Owner);
-                            height = verticalGeometry.Size;
-                        }
+                        Geometry verticalGeometry = GetVerticalLayout(childLayout.Owner);
+                        height = verticalGeometry.Size;
                     }
 
                     // Padding sizes are added because Padding sizes will be subtracted in MeasureChild().
@@ -470,12 +483,12 @@ namespace Tizen.NUI
                     int origWidthSpecification = childLayout.Owner.WidthSpecification;
                     int origHeightSpecification = childLayout.Owner.HeightSpecification;
 
-                    if (ellipsisText || needMeasuredWidth)
+                    if (ellipsisTextWidth || needMeasuredWidth)
                     {
                         origWidthSpecification = childLayout.Owner.WidthSpecification;
                         childLayout.Owner.WidthSpecification = LayoutParamPolicies.MatchParent;
                     }
-                    if (ellipsisText || needMeasuredHeight)
+                    if (ellipsisTextHeight || needMeasuredHeight)
                     {
                         origHeightSpecification = childLayout.Owner.HeightSpecification;
                         childLayout.Owner.HeightSpecification = LayoutParamPolicies.MatchParent;
@@ -483,11 +496,11 @@ namespace Tizen.NUI
 
                     MeasureChildWithMargins(childLayout, childWidthMeasureSpec, new LayoutLength(0), childHeightMeasureSpec, new LayoutLength(0));
 
-                    if (ellipsisText || needMeasuredWidth)
+                    if (ellipsisTextWidth || needMeasuredWidth)
                     {
                         childLayout.Owner.WidthSpecification = origWidthSpecification;
                     }
-                    if (ellipsisText || needMeasuredHeight)
+                    if (ellipsisTextHeight || needMeasuredHeight)
                     {
                         childLayout.Owner.HeightSpecification = origHeightSpecification;
                     }