[NUI] Change setter of property (#2298)
authorhuiyueun <35286162+huiyueun@users.noreply.github.com>
Fri, 27 Nov 2020 01:12:42 +0000 (10:12 +0900)
committerGitHub <noreply@github.com>
Fri, 27 Nov 2020 01:12:42 +0000 (10:12 +0900)
* [NUI] Change setter of property

- Setter is deprecated in API8.(Size/Scale/Color/Position)
- An unnecessary log comes out and causes performance degradation.

Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
* [NUI] Modify comment

Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
12 files changed:
src/Tizen.NUI.Components/Controls/DropDown.cs
src/Tizen.NUI.Components/Controls/FlexibleView/FlexibleViewLayoutManager.cs
src/Tizen.NUI.Components/Controls/Popup.cs
src/Tizen.NUI.Components/Controls/Tab.cs
src/Tizen.NUI.Components/Controls/Toast.cs
src/Tizen.NUI.Wearable/src/public/CircularPagination.cs
src/Tizen.NUI.Wearable/src/public/Title.cs
src/Tizen.NUI/src/public/BaseComponents/Style/ViewStyleBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/Color.cs
src/Tizen.NUI/src/public/VisualMaps.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ViewSizeWidthPropertySetTest.cs

index 97afcec..e9c3a56 100755 (executable)
@@ -562,7 +562,7 @@ namespace Tizen.NUI.Components
             }
             float fitWidth = (Button.Icon.Size?.Width ?? 48) + dropDownStyle.SpaceBetweenButtonTextAndIcon + buttonTextWidth;
             fitWidth += (button.IconPadding.Start + button.IconPadding.End);
-            button.Size.Width = Math.Max(button.Size.Width, fitWidth);
+            button.SizeWidth = Math.Max(button.Size.Width, fitWidth);
             RelayoutRequest();
 
             int numberOfItemsToAdd = adapter.GetItemCount();
index a7b3a01..e78a1e9 100755 (executable)
@@ -759,7 +759,6 @@ namespace Tizen.NUI.Components
          */
         private Vector2 GetRectOfVisibleChildScrollAmount(FlexibleView parent, FlexibleViewViewHolder child)
         {
-            Vector2 ret = new Vector2(0, 0);
             int parentLeft = PaddingLeft;
             int parentTop = PaddingTop;
             int parentRight = (int)Width - PaddingRight;
@@ -775,13 +774,9 @@ namespace Tizen.NUI.Components
                                          (ushort)Math.Max(0, childBottom - parentBottom));
 
             int dx = offset.Start != 0 ? offset.Start : Math.Min(childLeft - parentLeft, offset.End);
-
             int dy = offset.Top != 0 ? offset.Top : Math.Min(childTop - parentTop, offset.Bottom);
 
-            ret.X = -dx;
-            ret.Y = -dy;
-
-            return ret;
+            return new Vector2(-dx, -dy);
         }
 
         private void OnScrollAnimationFinished(object sender, EventArgs e)
index 87103f7..25c451e 100755 (executable)
@@ -37,7 +37,7 @@ namespace Tizen.NUI.Components
             var instance = (Popup)bindable;
             if (newValue != null && instance?.popupStyle?.Buttons?.Size != null )
             {
-                instance.popupStyle.Buttons.Size.Height = (int)newValue;
+                instance.popupStyle.Buttons.SizeHeight = (int)newValue;
                 instance.btGroup.Itemheight = (int)newValue;
                 instance.UpdateView();
             }
@@ -488,7 +488,7 @@ namespace Tizen.NUI.Components
             {
                 if (popupStyle?.Title?.Size != null)
                 {
-                    popupStyle.Title.Size.Height = value;
+                    popupStyle.Title.SizeHeight = value;
                 }
             }
         }
index df33271..82499a7 100755 (executable)
@@ -527,8 +527,8 @@ namespace Tizen.NUI.Components
                     for (int i = 0; i < totalNum; i++)
                     {
                         preW = (itemList[i].TextItem.NaturalSize2D != null ? itemList[i].TextItem.NaturalSize2D.Width : 0);
-                        itemList[i].Position2D.X = preX;
-                        itemList[i].Size2D.Width = preW;
+                        itemList[i].PositionX = preX;
+                        itemList[i].SizeWidth = preW;
                         preX = itemList[i].Position2D.X + preW + itemSpace;
                         itemList[i].Index = i;
                     }
@@ -538,8 +538,8 @@ namespace Tizen.NUI.Components
                     preW = (Size2D.Width - (int)tabStyle?.ItemPadding.Start - (int)tabStyle?.ItemPadding.End) / totalNum;
                     for (int i = 0; i < totalNum; i++)
                     {
-                        itemList[i].Position2D.X = preX;
-                        itemList[i].Size2D.Width = preW;
+                        itemList[i].PositionX = preX;
+                        itemList[i].SizeWidth = preW;
                         preX = itemList[i].Position2D.X + preW + itemSpace;
                         itemList[i].Index = i;
                     }
@@ -554,8 +554,8 @@ namespace Tizen.NUI.Components
                     for (int i = 0; i < totalNum; i++)
                     {
                         preW = (itemList[i].NaturalSize2D != null ? itemList[i].NaturalSize2D.Width : 0);
-                        itemList[i].Position2D.X = w - preW - preX;
-                        itemList[i].Size2D.Width = preW;
+                        itemList[i].PositionX = w - preW - preX;
+                        itemList[i].SizeWidth = preW;
                         preX = w - itemList[i].Position2D.X + itemSpace;
                         itemList[i].Index = i;
                     }
@@ -565,8 +565,8 @@ namespace Tizen.NUI.Components
                     preW = (Size2D.Width - (int)tabStyle?.ItemPadding.Start - (int)tabStyle?.ItemPadding.End) / totalNum;
                     for (int i = totalNum - 1; i >= 0; i--)
                     {
-                        itemList[i].Position2D.X = preX;
-                        itemList[i].Size2D.Width = preW;
+                        itemList[i].PositionX = preX;
+                        itemList[i].SizeWidth = preW;
                         preX = itemList[i].Position2D.X + preW + itemSpace;
                         itemList[i].Index = i;
                     }
@@ -599,8 +599,8 @@ namespace Tizen.NUI.Components
             item.TextItem.ApplyStyle(tabStyle.Text);
 
             item.Text = itemData.Text;
-            item.Size2D.Height = Size2D.Height - h - topSpace;
-            item.Position2D.Y = topSpace;
+            item.SizeHeight = SizeHeight - h - topSpace;
+            item.PositionY = topSpace;
             item.TouchEvent += ItemTouchEvent;
             Add(item);
 
@@ -648,7 +648,7 @@ namespace Tizen.NUI.Components
                 return;
             }
 
-            Underline.Size.Width = itemList[curIndex].Size2D.Width;
+            Underline.SizeWidth = itemList[curIndex].Size2D.Width;
 
             underline.Size2D = new Size2D(itemList[curIndex].Size2D.Width, (int)Underline.Size.Height);
             underline.BackgroundColor = tabStyle.UnderLine.BackgroundColor.All;
@@ -665,7 +665,7 @@ namespace Tizen.NUI.Components
             }
             else
             {
-                underline.Position2D.X = itemList[curIndex].Position2D.X;
+                underline.PositionX = itemList[curIndex].PositionX;
                 isNeedAnimation = true;
             }
 
index e861c49..5424d21 100755 (executable)
@@ -237,8 +237,8 @@ namespace Tizen.NUI.Components
         {
             window = win;
             window.Add(this);
-            this.Position.X = (window.Size.Width - this.Size.Width) / 2;
-            this.Position.Y = (window.Size.Height - this.Size.Height) / 2;
+            this.PositionX = (window.Size.Width - this.Size.Width) / 2;
+            this.PositionY = (window.Size.Height - this.Size.Height) / 2;
             timer.Start();
         }
 
index c7217fa..c9e0436 100755 (executable)
@@ -482,11 +482,16 @@ namespace Tizen.NUI.Wearable
         /// </summary>
         /// <param name="index">Indicator index</param>
         /// <param name="position">The position of a indicator by index</param>
+        /// <exception cref="ArgumentNullException">This exception can occur by the position is null.</exception>
         /// <since_tizen> 8 </since_tizen>
         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
         public virtual void SetIndicatorPosition(int index, Position position)
         {
+            if (position == null)
+            {
+                throw new ArgumentNullException(nameof(position));
+            }
             // Update odd / even Array and List by each converted index.
             if (isOddNumber)
             {
@@ -498,14 +503,12 @@ namespace Tizen.NUI.Wearable
                 {
                     oddArray[(middleIndex - leftIndicatorCount) + index] = position;
                 }
-                indicatorList[index].Position.X = position.X;
-                indicatorList[index].Position.Y = position.Y;
+                indicatorList[index].Position = new Vector2(position.X, position.Y);
             }
             else // Only symmetry circular pagination can be even number.
             {
                 evenArray[(middleIndex - (indicatorCount / 2) + index)] = position;
-                indicatorList[index].Position.X = position.X;
-                indicatorList[index].Position.Y = position.Y;
+                indicatorList[index].Position = new Vector2(position.X, position.Y);
             }
             UpdateVisual();
         }
index c6f7265..c03dbbb 100755 (executable)
@@ -183,8 +183,8 @@ namespace Tizen.NUI.Components
 
         private void UpdateImage()
         {
-            leftImage.Size.Width = fadeOutWidth;
-            rightImage.Size.Width = fadeOutWidth;
+            leftImage.SizeWidth = fadeOutWidth;
+            rightImage.SizeWidth = fadeOutWidth;
 
             if (fadeOutWidth > 0)
             {
index afe4a2f..c0e91a3 100755 (executable)
@@ -327,9 +327,8 @@ namespace Tizen.NUI.BaseComponents
                 if (viewStyle.size == null)
                 {
                     if ((float)newValue == 0) return;
-                    viewStyle.size = new Size();
                 }
-                viewStyle.size.Width = (float)newValue;
+                viewStyle.size = new Size((float)newValue, viewStyle.size?.Height ?? 0);
             }
         },
         defaultValueCreator: (bindable) =>
@@ -346,9 +345,8 @@ namespace Tizen.NUI.BaseComponents
                 if (viewStyle.size == null)
                 {
                     if ((float)newValue == 0) return;
-                    viewStyle.size = new Size();
                 }
-                viewStyle.size.Height = (float)newValue;
+                viewStyle.size = new Size(viewStyle.size?.Width ?? 0, (float)newValue);
             }
         },
         defaultValueCreator: (bindable) =>
@@ -381,9 +379,8 @@ namespace Tizen.NUI.BaseComponents
                 if (viewStyle.position == null)
                 {
                     if ((float)newValue == 0) return;
-                    viewStyle.position = new Position();
                 }
-                viewStyle.position.X = (float)newValue;
+                viewStyle.position = new Position((float)newValue, viewStyle.position?.Y ?? 0);
             }
         },
         defaultValueCreator: (bindable) =>
@@ -400,9 +397,8 @@ namespace Tizen.NUI.BaseComponents
                 if (viewStyle.position == null)
                 {
                     if ((float)newValue == 0) return;
-                    viewStyle.position = new Position();
                 }
-                viewStyle.position.Y = (float)newValue;
+                viewStyle.position = new Position(viewStyle.position?.X ?? 0, (float)newValue);
             }
         },
         defaultValueCreator: (bindable) =>
@@ -419,9 +415,8 @@ namespace Tizen.NUI.BaseComponents
                 if (viewStyle.position == null)
                 {
                     if ((float)newValue == 0) return;
-                    viewStyle.position = new Position();
                 }
-                viewStyle.position.Z = (float)newValue;
+                viewStyle.position = new Position(viewStyle.Position?.X ?? 0, viewStyle.Position?.Y ?? 0, (float)newValue);
             }
         },
         defaultValueCreator: (bindable) =>
@@ -463,9 +458,8 @@ namespace Tizen.NUI.BaseComponents
                 if (viewStyle.scale == null)
                 {
                     if ((float)newValue == 1.0f) return;
-                    viewStyle.scale = new Vector3();
                 }
-                viewStyle.scale.X = (float)newValue;
+                viewStyle.scale = new Vector3((float)newValue, viewStyle.scale?.Y ?? 0, viewStyle.scale?.Z ?? 0);
             }
         },
         defaultValueCreator: (bindable) =>
@@ -482,9 +476,8 @@ namespace Tizen.NUI.BaseComponents
                 if (viewStyle.scale == null)
                 {
                     if ((float)newValue == 1.0f) return;
-                    viewStyle.scale = new Vector3();
                 }
-                viewStyle.scale.Y = (float)newValue;
+                viewStyle.scale = new Vector3(viewStyle.scale?.X ?? 0, (float)newValue, viewStyle.scale?.Z ?? 0);
             }
         },
         defaultValueCreator: (bindable) =>
@@ -501,9 +494,8 @@ namespace Tizen.NUI.BaseComponents
                 if (viewStyle.scale == null)
                 {
                     if ((float)newValue == 1.0f) return;
-                    viewStyle.scale = new Vector3();
                 }
-                viewStyle.scale.Z = (float)newValue;
+                viewStyle.scale = new Vector3(viewStyle.scale?.X ?? 0, viewStyle.scale?.Y ?? 0, (float)newValue);
             }
         },
         defaultValueCreator: (bindable) =>
index 23a00b6..bc48681 100755 (executable)
@@ -767,14 +767,16 @@ namespace Tizen.NUI.BaseComponents
             get
             {
                 Size2D temp = (Size2D)GetValue(Size2DProperty);
+                int width = temp.Width;
+                int height = temp.Height;
 
                 if (this.Layout == null)
                 {
-                    if (temp.Width < 0) { temp.Width = 0; }
-                    if (temp.Height < 0) { temp.Height = 0; }
+                    if (width < 0) { width = 0; }
+                    if (height < 0) { height = 0; }
                 }
 
-                return new Size2D(OnSize2DChanged, temp.Width, temp.Height);
+                return new Size2D(OnSize2DChanged, width, height);
             }
             set
             {
index 4509fcc..11ba75c 100755 (executable)
@@ -484,46 +484,52 @@ namespace Tizen.NUI
 
         internal static Color ValueCheck(Color color)
         {
-            if (color.R < 0.0f)
+            float r = color.R;
+            float g = color.G;
+            float b = color.B;
+            float a = color.A;
+
+            if (r < 0.0f)
             {
-                color.R = 0.0f;
+                r = 0.0f;
                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
             }
-            else if (color.R > 1.0f)
+            else if (r > 1.0f)
             {
-                color.R = 1.0f;
+                r = 1.0f;
                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
             }
-            if (color.G < 0.0f)
+            if (g < 0.0f)
             {
-                color.G = 0.0f;
+                g = 0.0f;
                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
             }
-            else if (color.G > 1.0f)
+            else if (g > 1.0f)
             {
-                color.G = 1.0f;
+                g = 1.0f;
                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
             }
-            if (color.B < 0.0f)
+            if (b < 0.0f)
             {
-                color.B = 0.0f;
+                b = 0.0f;
                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
             }
-            else if (color.B > 1.0f)
+            else if (b > 1.0f)
             {
-                color.B = 1.0f;
+                b = 1.0f;
                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
             }
-            if (color.A < 0.0f)
+            if (a < 0.0f)
             {
-                color.A = 0.0f;
+                a = 0.0f;
                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
             }
-            else if (color.A > 1.0f)
+            else if (a > 1.0f)
             {
-                color.A = 1.0f;
+                a = 1.0f;
                 NUILog.Error("The value of Result is invalid! Should be between [0, 1].");
             }
+            color = new Color(r, g, b, a);
             return color;
         }
 
index c5d63a3..6ee9e4a 100755 (executable)
@@ -236,23 +236,21 @@ namespace Tizen.NUI
             }
             set
             {
-                if (_visualOffsetPolicy == null)
-                {
-                    _visualOffsetPolicy = new Vector2(0.0f, 0.0f);
-                }
+                float x = 0.0f;
 
                 switch (value)
                 {
                     case VisualTransformPolicyType.Relative:
-                        _visualOffsetPolicy.X = 0.0f;
+                        x = 0.0f;
                         break;
                     case VisualTransformPolicyType.Absolute:
-                        _visualOffsetPolicy.X = 1.0f;
+                        x = 1.0f;
                         break;
                     default:
-                        _visualOffsetPolicy.X = 0.0f;
+                        x = 0.0f;
                         break;
                 }
+                _visualOffsetPolicy = new Vector2(x, _visualOffsetPolicy?.Y ?? 0);
 
                 UpdateVisual();
             }
@@ -277,23 +275,21 @@ namespace Tizen.NUI
             }
             set
             {
-                if (_visualOffsetPolicy == null)
-                {
-                    _visualOffsetPolicy = new Vector2(0.0f, 0.0f);
-                }
+                float y = 0.0f;
 
                 switch (value)
                 {
                     case VisualTransformPolicyType.Relative:
-                        _visualOffsetPolicy.Y = 0.0f;
+                        y = 0.0f;
                         break;
                     case VisualTransformPolicyType.Absolute:
-                        _visualOffsetPolicy.Y = 1.0f;
+                        y = 1.0f;
                         break;
                     default:
-                        _visualOffsetPolicy.Y = 0.0f;
+                        y = 0.0f;
                         break;
                 }
+                _visualOffsetPolicy = new Vector2(_visualOffsetPolicy?.X ?? 0, y);
                 UpdateVisual();
             }
         }
@@ -353,23 +349,21 @@ namespace Tizen.NUI
             }
             set
             {
-                if (_visualSizePolicy == null)
-                {
-                    _visualSizePolicy = new Vector2(0.0f, 0.0f);
-                }
-
+                float width = 0.0f;
                 switch (value)
                 {
                     case VisualTransformPolicyType.Relative:
-                        _visualSizePolicy.Width = 0.0f;
+                        width = 0.0f;
                         break;
                     case VisualTransformPolicyType.Absolute:
-                        _visualSizePolicy.Width = 1.0f;
+                        width = 1.0f;
                         break;
                     default:
-                        _visualSizePolicy.Width = 0.0f;
+                        width = 0.0f;
                         break;
                 }
+
+                _visualSizePolicy = new Vector2(width, _visualSizePolicy?.Height ?? 0);
                 UpdateVisual();
             }
         }
@@ -393,23 +387,21 @@ namespace Tizen.NUI
             }
             set
             {
-                if (_visualSizePolicy == null)
-                {
-                    _visualSizePolicy = new Vector2(0.0f, 0.0f);
-                }
+                float height = 0.0f;
 
                 switch (value)
                 {
                     case VisualTransformPolicyType.Relative:
-                        _visualSizePolicy.Height = 0.0f;
+                        height = 0.0f;
                         break;
                     case VisualTransformPolicyType.Absolute:
-                        _visualSizePolicy.Height = 1.0f;
+                        height = 1.0f;
                         break;
                     default:
-                        _visualSizePolicy.Height = 0.0f;
+                        height = 0.0f;
                         break;
                 }
+                _visualSizePolicy = new Vector2(_visualSizePolicy?.Width ?? 0, height);
                 UpdateVisual();
             }
         }
index a75b8f4..f3eb220 100755 (executable)
@@ -58,11 +58,11 @@ namespace Tizen.NUI.Samples
             {
                 if (e.Key.KeyPressedName == "1")
                 {
-                    view1.Size2D.Width += 10;
+                    view1.SizeWidth += 10;
                 }
                 else if (e.Key.KeyPressedName == "2")
                 {
-                    view1.Size2D.Height += 10;
+                    view1.SizeHeight += 10;
                 }
                 else if (e.Key.KeyPressedName == "3")
                 {
@@ -88,10 +88,14 @@ namespace Tizen.NUI.Samples
                 {
                     view1.MaximumSize.Width = 70;
                 }
+                else if (e.Key.KeyPressedName == "9")
+                {
+                    view1.Size += new Size(10, 10);
+                }
                 else if (e.Key.KeyPressedName == "0")
                 {
-                    view1.Size2D.Width -= 10;
-                    view1.Size2D.Height -= 10;
+                    view1.SizeWidth -= 10;
+                    view1.SizeHeight -= 10;
                 }
             }
         }
@@ -103,6 +107,7 @@ namespace Tizen.NUI.Samples
                 string log = "";
                 log += $"view1 Size2D=({view1.Size2D.Width}, {view1.Size2D.Height}) \n";
                 log += $"SizeWidth={view1.SizeWidth}, SizeHeight={view1.SizeHeight} \n";
+                log += $"Size={view1.Size.Width}, SizeHeight={view1.Size.Height} \n";
                 log += $"WidthResizePolicy={view1.WidthResizePolicy}, HeightResizePolicy={view1.HeightResizePolicy} \n";
                 log += $"WidthSpecification={view1.WidthSpecification}, HeightSpecification={view1.HeightSpecification} \n";
                 log += $"MinimumSize=({view1.MinimumSize.Width}, {view1.MinimumSize.Height}) \n";