From aa465c0fd0c1e1f8f891f9cfeb5f5c93ca8ac73a Mon Sep 17 00:00:00 2001 From: "huiyu,eun" Date: Fri, 26 Jan 2018 11:13:23 +0900 Subject: [PATCH] [NUI] Apply SiblingOrder Change-Id: I8a44269bd4bb6a23db33bad05763e3e4e250c8b4 Signed-off-by: huiyu,eun --- src/Tizen.NUI/src/public/BaseComponents/View.cs | 126 +++++++++++++++++------- src/Tizen.NUI/src/public/Layer.cs | 88 ++++++++++++++--- 2 files changed, 163 insertions(+), 51 deletions(-) diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 4f02f46..762bc29 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -49,11 +49,18 @@ namespace Tizen.NUI.BaseComponents /// 4 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); + } } /// @@ -2239,7 +2246,7 @@ namespace Tizen.NUI.BaseComponents /// Sets the sibling order of the view so the depth position can be defined within the same parent. /// /// - /// Note the initial value is 0. + /// Note the initial value is 0. SiblingOrder should be bigger than 0 or equal to 0. /// Raise, Lower, RaiseToTop, LowerToBottom, RaiseAbove, and LowerBelow will override the sibling order. /// The values set by this property will likely change. /// @@ -2248,7 +2255,7 @@ namespace Tizen.NUI.BaseComponents { get { - var parentChildren = Parent?.Children; + var parentChildren = GetParent()?.Children; int currentOrder = 0; if (parentChildren != null) { @@ -2268,7 +2275,38 @@ namespace Tizen.NUI.BaseComponents } set { - SetProperty(View.Property.SIBLING_ORDER, new Tizen.NUI.PropertyValue(value)); + if(value < 0) + { + NUILog.Error("SiblingOrder should be bigger than 0 or equal to 0."); + return; + } + var siblings = GetParent()?.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(); + } + } + } } } @@ -2344,46 +2382,47 @@ namespace Tizen.NUI.BaseComponents internal void Raise() { - var parentChildren = Parent?.Children; + var parentChildren = GetParent()?.Children; if (parentChildren != null) { int currentIndex = parentChildren.IndexOf(this); // If the view is not already the last item in the list. - if (currentIndex != parentChildren.Count -1) + if (currentIndex >= 0 && currentIndex < parentChildren.Count -1) { View temp = parentChildren[currentIndex + 1]; parentChildren[currentIndex + 1] = this; parentChildren[currentIndex] = temp; + + NDalicPINVOKE.Raise(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } - NDalicPINVOKE.Raise(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal void Lower() { - var parentChildren = Parent?.Children; + var parentChildren = GetParent()?.Children; if (parentChildren != null) { int currentIndex = parentChildren.IndexOf(this); // If the view is not already the first item in the list. - if (currentIndex > 0) + if (currentIndex > 0 && currentIndex < parentChildren.Count) { View temp = parentChildren[currentIndex - 1]; parentChildren[currentIndex - 1] = this; parentChildren[currentIndex] = temp; + + NDalicPINVOKE.Lower(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } - - NDalicPINVOKE.Lower(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// @@ -2396,17 +2435,18 @@ namespace Tizen.NUI.BaseComponents /// 3 public void RaiseToTop() { - var parentChildren = Parent?.Children; + var parentChildren = GetParent()?.Children; if (parentChildren != null) { parentChildren.Remove(this); parentChildren.Add(this); + + NDalicPINVOKE.RaiseToTop(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - NDalicPINVOKE.RaiseToTop(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// @@ -2419,17 +2459,17 @@ namespace Tizen.NUI.BaseComponents /// 3 public void LowerToBottom() { - var parentChildren = Parent?.Children; + var parentChildren = GetParent()?.Children; if (parentChildren != null) { parentChildren.Remove(this); parentChildren.Insert(0, this); - } - NDalicPINVOKE.LowerToBottom(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + NDalicPINVOKE.LowerToBottom(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } } /// @@ -2456,24 +2496,31 @@ namespace Tizen.NUI.BaseComponents /// Will be raised above this view. internal void RaiseAbove(View target) { - var parentChildren = Parent?.Children; + var parentChildren = GetParent()?.Children; if (parentChildren != null) { int currentIndex = parentChildren.IndexOf(this); int targetIndex = parentChildren.IndexOf(target); + if(currentIndex < 0 || targetIndex < 0 || + currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count) + { + NUILog.Error("index should be bigger than 0 and less than children of layer count"); + return; + } // 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.RaiseAbove(swigCPtr, View.getCPtr(target)); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } - NDalicPINVOKE.RaiseAbove(swigCPtr, View.getCPtr(target)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// @@ -2486,12 +2533,18 @@ namespace Tizen.NUI.BaseComponents /// Will be lowered below this view. internal void LowerBelow(View target) { - var parentChildren = Parent?.Children; + var parentChildren = GetParent()?.Children; if (parentChildren != null) { int currentIndex = parentChildren.IndexOf(this); int targetIndex = parentChildren.IndexOf(target); + if(currentIndex < 0 || targetIndex < 0 || + currentIndex >= parentChildren.Count ||targetIndex >= parentChildren.Count) + { + NUILog.Error("index should be bigger than 0 and less than children of layer count"); + return; + } // If the currentIndex is not already the 0th index and the target has the same parent. if ((currentIndex != 0) && (targetIndex != -1) && @@ -2499,12 +2552,13 @@ namespace Tizen.NUI.BaseComponents { parentChildren.Remove(this); parentChildren.Insert(targetIndex, this); + + NDalicPINVOKE.LowerBelow(swigCPtr, View.getCPtr(target)); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } - NDalicPINVOKE.LowerBelow(swigCPtr, View.getCPtr(target)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal string GetName() diff --git a/src/Tizen.NUI/src/public/Layer.cs b/src/Tizen.NUI/src/public/Layer.cs index 8fee27b..37efd13 100755 --- a/src/Tizen.NUI/src/public/Layer.cs +++ b/src/Tizen.NUI/src/public/Layer.cs @@ -50,11 +50,18 @@ namespace Tizen.NUI /// 4 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); + } } /// @@ -254,13 +261,16 @@ namespace Tizen.NUI { int currentIdx = parentChildren.IndexOf(this); - if (currentIdx != parentChildren.Count - 1) + if (currentIdx >= 0 && currentIdx < parentChildren.Count - 1) { RaiseAbove(parentChildren[currentIdx + 1]); Layer temp = parentChildren[currentIdx + 1]; parentChildren[currentIdx + 1] = this; parentChildren[currentIdx] = temp; + + NDalicPINVOKE.Layer_Raise(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } @@ -276,7 +286,7 @@ namespace Tizen.NUI { int currentIdx = parentChildren.IndexOf(this); - if (currentIdx > 0) + if (currentIdx > 0 && currentIdx < parentChildren.Count) { LowerBelow(parentChildren[currentIdx - 1]); @@ -284,20 +294,66 @@ namespace Tizen.NUI parentChildren[currentIdx - 1] = this; parentChildren[currentIdx] = temp; + NDalicPINVOKE.Layer_Lower(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } internal void RaiseAbove(Layer target) { - NDalicPINVOKE.Layer_RaiseAbove(swigCPtr, Layer.getCPtr(target)); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + var parentChildren = Window.Instance.LayersChildren; + if (parentChildren != null) + { + int currentIndex = parentChildren.IndexOf(this); + int targetIndex = parentChildren.IndexOf(target); + + if(currentIndex < 0 || targetIndex < 0 || + currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count) + { + NUILog.Error("index should be bigger than 0 and less than children of layer count"); + return; + } + + // 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) { - NDalicPINVOKE.Layer_LowerBelow(swigCPtr, Layer.getCPtr(target)); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + var parentChildren = Window.Instance.LayersChildren; + + if (parentChildren != null) + { + int currentIndex = parentChildren.IndexOf(this); + int targetIndex = parentChildren.IndexOf(target); + + if(currentIndex < 0 || targetIndex < 0 || + currentIndex >= parentChildren.Count || targetIndex >= parentChildren.Count) + { + NUILog.Error("index should be bigger than 0 and less than children of layer count"); + return; + } + + // 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(); + } + } } /// @@ -312,9 +368,10 @@ namespace Tizen.NUI { parentChildren.Remove(this); parentChildren.Add(this); + + NDalicPINVOKE.Layer_RaiseToTop(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - NDalicPINVOKE.Layer_RaiseToTop(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// @@ -329,10 +386,11 @@ namespace Tizen.NUI { parentChildren.Remove(this); parentChildren.Insert(0, this); + + NDalicPINVOKE.Layer_LowerToBottom(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } - NDalicPINVOKE.Layer_LowerToBottom(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// -- 2.7.4