2 * Copyright (c) 2020 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.
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Components;
23 namespace Tizen.NUI.Samples
25 class GridExample : IExample
27 private Window currentWindow;
28 private static int MAX_ITEM_COUNT = 31;
29 private int layoutOption = 3;
31 private View layoutView;
32 private TextLabel label;
33 private View bottomView;
34 private View bottomView_2;
36 public void Activate()
41 public void Initialize()
43 currentWindow = NUIApplication.GetDefaultWindow();
44 currentWindow.BackgroundColor = Color.White;
46 InitializeDefaultUI();
50 public void InitializeLayoutUI()
52 for (int i = 0; i < MAX_ITEM_COUNT; i++)
54 View child = new View()
56 Size = new Size(100, 100),
57 BackgroundColor = i % 2 == 0 ? Color.Magenta : Color.Cyan,
60 TextLabel text = new TextLabel("" + (i + 1))
63 Size = new Size(50, 50),
67 layoutView.Add(child);
72 public void InitializeDefaultUI()
74 label = new TextLabel()
76 Text = "Layout Sample",
79 currentWindow.Add(label);
81 layoutView = new View()
83 Size2D = new Size2D(480, 600),
84 Position2D = new Position2D(0, 30),
85 BackgroundColor = Color.Black,
86 Layout = new GridLayout()
88 GridOrientation = GridLayout.Orientation.Vertical,
93 currentWindow.Add(layoutView);
95 View bottomView = new View()
97 Size = new Size(480, 100),
98 Position2D = new Position2D(0, 600),
99 BackgroundColor = Color.Black,
100 Layout = new LinearLayout()
102 LinearOrientation = LinearLayout.Orientation.Horizontal,
103 LinearAlignment = LinearLayout.Alignment.Center,
107 currentWindow.Add(bottomView);
109 Button btn_1 = new Button()
112 Size = new Size(100, 50),
115 Button btn_2 = new Button()
118 Size = new Size(100, 50),
121 btn_1.Clicked += Btn1_Clicked;
122 btn_2.Clicked += Btn2_Clicked;
124 bottomView.Add(btn_1);
125 bottomView.Add(btn_2);
127 bottomView_2 = new View()
129 Size = new Size(480, 100),
130 Position2D = new Position2D(0, 700),
131 BackgroundColor = Color.Black,
132 Layout = new LinearLayout()
134 LinearOrientation = LinearLayout.Orientation.Horizontal,
135 LinearAlignment = LinearLayout.Alignment.Center,
138 currentWindow.Add(bottomView_2);
140 Button btn_5 = new Button()
143 Size = new Size(50, 50),
146 Button btn_6 = new Button()
149 Size = new Size(50, 50),
152 btn_5.Clicked += Btn5_Clicked;
153 btn_6.Clicked += Btn6_Clicked;
155 bottomView_2.Add(btn_5);
156 bottomView_2.Add(btn_6);
159 private void Btn1_Clicked(object sender, ClickedEventArgs e)
161 GridLayout layout = new GridLayout();
163 layout.GridOrientation = GridLayout.Orientation.Vertical;
164 layoutView.Layout = layout;
166 layout.LayoutWithTransition = true;
169 private void Btn2_Clicked(object sender, ClickedEventArgs e)
171 GridLayout layout = new GridLayout();
172 layout.LayoutWithTransition = true;
174 layout.GridOrientation = GridLayout.Orientation.Horizontal;
175 layoutView.Layout = layout;
180 private void Btn5_Clicked(object sender, ClickedEventArgs e)
185 private void Btn6_Clicked(object sender, ClickedEventArgs e)
187 ObjectProcess(false);
190 public void ObjectProcess(bool opt)
192 int nValue = opt ? 1 : -1;
193 switch (layoutOption)
196 (layoutView.Layout as GridLayout).Columns += nValue;
199 (layoutView.Layout as GridLayout).Rows += nValue;
204 public void Deactivate()
207 layoutView.Unparent();
208 bottomView.Unparent();
209 bottomView_2.Unparent();
212 layoutView.Dispose();
213 bottomView.Dispose();
214 bottomView_2.Dispose();