2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Components;
21 namespace NUITizenGallery
23 public partial class StackLayoutTest8Page : View
25 public StackLayoutTest8Page()
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;
37 private void OnPaddingSliderChanged(object sender, SliderValueChangedEventArgs e)
39 ushort padding = (ushort)e.CurrentValue;
40 layout.Padding = new Extents(padding, padding, padding, padding);
43 private void OnCellPaddingSilderChanged(object sender, SliderValueChangedEventArgs e)
45 (layout.Layout as LinearLayout).CellPadding = new Size2D((int)e.CurrentValue, (int)e.CurrentValue);
48 private void OnMarginSliderChanged(object sender, SliderValueChangedEventArgs e)
50 ushort margin = (ushort)e.CurrentValue;
51 layout.Margin = new Extents(margin, margin, margin, margin);
54 private void OnButtonOrientationClicked(object sender, ClickedEventArgs e)
56 LinearLayout linearLayout = (layout.Layout as LinearLayout);
58 if (linearLayout.LinearOrientation == LinearLayout.Orientation.Horizontal)
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;
70 linearLayout.LinearOrientation = LinearLayout.Orientation.Horizontal;
71 redBox.WidthSpecification = 80;
72 greenBox.WidthSpecification = 80;
73 blueBox.WidthSpecification = 80;
77 private void OnResetButtonClikced(object sender, ClickedEventArgs e)
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);
83 sliderPadding.CurrentValue = 0.0f;
84 sliderCellPadding.CurrentValue = 0.0f;
85 sliderMargin.CurrentValue = 0.0f;
89 protected override void Dispose(DisposeTypes type)
96 if (type == DisposeTypes.Explicit)
98 sliderPadding.ValueChanged -= OnPaddingSliderChanged;
99 sliderCellPadding.ValueChanged -= OnCellPaddingSilderChanged;
100 sliderMargin.ValueChanged -= OnMarginSliderChanged;
101 buttonOrientation.Clicked -= OnButtonOrientationClicked;
102 buttonReset.Clicked -= OnResetButtonClikced;
103 RemoveAllChildren(true);
109 private void RemoveAllChildren(bool dispose = false)
111 RecursiveRemoveChildren(this, dispose);
114 private void RecursiveRemoveChildren(View parent, bool dispose)
121 int maxChild = (int)parent.ChildCount;
122 for (int i = maxChild - 1; i >= 0; --i)
124 View child = parent.GetChildAt((uint)i);
130 RecursiveRemoveChildren(child, dispose);
131 parent.Remove(child);