[NUI] Add RemoveAllChildren() in ScrollableBase (#2076)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / RemoveAllChildrenTest.cs
1 
2 using Tizen.NUI;
3 using Tizen.NUI.BaseComponents;
4 using NUnit.Framework;
5 using Tizen.NUI.Components;
6
7 namespace Tizen.NUI.Samples
8 {
9     using tlog = Tizen.Log;
10     public class RemoveAllChildrenTest : IExample
11     {
12         const string tag = "NUITEST";
13
14         public void Activate()
15         {
16             test();
17         }
18         public void Deactivate()
19         {
20         }
21
22         private TextLabel t1, t2, t3, t4;
23         private Window window;
24         private ScrollableBase scroll;
25         private View grid;
26
27         void test()
28         {
29             window = NUIApplication.GetDefaultWindow();
30             window.KeyEvent += OnKeyEvent;
31
32             t1 = new TextLabel()
33             {
34                 Size = new Size(400, 100),
35                 Position = new Position(10, 10),
36                 Text = "TextLable-1",
37                 BackgroundColor = Color.Yellow,
38                 Name = "tl-1",
39             };
40             window.Add(t1);
41
42             t2 = new TextLabel()
43             {
44                 Size = new Size(400, 150),
45                 Position = new Position(10, 120),
46                 Text = "TextLable-2",
47                 BackgroundColor = Color.Green,
48                 Name = "tl-2",
49             };
50             window.Add(t2);
51
52             scroll = new ScrollableBase()
53             {
54                 Size = new Size(400, 500),
55                 Position = new Position(10, 280),
56                 BackgroundColor = Color.Red,
57                 ScrollingDirection = ScrollableBase.Direction.Vertical,
58                 Layout = new LinearLayout()
59                 {
60                     LinearOrientation = LinearLayout.Orientation.Vertical,
61                 },
62                 Padding = new Extents(20, 20, 20, 20),
63                 Name = "scr-1",
64             };
65             window.Add(scroll);
66
67             grid = new View()
68             {
69                 Layout = new GridLayout()
70                 {
71                     GridOrientation = GridLayout.Orientation.Vertical,
72                     Columns = 3,
73                     Rows = 3,
74                 },
75                 WidthSpecification = 390,
76                 HeightSpecification = 590,
77                 BackgroundColor = new Color(global::System.Drawing.Color.FromName("SlateBlue")),
78                 Padding = new Extents(5, 5, 5, 5),
79                 Name = "grid-1",
80             };
81             scroll.Add(grid);
82
83             for (int i = 0; i < 9; i++)
84             {
85                 var t = new TextLabel()
86                 {
87                     Size = new Size(100, 180),
88                     Text = $"con-{i}",
89                     BackgroundColor = new Color(0.5f, (100 + 10 * i) / 255.0f, 0.5f, 1),
90                     Margin = new Extents(2, 2, 2, 2),
91                     Name = $"sub-tl-{i}",
92                 };
93                 grid.Add(t);
94             }
95
96             t3 = new TextLabel()
97             {
98                 WidthSpecification = LayoutParamPolicies.MatchParent,
99                 HeightSpecification = 200,
100                 Text = "TextLable-3",
101                 BackgroundColor = Color.Magenta,
102                 Margin = new Extents(10, 10, 10, 10),
103                 Name = "tl-3",
104             };
105             scroll.Add(t3);
106
107             t4 = new TextLabel()
108             {
109                 WidthSpecification = LayoutParamPolicies.MatchParent,
110                 HeightSpecification = 200,
111                 Text = "TextLable-4",
112                 BackgroundColor = new Color(global::System.Drawing.Color.FromName("HotPink")),
113                 Margin = new Extents(10, 10, 10, 10),
114                 Name = "tl-4",
115             };
116             scroll.Add(t4);
117         }
118
119
120         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
121         {
122             if (e.Key.State == Key.StateType.Down)
123             {
124                 if (e.Key.KeyPressedName == "1")
125                 {
126                     ChangeScrollableBaseSizeBigger();
127                 }
128                 else if (e.Key.KeyPressedName == "2")
129                 {
130                     ChangeScrollableBaseSizeSmaller();
131                 }
132                 else if (e.Key.KeyPressedName == "3")
133                 {
134                     RemoveAllChildrenDisposeFalse();
135                 }
136                 else if (e.Key.KeyPressedName == "4")
137                 {
138                     RemoveAllChildrenDisposeTrue();
139                 }
140                 else if (e.Key.KeyPressedName == "5")
141                 {
142                     AddChildrenInScrollableBase();
143                 }
144             }
145         }
146
147         [Test]
148         void ChangeScrollableBaseSizeBigger()
149         {
150             tlog.Debug(tag, "ChangeScrollableBaseSizeBigger test");
151             t2.Position += new Position(10, -100);
152             scroll.Position += new Position(0, -100);
153             scroll.HeightSpecification += 100;
154         }
155
156         [Test]
157         void ChangeScrollableBaseSizeSmaller()
158         {
159             tlog.Debug(tag, "ChangeScrollableBaseSizeSmaller test");
160             t2.Position += new Position(-10, 100);
161             scroll.Position += new Position(0, 100);
162             scroll.HeightSpecification -= 100;
163
164         }
165
166         [Test]
167         void AddChildrenInScrollableBase()
168         {
169             tlog.Debug(tag, "AddChildrenInScrollableBase test");
170
171             grid = new View()
172             {
173                 Layout = new GridLayout()
174                 {
175                     GridOrientation = GridLayout.Orientation.Vertical,
176                     Columns = 3,
177                     Rows = 3,
178                 },
179                 WidthSpecification = 390,
180                 HeightSpecification = 590,
181                 BackgroundColor = new Color(global::System.Drawing.Color.FromName("SlateBlue")),
182                 Padding = new Extents(5, 5, 5, 5),
183                 Name = "grid-1",
184             };
185             scroll.Add(grid);
186
187             for (int i = 0; i < 9; i++)
188             {
189                 var t = new TextLabel()
190                 {
191                     Size = new Size(100, 180),
192                     Text = $"con-{i}",
193                     BackgroundColor = new Color(0.5f, (100 + 10 * i) / 255.0f, 0.5f, 1),
194                     Margin = new Extents(2, 2, 2, 2),
195                     Name = $"sub-tl-{i}",
196                 };
197                 grid.Add(t);
198             }
199
200             t3 = new TextLabel()
201             {
202                 WidthSpecification = LayoutParamPolicies.MatchParent,
203                 HeightSpecification = 200,
204                 Text = "TextLable-3",
205                 BackgroundColor = Color.Magenta,
206                 Margin = new Extents(10, 10, 10, 10),
207                 Name = "tl-3",
208             };
209             scroll.Add(t3);
210
211             t4 = new TextLabel()
212             {
213                 WidthSpecification = LayoutParamPolicies.MatchParent,
214                 HeightSpecification = 200,
215                 Text = "TextLable-4",
216                 BackgroundColor = new Color(global::System.Drawing.Color.FromName("HotPink")),
217                 Margin = new Extents(10, 10, 10, 10),
218                 Name = "tl-4",
219             };
220             scroll.Add(t4);
221         }
222
223         [Test]
224         void RemoveAllChildrenDisposeTrue()
225         {
226             tlog.Debug(tag, "RemoveAllChildrenDisposeTrue test");
227
228             scroll.RemoveAllChildren(true);
229         }
230
231         [Test]
232         void RemoveAllChildrenDisposeFalse()
233         {
234             tlog.Debug(tag, "RemoveAllChildrenDisposeFalse test");
235
236             scroll.RemoveAllChildren(false);
237         }
238
239     }
240 }