[NUI] Change for Size2D property to own internalSize2D which is cashed to prevent...
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / StackLayoutTest8 / StackLayoutTest8Page.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 StackLayoutTest8Page : View
24     {
25         public StackLayoutTest8Page()
26         {
27             InitializeComponent();
28             this.Padding = new Extents(20, 20, 20, 20);
29             sliderPadding.ValueChanged += OnPaddingSliderChanged;
30             sliderCellPadding.ValueChanged += OnCellPaddingSilderChanged;
31             sliderMargin.ValueChanged += OnMarginSliderChanged;
32             buttonOrientation.Clicked += OnButtonOrientationClicked;
33             buttonReset.Clicked += OnResetButtonClikced;
34
35         }
36
37         private void OnPaddingSliderChanged(object sender, SliderValueChangedEventArgs e)
38         {
39             ushort padding = (ushort)e.CurrentValue;
40             layout.Padding = new Extents(padding, padding, padding, padding);
41         }
42
43         private void OnCellPaddingSilderChanged(object sender, SliderValueChangedEventArgs e)
44         {
45             (layout.Layout as LinearLayout).CellPadding = new Size2D((int)e.CurrentValue, (int)e.CurrentValue);
46         }
47
48         private void OnMarginSliderChanged(object sender, SliderValueChangedEventArgs e)
49         {
50             ushort margin = (ushort)e.CurrentValue;
51             layout.Margin = new Extents(margin, margin, margin, margin);
52         }
53
54         private void OnButtonOrientationClicked(object sender, ClickedEventArgs e)
55         {
56             LinearLayout linearLayout = (layout.Layout as LinearLayout);
57
58             if (linearLayout.LinearOrientation == LinearLayout.Orientation.Horizontal)
59             {
60                 linearLayout.LinearOrientation = LinearLayout.Orientation.Vertical;
61                 redBox.WidthSpecification = LayoutParamPolicies.MatchParent;
62                 greenBox.WidthSpecification = LayoutParamPolicies.MatchParent;
63                 blueBox.WidthSpecification = LayoutParamPolicies.MatchParent;
64                 redBox.HeightSpecification = 80;
65                 greenBox.HeightSpecification = 80;
66                 blueBox.HeightSpecification = 80;
67             }
68             else
69             {
70                 linearLayout.LinearOrientation = LinearLayout.Orientation.Horizontal;
71                 redBox.WidthSpecification = 80;
72                 greenBox.WidthSpecification = 80;
73                 blueBox.WidthSpecification = 80;
74             }
75         }
76
77         private void OnResetButtonClikced(object sender, ClickedEventArgs e)
78         {
79             layout.Padding = new Extents(0, 0, 0, 0);
80             layout.Margin = new Extents(0, 0, 0, 0);
81             (layout.Layout as LinearLayout).CellPadding = new Size2D(0,0);
82
83             sliderPadding.CurrentValue = 0.0f;
84             sliderCellPadding.CurrentValue = 0.0f;
85             sliderMargin.CurrentValue = 0.0f;
86
87         }
88
89         protected override void Dispose(DisposeTypes type)
90         {
91             if (Disposed)
92             {
93                 return;
94             }
95
96             if (type == DisposeTypes.Explicit)
97             {
98                 sliderPadding.ValueChanged -= OnPaddingSliderChanged;
99                 sliderCellPadding.ValueChanged -= OnCellPaddingSilderChanged;
100                 sliderMargin.ValueChanged -= OnMarginSliderChanged;
101                 buttonOrientation.Clicked -= OnButtonOrientationClicked;
102                 buttonReset.Clicked -= OnResetButtonClikced;
103                 RemoveAllChildren(true);
104             }
105
106             base.Dispose(type);
107         }
108
109         private void RemoveAllChildren(bool dispose = false)
110         {
111             RecursiveRemoveChildren(this, dispose);
112         }
113
114         private void RecursiveRemoveChildren(View parent, bool dispose)
115         {
116             if (parent == null)
117             {
118                 return;
119             }
120
121             int maxChild = (int)parent.ChildCount;
122             for (int i = maxChild - 1; i >= 0; --i)
123             {
124                 View child = parent.GetChildAt((uint)i);
125                 if (child == null)
126                 {
127                     continue;
128                 }
129
130                 RecursiveRemoveChildren(child, dispose);
131                 parent.Remove(child);
132                 if (dispose)
133                 {
134                     child.Dispose();
135                 }
136             }
137         }
138     }
139 }