4 using Tizen.NUI.BaseComponents;
5 using Tizen.NUI.Components;
7 namespace Tizen.NUI.Samples
9 using tlog = Tizen.Log;
10 public class FindChildByIdTest : IExample
12 private const string tag = "NUITEST";
13 private const int numberOfChildren = 10;
15 private View root, parent1, parent2;
16 private TextLabel[] childList1, childList2;
17 private Button button1, button2;
19 private uint removeTargetID1, removeTargetID2;
20 private Layer layer1, layer2;
21 private uint layer1ID, layer2ID;
23 public void Activate()
26 win = NUIApplication.GetDefaultWindow();
27 win.BackgroundColor = Color.Green;
31 Size = new Size(1000, 1000),
32 BackgroundColor = Color.Yellow,
33 PositionUsesPivotPoint = true,
34 ParentOrigin = ParentOrigin.Center,
35 PivotPoint = PivotPoint.Center,
37 root.TouchEvent += OnRootTouchEvent;
41 makeParentsAndChildrenToAdd(root);
46 layer1.Name = "layerTest1";
51 layer2.Name = "layerTest2";
56 private void Button_Clicked(object sender, ClickedEventArgs e)
58 TextLabel currentChild;
59 bool isCurrentParent1 = (sender as Button) == button1;
60 View currentParent = isCurrentParent1 ? parent1 : parent2;
63 currentChild = currentParent.FindDescendantByID(removeTargetID1) as TextLabel;
67 currentChild = currentParent.FindDescendantByID(removeTargetID2) as TextLabel;
70 if (currentChild != null && currentChild.Name.Contains("ID"))
72 tlog.Debug(tag, $"found child : Name={currentChild.Name}, Id={currentChild.Id}, ID={currentChild.ID} and unparent the child!");
73 currentChild.Unparent();
77 removeTargetID1 = currentParent.GetChildAt(0).ID;
81 removeTargetID2 = currentParent.GetChildAt(0).ID;
86 tlog.Debug(tag, $"couldn't find the child of ID {(isCurrentParent1 ? removeTargetID1 : removeTargetID2)}, or this is not a target of this test!");
89 currentChild = new TextLabel();
90 currentChild.Size = new Size(100, 100);
91 currentChild.PositionUsesPivotPoint = true;
92 currentChild.ParentOrigin = ParentOrigin.TopLeft;
93 currentChild.PivotPoint = PivotPoint.Center;
94 currentChild.BackgroundColor = new Color((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), 0.8f);
95 currentChild.Position = new Position(rand.Next(100, 400), rand.Next(100, 400));
96 currentChild.Name = currentChild.Text = $"ID-{currentChild.ID}";
97 currentChild.TextFit = new PropertyMap().Add("enable", new PropertyValue(true)).Add("minSize", new PropertyValue(5.0f)).Add("maxSize", new PropertyValue(50.0f));
98 currentParent.Add(currentChild);
99 tlog.Debug(tag, $"Add new child.ID={currentChild.ID}, Id={currentChild.Id}, Name={currentChild.Name}");
102 private bool OnRootTouchEvent(object source, View.TouchEventArgs e)
104 if (e.Touch.GetState(0) == PointStateType.Down)
106 printChildrenIDs(parent1);
107 printChildrenIDs(parent2);
112 private void printChildrenIDs(View parent)
114 uint numChild = parent.ChildCount;
115 tlog.Debug(tag, $"=============================================");
116 tlog.Debug(tag, $"parent: Name={parent.Name}, Id={parent.Id}, ID={parent.ID}");
117 for (int i = (int)numChild - 1; i >= 0; i--)
119 View child = parent.GetChildAt((uint)i);
120 tlog.Debug(tag, $" + child index[{i}]: Name={child.Name}, Id={child.Id}, ID={child.ID}");
122 tlog.Debug(tag, $"=============================================");
125 private void makeButtons(View root)
127 button1 = new Button();
128 button1.Text = "Remove & Add in parent1";
129 button1.Size = new Size(200, 200);
130 button1.BackgroundColor = Color.Cyan;
131 button1.Position = new Position(10, 600);
133 button1.Clicked += Button_Clicked;
135 button2 = new Button();
136 button2.Text = "Remove & Add in parent2";
137 button2.Size = new Size(200, 200);
138 button2.BackgroundColor = Color.Cyan;
139 button2.Position = new Position(510, 600);
141 button2.Clicked += Button_Clicked;
144 private void makeParentsAndChildrenToAdd(View root)
148 Size = new Size(500, 500),
149 Position = new Position(0, 10),
150 BackgroundColor = Color.Blue,
155 childList1 = new TextLabel[numberOfChildren];
157 for (int i = 0; i < numberOfChildren; i++)
159 childList1[i] = new TextLabel();
160 childList1[i].Size = new Size(100, 100);
161 childList1[i].PositionUsesPivotPoint = true;
162 childList1[i].ParentOrigin = ParentOrigin.TopLeft;
163 childList1[i].PivotPoint = PivotPoint.Center;
164 childList1[i].BackgroundColor = new Color(0.1f, 0.1f, (float)rand.NextDouble(), 0.8f);
165 childList1[i].Position = new Position(rand.Next(100, 400), rand.Next(100, 400));
166 childList1[i].Name = childList1[i].Text = $"ID={childList1[i].ID}";
167 childList1[i].TextFit = new PropertyMap().Add("enable", new PropertyValue(true)).Add("minSize", new PropertyValue(5.0f)).Add("maxSize", new PropertyValue(50.0f));
168 parent1.Add(childList1[i]);
170 removeTargetID1 = childList1[0].ID;
172 tlog.Debug(tag, $" \n");
173 tlog.Debug(tag, $" parent1 Id={parent1.Id} ID={parent1.ID}");
174 for (int i = 0; i < numberOfChildren; i++)
176 tlog.Debug(tag, $" child1({childList1[i].Text}) Id={childList1[i].Id}, ID={childList1[i].ID}");
181 Size = new Size(500, 500),
182 Position = new Position(500, 10),
183 BackgroundColor = Color.Red,
188 childList2 = new TextLabel[numberOfChildren];
190 for (int i = 0; i < numberOfChildren; i++)
192 childList2[i] = new TextLabel();
193 childList2[i].Size = new Size(100, 100);
194 childList2[i].PositionUsesPivotPoint = true;
195 childList2[i].ParentOrigin = ParentOrigin.TopLeft;
196 childList2[i].PivotPoint = PivotPoint.Center;
197 childList2[i].BackgroundColor = new Color((float)rand.NextDouble(), 0.1f, 0.1f, 1.0f);
198 childList2[i].Position = new Position(rand.Next(100, 400), rand.Next(100, 400));
199 childList2[i].Name = childList2[i].Text = $"ID={childList2[i].ID}";
200 childList2[i].TextFit = new PropertyMap().Add("enable", new PropertyValue(true)).Add("minSize", new PropertyValue(5.0f)).Add("maxSize", new PropertyValue(50.0f));
201 parent2.Add(childList2[i]);
203 removeTargetID2 = childList2[0].ID;
205 tlog.Debug(tag, $" \n");
206 tlog.Debug(tag, $" parent2 Id={parent2.Id} ID={parent2.ID}");
207 for (int i = 0; i < numberOfChildren; i++)
209 tlog.Debug(tag, $" child2({childList2[i].Text}) Id={childList2[i].Id}, ID={childList2[i].ID}");
214 private void WindowTouchEvent(object sender, Window.TouchEventArgs e)
216 if (e.Touch.GetState(0) == PointStateType.Down)
218 tlog.Debug(tag, $"======================");
219 var ret = checkTest() ? "PASS" : "FAIL";
220 tlog.Debug(tag, $"test result={ret}");
224 private void WindowKeyEvent(object sender, Window.KeyEventArgs e)
226 if (e.Key.State == Key.StateType.Down)
228 if (e.Key.KeyPressedName == "Up")
230 tlog.Debug(tag, $"======================");
231 var ret = checkTest() ? "PASS" : "FAIL";
232 tlog.Debug(tag, $"test result={ret}");
244 var gotten = win.FindLayerByID(layer1ID);
247 if (layer1ID == gotten.ID)
249 tlog.Debug(tag, $"Test#1: FindLayerByID({gotten.ID}) OK");
253 tlog.Debug(tag, $"Test#1: FindLayerByID({gotten.ID}) ERROR");
259 tlog.Debug(tag, $"Test#1: FindLayerByID() ERROR, gotten Layer is NULL!");
265 var gotten = win.FindLayerByID(layer2ID);
268 if (layer2ID == gotten.ID)
270 tlog.Debug(tag, $"Test#2: FindLayerByID({gotten.ID}) OK");
274 tlog.Debug(tag, $"Test#2: FindLayerByID({gotten.ID}) ERROR");
280 tlog.Debug(tag, $"Test#2: FindLayerByID() ERROR, gotten Layer is NULL!");
287 public void Deactivate()
289 for (int i = (int)(parent1.ChildCount - 1); i >= 0; i--)
291 View child = parent1.GetChildAt((uint)i);
298 for (int i = (int)(parent2.ChildCount - 1); i >= 0; i--)
300 View child = parent2.GetChildAt((uint)i);