[NUI] Add FindLayerByID(), FindChildByID()
authordongsug.song <dongsug.song@samsung.com>
Fri, 14 May 2021 07:22:32 +0000 (16:22 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 17 May 2021 09:18:32 +0000 (18:18 +0900)
- FindLayerByID() in Window and FindChildByID() in View are added.
- These are all Hidden-APIs.

src/Tizen.NUI/src/public/BaseComponents/ViewPublicMethods.cs
src/Tizen.NUI/src/public/Layer.cs
src/Tizen.NUI/src/public/Window.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/FindChildByIDTest.cs [new file with mode: 0644]

index d73a0d4..17c037f 100755 (executable)
@@ -632,5 +632,22 @@ namespace Tizen.NUI.BaseComponents
                 view.ObjectDump();
             }
         }
+
+        /// <summary>
+        /// Search through this View's hierarchy for a View with the given unique ID.
+        /// </summary>
+        /// <param name="id">The ID of the View to find.</param>
+        /// <remarks>Hidden-API</remarks>
+        /// <returns>A handle to the View if found, or an empty handle if not.</returns>
+        [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<View>(cPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
     }
 }
index 34cefd1..3192aaa 100755 (executable)
@@ -256,6 +256,21 @@ namespace Tizen.NUI
             }
         }
 
+        /// <summary>
+        /// Gets the Layer's ID
+        /// Readonly
+        /// </summary>
+        /// <remarks>Hidden-API</remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public uint ID
+        {
+            get
+            {
+                return GetId();
+            }
+        }
+
+
         /// From the Container base class.
 
         /// <summary>
@@ -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)
index cce9c4d..91d60f5 100755 (executable)
@@ -1442,5 +1442,23 @@ namespace Tizen.NUI
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
+
+        /// <summary>
+        /// Search through this Window for a Layer with the given unique ID.
+        /// </summary>
+        /// <param name="id">The ID of the Layer to find.</param>
+        /// <remarks>Hidden-API</remarks>
+        /// <returns>A handle to the Layer if found, or an empty handle if not.</returns>
+        [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<Layer>(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 (file)
index 0000000..2051ece
--- /dev/null
@@ -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()
+        {
+        }
+    }
+}