[NUI] Apply sibling patch (#79) 4.0.1-preview1-00068
authorhuiyueun <35286162+huiyueun@users.noreply.github.com>
Thu, 25 Jan 2018 04:44:48 +0000 (13:44 +0900)
committerGitHub <noreply@github.com>
Thu, 25 Jan 2018 04:44:48 +0000 (13:44 +0900)
* [NUI] Fix sibling issue

This reverts commit c52e414d9473f1ec744bb30eeed0bed033eec2dc.

* [NUI]Fix bug about Children property.

This reverts commit 5f2fa0f0e7bc26eed46b38431f6b702cc396e52f.

* [NUI] Fix SiblingOrder return value

This reverts commit 83d9228a204bccef4f9cd7b8d5927c869d8e41b4.

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

index 41668b2..0e3ae04 100755 (executable)
@@ -49,11 +49,18 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 4 </since_tizen>
         public override void Add(View child)
         {
-            NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-
-            Children.Add(child);
+            Container oldParent = child.Parent;
+            if(oldParent != this)
+            {
+                if (oldParent != null)
+                {
+                    oldParent.Remove(child);
+                }
+                NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
+                if (NDalicPINVOKE.SWIGPendingException.Pending)
+                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                Children.Add(child);
+            }
         }
 
         /// <summary>
@@ -2248,13 +2255,54 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                int temp = 0;
-                GetProperty(View.Property.SIBLING_ORDER).Get(out temp);
-                return temp;
+                var parentChildren = Parent?.Children;
+                int currentOrder = 0;
+                if (parentChildren != null)
+                {
+                    currentOrder = parentChildren.IndexOf(this);
+
+                    if (currentOrder < 0)
+                    {
+                        return 0;
+                    }
+                    else if (currentOrder < parentChildren.Count)
+                    {
+                        return currentOrder;
+                    }
+                }
+
+                return 0;
             }
             set
             {
-                SetProperty(View.Property.SIBLING_ORDER, new Tizen.NUI.PropertyValue(value));
+                var siblings = Parent?.Children;
+                if (siblings != null)
+                {
+                    int currentOrder = siblings.IndexOf(this);
+
+                    if (value != currentOrder)
+                    {
+                        if (value == 0)
+                        {
+                            LowerToBottom();
+                        }
+                        else if (value < siblings.Count - 1)
+                        {
+                            if (value > currentOrder)
+                            {
+                                RaiseAbove(siblings[value]);
+                            }
+                            else
+                            {
+                                LowerBelow(siblings[value]);
+                            }
+                        }
+                        else
+                        {
+                            RaiseToTop();
+                        }
+                    }
+                }
             }
         }
 
@@ -3696,6 +3744,22 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+
+        /// <summary>
+        /// [Obsolete("Please do not use! this will be deprecated. Please use Visibility instead.")]
+        /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Please do not use! This will be deprecated! Please use Visibility instead!")]
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool Visible
+        {
+            get
+            {
+                return IsVisible();
+            }
+        }
+
+
         /// <summary>
         /// Gets the view's world color.
         /// </summary>
index 8fee27b..9264686 100755 (executable)
@@ -50,11 +50,18 @@ namespace Tizen.NUI
         /// <since_tizen> 4 </since_tizen>
         public override void Add(View child)
         {
-            NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-
-            Children.Add(child);
+            Container oldParent = child.GetParent();
+            if (oldParent != this)
+            {
+                if (oldParent != null)
+                {
+                    oldParent.Remove(child);
+                }
+                NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
+                if (NDalicPINVOKE.SWIGPendingException.Pending)
+                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                Children.Add(child);
+            }
         }
 
         /// <summary>
@@ -263,6 +270,8 @@ namespace Tizen.NUI
                     parentChildren[currentIdx] = temp;
                 }
             }
+            NDalicPINVOKE.Layer_Raise(swigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         /// <summary>
@@ -286,16 +295,46 @@ namespace Tizen.NUI
 
                 }
             }
+            NDalicPINVOKE.Layer_Lower(swigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         internal void RaiseAbove(Layer target)
         {
+            var parentChildren = Window.Instance.LayersChildren;
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+                int targetIndex = parentChildren.IndexOf(target);
+
+                // If the currentIndex is less than the target index and the target has the same parent.
+                if (currentIndex < targetIndex)
+                {
+                    parentChildren.Remove(this);
+                    parentChildren.Insert(targetIndex, this);
+                }
+            }
             NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         internal void LowerBelow(Layer target)
         {
+            var parentChildren = Window.Instance.LayersChildren;
+
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+                int targetIndex = parentChildren.IndexOf(target);
+
+                // If the currentIndex is not already the 0th index and the target has the same parent.
+                if ((currentIndex != 0) && (targetIndex != -1) &&
+                    (currentIndex > targetIndex))
+                {
+                    parentChildren.Remove(this);
+                    parentChildren.Insert(targetIndex, this);
+                }
+            }
             NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }