From: dongsug.song Date: Fri, 14 May 2021 07:22:32 +0000 (+0900) Subject: [NUI] Add FindLayerByID(), FindChildByID() X-Git-Tag: submit/tizen_6.0/20210518.005232~1^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6bbe0dcb0e070583a37d572849e70306cd9d5cdf;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add FindLayerByID(), FindChildByID() - FindLayerByID() in Window and FindChildByID() in View are added. - These are all Hidden-APIs. --- diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs index d73a0d450..17c037f6e 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs @@ -632,5 +632,22 @@ namespace Tizen.NUI.BaseComponents view.ObjectDump(); } } + + /// + /// Search through this View's hierarchy for a View with the given unique ID. + /// + /// The ID of the View to find. + /// Hidden-API + /// A handle to the View if found, or an empty handle if not. + [EditorBrowsable(EditorBrowsableState.Never)] + public View FindChildByID(uint id) + { + //to fix memory leak issue, match the handle count with native side. + IntPtr cPtr = Interop.Actor.Actor_FindChildById(swigCPtr, id); + View ret = this.GetInstanceSafely(cPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } } diff --git a/src/Tizen.NUI/src/public/Layer.cs b/src/Tizen.NUI/src/public/Layer.cs index 34cefd1f5..3192aaaff 100755 --- a/src/Tizen.NUI/src/public/Layer.cs +++ b/src/Tizen.NUI/src/public/Layer.cs @@ -256,6 +256,21 @@ namespace Tizen.NUI } } + /// + /// Gets the Layer's ID + /// Readonly + /// + /// Hidden-API + [EditorBrowsable(EditorBrowsableState.Never)] + public uint ID + { + get + { + return GetId(); + } + } + + /// From the Container base class. /// @@ -672,6 +687,14 @@ namespace Tizen.NUI window = win; } + internal uint GetId() + { + uint ret = Interop.Actor.Actor_GetId(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + /// This will not be public opened. [EditorBrowsable(EditorBrowsableState.Never)] protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) diff --git a/src/Tizen.NUI/src/public/Window.cs b/src/Tizen.NUI/src/public/Window.cs index cce9c4d7d..91d60f51a 100755 --- a/src/Tizen.NUI/src/public/Window.cs +++ b/src/Tizen.NUI/src/public/Window.cs @@ -1442,5 +1442,23 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } + + /// + /// Search through this Window for a Layer with the given unique ID. + /// + /// The ID of the Layer to find. + /// Hidden-API + /// A handle to the Layer if found, or an empty handle if not. + [EditorBrowsable(EditorBrowsableState.Never)] + public Layer FindLayerByID(uint id) + { + Layer defaultLayer = this.GetDefaultLayer(); + IntPtr cPtr = Interop.Actor.Actor_FindChildById(defaultLayer.SwigCPtr, id); + Layer ret = this.GetInstanceSafely(cPtr); + + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + } } diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/FindChildByIDTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/FindChildByIDTest.cs new file mode 100644 index 000000000..2051eceea --- /dev/null +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/FindChildByIDTest.cs @@ -0,0 +1,195 @@ + +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Components; +using System; + +namespace Tizen.NUI.Samples +{ + using l = Tizen.Log; + + public class FindChildByIDTest : IExample + { + Window window; + Layer layer1, layer2; + View view1, view2; + TextLabel text1, text2; + uint layer1ID, layer2ID, view1ID, view2ID, text1ID, text2ID; + const string t = "NUITEST"; + + public void Activate() + { + window = NUIApplication.GetDefaultWindow(); + window.KeyEvent += WindowKeyEvent; + window.TouchEvent += WindowTouchEvent; + + layer1 = new Layer(); + layer1.Name = "layerTest1"; + window.AddLayer(layer1); + + layer2 = new Layer(); + layer2.Name = "layerTest2"; + window.AddLayer(layer2); + + view1 = new View(); + view1.Name = "viewTest1"; + view1.Size = new Size(100, 100); + view1.Position = new Position(10, 10); + view1.BackgroundColor = Color.Blue; + layer1.Add(view1); + + view2 = new View(); + view2.Name = "viewTest2"; + view2.Size = new Size(100, 100); + view2.Position = new Position(100, 100); + view2.BackgroundColor = Color.Blue; + layer2.Add(view2); + + text1 = new TextLabel() + { + Name = "textTest1", + Size = new Size(300, 100), + Position = new Position(200, 200), + Text = "text1", + BackgroundColor = Color.Yellow, + }; + view1.Add(text1); + + text2 = new TextLabel() + { + Name = "textTest2", + Size = new Size(300, 100), + Position = new Position(300, 300), + Text = "text2", + BackgroundColor = Color.Green, + }; + view2.Add(text2); + + layer1ID = layer1.ID; + layer2ID = layer2.ID; + view1ID = view1.ID; + view2ID = view2.ID; + text1ID = text1.ID; + text2ID = text2.ID; + } + + bool toggle = false; + private void WindowTouchEvent(object sender, Window.TouchEventArgs e) + { + if (e.Touch.GetState(0) == PointStateType.Down) + { + l.Fatal(t, $"======================"); + var ret = checkTest() ? "PASS" : "FAIL"; + l.Fatal(t, $"test result={ret}"); + } + } + + private void WindowKeyEvent(object sender, Window.KeyEventArgs e) + { + if (e.Key.State == Key.StateType.Down) + { + if (e.Key.KeyPressedName == "Up") + { + l.Fatal(t, $"======================"); + var ret = checkTest() ? "PASS" : "FAIL"; + l.Fatal(t, $"test result={ret}"); + } + } + } + + bool checkTest() + { + bool ret = true; + toggle = !toggle; + + if (toggle) + { + var gotten = window.FindLayerByID(layer1ID); + if (gotten) + { + if (layer1ID == gotten.ID) + { + l.Fatal(t, $"Test#1: FindLayerByID({gotten.ID}) OK"); + var gotten2 = gotten.FindChildById(text1ID); + if (gotten2.ID == text1ID) + { + l.Fatal(t, $"Test#1-1: FindChildById({gotten2.ID}) OK"); + } + else + { + l.Fatal(t, $"Test#1-1: FindChildById({gotten2.ID}) ERROR"); + ret = false; + } + + gotten2 = gotten.FindChildById(view2ID); + if (gotten2 == null) + { + l.Fatal(t, $"Test#1-2: FindChildById() OK"); + } + else + { + l.Fatal(t, $"Test#1-2: FindChildById() ERROR"); + ret = false; + } + } + else + { + l.Fatal(t, $"Test#1: FindLayerByID({gotten.ID}) ERROR"); + ret = false; + } + } + else + { + l.Fatal(t, $"Test#1: FindLayerByID() ERROR, gotten Layer is NULL!"); + ret = false; + } + } + else + { + var gotten = window.FindLayerByID(layer2ID); + if (gotten) + { + if (layer2ID == gotten.ID) + { + l.Fatal(t, $"Test#2: FindLayerByID({gotten.ID}) OK"); + var gotten2 = gotten.FindChildById(text2ID); + if (gotten2.ID == text2ID) + { + l.Fatal(t, $"Test#2-1: FindChildById({gotten2.ID}) OK"); + } + else + { + l.Fatal(t, $"Test#2-1: FindChildById({gotten2.ID}) ERROR"); + ret = false; + } + + gotten2 = gotten.FindChildById(view1ID); + if (gotten2 == null) + { + l.Fatal(t, $"Test#2-2: FindChildById() OK"); + } + else + { + l.Fatal(t, $"Test#2-2: FindChildById() ERROR"); + ret = false; + } + } + else + { + l.Fatal(t, $"Test#2: FindLayerByID({gotten.ID}) ERROR"); + ret = false; + } + } + else + { + l.Fatal(t, $"Test#2: FindLayerByID() ERROR, gotten Layer is NULL!"); + ret = false; + } + } + return ret; + } + + public void Deactivate() + { + } + } +}