[NUI] Change for Size2D property to own internalSize2D which is cashed to prevent...
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / ImageTest5 / ImageTest5.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 System;
18 using Tizen.NUI;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Components;
21
22 namespace NUITizenGallery
23 {
24     public partial class ImageTest5Page : ContentPage
25     {
26
27         private float imgWidth = 0;
28         private float imgHeight = 0;
29         private String mode = "FillToParent";
30         private int choice = 0;
31
32         private void updateLabel()
33         {
34             imgHeight = imageView.Size2D.Height;
35             imgWidth = imageView.Size2D.Width;
36
37             if (choice == 0) mode = "FillToParent";
38             else if (choice == 1) mode = "SizeRelativeToParent";
39             else if (choice == 2) mode = "FitToChildren";
40             else mode = "Other";
41             desc1.Text = "Mode : " + mode + "/ Width : " + (imgWidth > 0 ? imgWidth.ToString() : "-") + ", Height: " + (imgHeight > 0 ? imgHeight.ToString() : "-");
42         }
43
44         public ImageTest5Page()
45         {
46             InitializeComponent();
47             updateLabel();
48
49             image1Btn.Clicked += (o, e) =>
50             {
51                 imageView.Size2D = new Size2D(imageView.Size2D.Width + 100, imageView.Size2D.Height + 100);
52                 updateLabel();
53             };
54             image2Btn.Clicked += (o, e) =>
55             {
56                 imageView.Size2D = new Size2D(imageView.Size2D.Width - 100, imageView.Size2D.Height - 100);
57                 updateLabel();
58             };
59             image3Btn.Clicked += (o, e) =>
60             {
61                 imageView.Size2D = new Size2D(imageView.Size2D.Width, imageView.Size2D.Height + 100);
62                 updateLabel();
63             };
64             image4Btn.Clicked += (o, e) =>
65             {
66                 imageView.Size2D = new Size2D(imageView.Size2D.Width, imageView.Size2D.Height - 100);
67                 updateLabel();
68             };
69             image5Btn.Clicked += (o, e) =>
70             {
71                 if (choice == 0)
72                 {
73                     imageView.HeightResizePolicy = Tizen.NUI.ResizePolicyType.FillToParent;
74                     imageView.WidthResizePolicy = Tizen.NUI.ResizePolicyType.FillToParent;
75                     choice++;
76                 }
77                 else if (choice == 1)
78                 {
79                     imageView.HeightResizePolicy = Tizen.NUI.ResizePolicyType.SizeRelativeToParent;
80                     imageView.WidthResizePolicy = Tizen.NUI.ResizePolicyType.SizeRelativeToParent;
81                     choice++;
82                 }
83                 else if (choice == 2)
84                 {
85                     imageView.HeightResizePolicy = Tizen.NUI.ResizePolicyType.FitToChildren;
86                     imageView.WidthResizePolicy = Tizen.NUI.ResizePolicyType.FitToChildren;
87                     choice = 0;
88                 }
89                 updateLabel();
90             };
91         }
92         protected override void Dispose(DisposeTypes type)
93         {
94             if (Disposed)
95             {
96                 return;
97             }
98
99             if (type == DisposeTypes.Explicit)
100             {
101                 RemoveAllChildren(true);
102             }
103
104             base.Dispose(type);
105         }
106
107         private void RemoveAllChildren(bool dispose = false)
108         {
109             RecursiveRemoveChildren(this, dispose);
110         }
111
112         private void RecursiveRemoveChildren(View parent, bool dispose)
113         {
114             if (parent == null)
115             {
116                 return;
117             }
118
119             int maxChild = (int)parent.ChildCount;
120             for (int i = maxChild - 1; i >= 0; --i)
121             {
122                 View child = parent.GetChildAt((uint)i);
123                 if (child == null)
124                 {
125                     continue;
126                 }
127
128                 RecursiveRemoveChildren(child, dispose);
129                 parent.Remove(child);
130                 if (dispose)
131                 {
132                     child.Dispose();
133                 }
134             }
135         }
136     }
137 }
138