[NUI] Fix FlexLayout OnMeasure to calculate size correctly
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Fri, 16 Dec 2022 10:11:13 +0000 (19:11 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 27 Dec 2022 05:50:29 +0000 (14:50 +0900)
Previously, the measured size of FlexLayout with WrapContent could be
calculated like MatchParent.
The above issue happened in the following case.
Tizen.NUI.Components.DialogPage.ShowAlertDialog("Title", "Message", null);

To resolve the above issue without breaking backward compatibility,
FlexLayout OnMeasure has been fixed to use ResolveSizeAndState()
instead of GetDefaultSize() when calculating the measured size.

To test the issue, showing a dialog without action button case has
been added to Tizen.NUI.StyleGuide.

src/Tizen.NUI/src/public/Layouting/FlexLayout.cs
test/Tizen.NUI.StyleGuide/Examples/DialogAndAlertDialogExample.cs

index e5c19cb..1a5e7c9 100755 (executable)
@@ -773,8 +773,16 @@ namespace Tizen.NUI
 
             NUILog.Debug("FlexLayout OnMeasure width:" + flexLayoutWidth.AsRoundedValue() + " height:" + flexLayoutHeight.AsRoundedValue());
 
-            SetMeasuredDimensions(GetDefaultSize(flexLayoutWidth, widthMeasureSpec),
-                                   GetDefaultSize(flexLayoutHeight, heightMeasureSpec));
+            // If flexLayoutWidth or flexLayoutHeight is 0,
+            // then the measured width or height can be assigned with parent's width or height.
+            // e.g. Let flexLayoutHeight be 0.
+            //      Let heightMeasureSpec.Mode be AtMost.
+            //      Then GetDefaultSize(flexLayoutHeight, heightMeasureSpec) returns the parent's height.
+            // Not to break backward compatibility of GetDefaultSize(), ResolveSizeAndState() is used instead.
+            Tizen.NUI.MeasuredSize widthMeasuredSize = ResolveSizeAndState(flexLayoutWidth, widthMeasureSpec, Tizen.NUI.MeasuredSize.StateType.MeasuredSizeOK);
+            Tizen.NUI.MeasuredSize heightMeasuredSize = ResolveSizeAndState(flexLayoutHeight, heightMeasureSpec, Tizen.NUI.MeasuredSize.StateType.MeasuredSizeOK);
+
+            SetMeasuredDimensions(widthMeasuredSize, heightMeasuredSize);
         }
 
         /// <summary>
index 6f00a9a..085a56f 100644 (file)
@@ -26,7 +26,7 @@ namespace Tizen.NUI.StyleGuide
     internal class DialogAndAlertDialogExample : ContentPage, IExample
     {
         private View rootContent;
-        private Button buttonOneAction, buttonTwoAction, buttonNoTitle, buttonNoMessage;
+        private Button buttonNoAction, buttonOneAction, buttonTwoAction, buttonNoTitle, buttonNoMessage;
 
         public void Activate()
         {
@@ -63,6 +63,19 @@ namespace Tizen.NUI.StyleGuide
                 },
             };
 
+            buttonNoAction = new Button
+            {
+                Name = "buttonNoAction",
+                Text = "Show AlertDialog without button",
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+            };
+            rootContent.Add(buttonNoAction);
+
+            buttonNoAction.Clicked += (s, e) =>
+            {
+                DialogPage.ShowAlertDialog("Title", "Message", null);
+            };
+
             buttonOneAction = new Button
             {
                 Name = "buttonOneAction",