[NUI] Ignore ResizePolicy when View size is calculated by Layout
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Thu, 28 Oct 2021 10:19:47 +0000 (19:19 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 9 Nov 2021 05:57:53 +0000 (14:57 +0900)
View size is calculated based on Width/HeightSpecification if View's
Layout is set.

However, if View's ResizePolicy is not UseNaturalSize (default value),
then View's ResizePolicy also affects View size calculation in DALi
although View's Layout is set.

To ignore ResizePolicy when View size is calculated by View's Layout,
ResizePolicy is set with FIXED when View's Layout is set.

ResizePolicy is stored when Layout is set and it is ignored when View
size is calculated.
ResizePolicy is restored when Layout is unset and it is considered when
View size is calculated.

src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs

index 6746df1..1829836 100755 (executable)
@@ -1856,6 +1856,9 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
+                // Store ResizePolicy to restore it when Layout is unset.
+                widthResizePolicy = value;
+
                 SetValue(WidthResizePolicyProperty, value);
                 NotifyPropertyChanged();
             }
@@ -1873,6 +1876,9 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
+                // Store ResizePolicy to restore it when Layout is unset.
+                heightResizePolicy = value;
+
                 SetValue(HeightResizePolicyProperty, value);
                 NotifyPropertyChanged();
             }
@@ -2549,6 +2555,13 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
+                // ResizePolicy is restored when Layout is unset and it is considered when View size is calculated.
+                // SetValue(LayoutProperty, value) sets InternalLayout only if layout is not null.
+                if (value == null)
+                {
+                    RestoreResizePolicy();
+                }
+
                 SetValue(LayoutProperty, value);
             }
         }
index 4905a60..0c6c021 100755 (executable)
@@ -31,6 +31,14 @@ namespace Tizen.NUI.BaseComponents
     public partial class View
     {
         private MergedStyle mergedStyle = null;
+
+        // Ignore WidthResizePolicy and HeightResizePolicy when Layout is set.
+        // Restore WidthResizePolicy and HeightResizePolicy when Layout is unset.
+        // See also IgnoreResizePolicy() and RestoreResizePolicy().
+        private ResizePolicyType widthResizePolicy = ResizePolicyType.Fixed;
+        private ResizePolicyType heightResizePolicy = ResizePolicyType.Fixed;
+        private bool isIgnoredResizePolicy = false;
+
         internal string styleName;
 
         internal MergedStyle MergedStyle
@@ -189,6 +197,17 @@ namespace Tizen.NUI.BaseComponents
 
         internal void SetLayout(LayoutItem layout)
         {
+            // ResizePolicy is restored when Layout is unset and it is considered when View size is calculated.
+            if (layout == null)
+            {
+                RestoreResizePolicy();
+            }
+            // ResizePolicy is stored when Layout is set and it is ignored when View size is calculated.
+            else
+            {
+                IgnoreResizePolicy();
+            }
+
             Window.Instance.LayoutController.CreateProcessCallback();
             this.layout = layout;
             this.layout?.AttachToOwner(this);
@@ -1010,6 +1029,8 @@ namespace Tizen.NUI.BaseComponents
         /// </summary>
         internal void ResetLayout()
         {
+            // ResizePolicy is restored when Layout is unset and it is considered when View size is calculated.
+            RestoreResizePolicy();
             layout = null;
         }
 
@@ -1464,5 +1485,32 @@ namespace Tizen.NUI.BaseComponents
 
             return themeData.selectorData ?? (themeData.selectorData = new ViewSelectorData());
         }
+
+        // ResizePolicy is stored when Layout is set and it is ignored when View size is calculated.
+        private void IgnoreResizePolicy()
+        {
+            if (isIgnoredResizePolicy) return;
+            isIgnoredResizePolicy = true;
+
+            widthResizePolicy = WidthResizePolicy;
+            heightResizePolicy = HeightResizePolicy;
+
+            // Set bindable property directly not to store width/heightResizePolicy duplicately.
+            SetValue(WidthResizePolicyProperty, ResizePolicyType.Fixed);
+            SetValue(HeightResizePolicyProperty, ResizePolicyType.Fixed);
+            NotifyPropertyChanged();
+        }
+
+        // ResizePolicy is restored when Layout is unset and it is considered when View size is calculated.
+        private void RestoreResizePolicy()
+        {
+            if (!isIgnoredResizePolicy) return;
+            isIgnoredResizePolicy = false;
+
+            // Set bindable property directly not to store width/heightResizePolicy duplicately.
+            SetValue(WidthResizePolicyProperty, widthResizePolicy);
+            SetValue(HeightResizePolicyProperty, heightResizePolicy);
+            NotifyPropertyChanged();
+        }
     }
 }