[NUI] Fix NUITizenGallery to run on Ubuntu VS-Code debugging
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / LabelTest / LabelTest3Page.xaml.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using Tizen.NUI;
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Components;
20
21 namespace NUITizenGallery
22 {
23     public partial class LabelTest3Page : ContentPage
24     {
25         public LabelTest3Page()
26         {
27             InitializeComponent();
28             mainView.Padding = new Extents(20, 20, 20, 100);
29         }
30
31         protected override void Dispose(DisposeTypes type)
32         {
33             if (Disposed)
34             {
35                 return;
36             }
37
38             if (type == DisposeTypes.Explicit)
39             {
40                 RemoveAllChildren(true);
41             }
42
43             base.Dispose(type);
44         }
45
46         private void RemoveAllChildren(bool dispose = false)
47         {
48             RecursiveRemoveChildren(this, dispose);
49         }
50
51         private void RecursiveRemoveChildren(View parent, bool dispose)
52         {
53             if (parent == null)
54             {
55                 return;
56             }
57
58             int maxChild = (int)parent.ChildCount;
59             for (int i = maxChild - 1; i >= 0; --i)
60             {
61                 View child = parent.GetChildAt((uint)i);
62                 if (child == null)
63                 {
64                     continue;
65                 }
66
67                 RecursiveRemoveChildren(child, dispose);
68                 parent.Remove(child);
69                 if (dispose)
70                 {
71                     child.Dispose();
72                 }
73             }
74         }
75     }
76 }