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;
21 public void Activate()
24 win = NUIApplication.GetDefaultWindow();
25 win.BackgroundColor = Color.Green;
29 Size = new Size(1000, 1000),
30 BackgroundColor = Color.Yellow,
31 PositionUsesPivotPoint = true,
32 ParentOrigin = ParentOrigin.Center,
33 PivotPoint = PivotPoint.Center,
35 root.TouchEvent += OnRootTouchEvent;
39 makeParentsAndChildrenToAdd(root);
44 private void Button_Clicked(object sender, ClickedEventArgs e)
46 TextLabel currentChild;
47 bool isCurrentParent1 = (sender as Button) == button1;
48 View currentParent = isCurrentParent1 ? parent1 : parent2;
51 currentChild = currentParent.FindChildByID(removeTargetID1) as TextLabel;
55 currentChild = currentParent.FindChildByID(removeTargetID2) as TextLabel;
58 if (currentChild != null && currentChild.Name.Contains("ID"))
60 tlog.Debug(tag, $"found child : Name={currentChild.Name}, Id={currentChild.Id}, ID={currentChild.ID} and unparent the child!");
61 currentChild.Unparent();
65 removeTargetID1 = currentParent.GetChildAt(0).ID;
69 removeTargetID2 = currentParent.GetChildAt(0).ID;
74 tlog.Debug(tag, $"couldn't find the child of ID {(isCurrentParent1 ? removeTargetID1 : removeTargetID2)}, or this is not a target of this test!");
77 currentChild = new TextLabel();
78 currentChild.Size = new Size(100, 100);
79 currentChild.PositionUsesPivotPoint = true;
80 currentChild.ParentOrigin = ParentOrigin.TopLeft;
81 currentChild.PivotPoint = PivotPoint.Center;
82 currentChild.BackgroundColor = new Color((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), 0.8f);
83 currentChild.Position = new Position(rand.Next(100, 400), rand.Next(100, 400));
84 currentChild.Name = currentChild.Text = $"ID-{currentChild.ID}";
85 currentChild.TextFit = new PropertyMap().Add("enable", new PropertyValue(true)).Add("minSize", new PropertyValue(5.0f)).Add("maxSize", new PropertyValue(50.0f));
86 currentParent.Add(currentChild);
87 tlog.Debug(tag, $"Add new child.ID={currentChild.ID}, Id={currentChild.Id}, Name={currentChild.Name}");
90 private bool OnRootTouchEvent(object source, View.TouchEventArgs e)
92 if (e.Touch.GetState(0) == PointStateType.Down)
94 printChildrenIDs(parent1);
95 printChildrenIDs(parent2);
100 private void printChildrenIDs(View parent)
102 uint numChild = parent.ChildCount;
103 tlog.Debug(tag, $"=============================================");
104 tlog.Debug(tag, $"parent: Name={parent.Name}, Id={parent.Id}, ID={parent.ID}");
105 for (int i = (int)numChild - 1; i >= 0; i--)
107 View child = parent.GetChildAt((uint)i);
108 tlog.Debug(tag, $" + child index[{i}]: Name={child.Name}, Id={child.Id}, ID={child.ID}");
110 tlog.Debug(tag, $"=============================================");
113 private void makeButtons(View root)
115 button1 = new Button();
116 button1.Text = "Remove & Add in parent1";
117 button1.Size = new Size(200, 200);
118 button1.BackgroundColor = Color.Cyan;
119 button1.Position = new Position(10, 600);
121 button1.Clicked += Button_Clicked;
123 button2 = new Button();
124 button2.Text = "Remove & Add in parent2";
125 button2.Size = new Size(200, 200);
126 button2.BackgroundColor = Color.Cyan;
127 button2.Position = new Position(510, 600);
129 button2.Clicked += Button_Clicked;
132 private void makeParentsAndChildrenToAdd(View root)
136 Size = new Size(500, 500),
137 Position = new Position(0, 10),
138 BackgroundColor = Color.Blue,
143 childList1 = new TextLabel[numberOfChildren];
145 for (int i = 0; i < numberOfChildren; i++)
147 childList1[i] = new TextLabel();
148 childList1[i].Size = new Size(100, 100);
149 childList1[i].PositionUsesPivotPoint = true;
150 childList1[i].ParentOrigin = ParentOrigin.TopLeft;
151 childList1[i].PivotPoint = PivotPoint.Center;
152 childList1[i].BackgroundColor = new Color(0.1f, 0.1f, (float)rand.NextDouble(), 0.8f);
153 childList1[i].Position = new Position(rand.Next(100, 400), rand.Next(100, 400));
154 childList1[i].Name = childList1[i].Text = $"ID={childList1[i].ID}";
155 childList1[i].TextFit = new PropertyMap().Add("enable", new PropertyValue(true)).Add("minSize", new PropertyValue(5.0f)).Add("maxSize", new PropertyValue(50.0f));
156 parent1.Add(childList1[i]);
158 removeTargetID1 = childList1[0].ID;
160 tlog.Debug(tag, $" \n");
161 tlog.Debug(tag, $" parent1 Id={parent1.Id} ID={parent1.ID}");
162 for (int i = 0; i < numberOfChildren; i++)
164 tlog.Debug(tag, $" child1({childList1[i].Text}) Id={childList1[i].Id}, ID={childList1[i].ID}");
169 Size = new Size(500, 500),
170 Position = new Position(500, 10),
171 BackgroundColor = Color.Red,
176 childList2 = new TextLabel[numberOfChildren];
178 for (int i = 0; i < numberOfChildren; i++)
180 childList2[i] = new TextLabel();
181 childList2[i].Size = new Size(100, 100);
182 childList2[i].PositionUsesPivotPoint = true;
183 childList2[i].ParentOrigin = ParentOrigin.TopLeft;
184 childList2[i].PivotPoint = PivotPoint.Center;
185 childList2[i].BackgroundColor = new Color((float)rand.NextDouble(), 0.1f, 0.1f, 1.0f);
186 childList2[i].Position = new Position(rand.Next(100, 400), rand.Next(100, 400));
187 childList2[i].Name = childList2[i].Text = $"ID={childList2[i].ID}";
188 childList2[i].TextFit = new PropertyMap().Add("enable", new PropertyValue(true)).Add("minSize", new PropertyValue(5.0f)).Add("maxSize", new PropertyValue(50.0f));
189 parent2.Add(childList2[i]);
191 removeTargetID2 = childList2[0].ID;
193 tlog.Debug(tag, $" \n");
194 tlog.Debug(tag, $" parent2 Id={parent2.Id} ID={parent2.ID}");
195 for (int i = 0; i < numberOfChildren; i++)
197 tlog.Debug(tag, $" child2({childList2[i].Text}) Id={childList2[i].Id}, ID={childList2[i].ID}");
201 public void Deactivate()
203 for (int i = (int)(parent1.ChildCount - 1); i >= 0; i--)
205 View child = parent1.GetChildAt((uint)i);
212 for (int i = (int)(parent2.ChildCount - 1); i >= 0; i--)
214 View child = parent2.GetChildAt((uint)i);