[NUI] Add GridLaoyt Sample (#1485)
authorhuiyueun <35286162+huiyueun@users.noreply.github.com>
Wed, 25 Mar 2020 03:20:25 +0000 (12:20 +0900)
committerGitHub <noreply@github.com>
Wed, 25 Mar 2020 03:20:25 +0000 (12:20 +0900)
Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/GridLayoutSample.cs [new file with mode: 0755]

diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/GridLayoutSample.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/GridLayoutSample.cs
new file mode 100755 (executable)
index 0000000..6f111f1
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+using System;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+
+namespace Tizen.NUI.Samples
+{
+    class GridExample : IExample
+    {
+        private Window currentWindow;
+        private static int MAX_ITEM_COUNT = 31;
+        private int layoutOption = 3;
+
+        private View layoutView;
+        private TextLabel label;
+        private View bottomView;
+        private View bottomView_2;
+
+        public void Activate()
+        {
+            Initialize();
+        }
+
+        public void Initialize()
+        {
+            currentWindow = NUIApplication.GetDefaultWindow();
+            currentWindow.BackgroundColor = Color.White;
+
+            InitializeDefaultUI();
+            InitializeLayoutUI();
+        }
+
+        public void InitializeLayoutUI()
+        {
+            for (int i = 0; i < MAX_ITEM_COUNT; i++)
+            {
+                View child = new View()
+                {
+                    Size = new Size(100, 100),
+                    BackgroundColor = i % 2 == 0 ? Color.Magenta : Color.Cyan,
+                };
+
+                TextLabel text = new TextLabel("" + (i + 1))
+                {
+                    PointSize = 14,
+                    Size = new Size(50, 50),
+                };
+
+                child.Add(text);
+                layoutView.Add(child);
+            }
+
+        }
+
+        public void InitializeDefaultUI()
+        {
+            label = new TextLabel()
+            {
+                Text = "Layout Sample",
+                PointSize = 20,
+            };
+            currentWindow.Add(label);
+
+            layoutView = new View()
+            {
+                Size2D = new Size2D(480, 600),
+                Position2D = new Position2D(0, 30),
+                BackgroundColor = Color.Black,
+                Layout = new GridLayout()
+                {
+                    LinearOrientation = GridLayout.Orientation.Vertical,
+                    Columns = 5,
+                },
+
+            };
+            currentWindow.Add(layoutView);
+
+            View bottomView = new View()
+            {
+                Size = new Size(480, 100),
+                Position2D = new Position2D(0, 600),
+                BackgroundColor = Color.Black,
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Horizontal,
+                    LinearAlignment = LinearLayout.Alignment.Center,
+                }
+
+            };
+            currentWindow.Add(bottomView);
+
+            Button btn_1 = new Button()
+            {
+                Text = "Grid_V",
+                Size = new Size(100, 50),
+                Margin = 10,
+            };
+            Button btn_2 = new Button()
+            {
+                Text = "Grid_H",
+                Size = new Size(100, 50),
+                Margin = 10,
+            };
+            btn_1.ClickEvent += Btn1_ClickEvent;
+            btn_2.ClickEvent += Btn2_ClickEvent;
+
+            bottomView.Add(btn_1);
+            bottomView.Add(btn_2);
+
+            bottomView_2 = new View()
+            {
+                Size = new Size(480, 100),
+                Position2D = new Position2D(0, 700),
+                BackgroundColor = Color.Black,
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Horizontal,
+                    LinearAlignment = LinearLayout.Alignment.Center,
+                }
+            };
+            currentWindow.Add(bottomView_2);
+
+            Button btn_5 = new Button()
+            {
+                Text = "++",
+                Size = new Size(50, 50),
+                Margin = 10,
+            };
+            Button btn_6 = new Button()
+            {
+                Text = "--",
+                Size = new Size(50, 50),
+                Margin = 10,
+            };
+            btn_5.ClickEvent += Btn5_ClickEvent;
+            btn_6.ClickEvent += Btn6_ClickEvent;
+
+            bottomView_2.Add(btn_5);
+            bottomView_2.Add(btn_6);
+        }
+
+        private void Btn1_ClickEvent(object sender, Button.ClickEventArgs e)
+        {
+            GridLayout layout = new GridLayout();
+            layout.Columns = 5;
+            layout.LinearOrientation = GridLayout.Orientation.Vertical;
+            layoutView.Layout = layout;
+            layoutOption = 1;
+            layout.LayoutWithTransition = true;
+        }
+
+        private void Btn2_ClickEvent(object sender, Button.ClickEventArgs e)
+        {
+            GridLayout layout = new GridLayout();
+            layout.LayoutWithTransition = true;
+            layout.Rows = 5;
+            layout.LinearOrientation = GridLayout.Orientation.Horizontal;
+            layoutView.Layout = layout;
+
+            layoutOption = 2;
+        }
+
+        private void Btn5_ClickEvent(object sender, Button.ClickEventArgs e)
+        {
+            ObjectProcess(true);
+        }
+
+        private void Btn6_ClickEvent(object sender, Button.ClickEventArgs e)
+        {
+            ObjectProcess(false);
+        }
+
+        public void ObjectProcess(bool opt)
+        {
+            int nValue = opt ? 1 : -1;
+            switch (layoutOption)
+            {
+                case 1:
+                    (layoutView.Layout as GridLayout).Columns += nValue;
+                    break;
+                case 2:
+                    (layoutView.Layout as GridLayout).Rows += nValue;
+                    break;
+            }
+        }
+
+        public void Deactivate()
+        {
+            label.Unparent();
+            layoutView.Unparent();
+            bottomView.Unparent();
+            bottomView_2.Unparent();
+
+            label.Dispose();
+            layoutView.Dispose();
+            bottomView.Dispose();
+            bottomView_2.Dispose();
+
+            label = null;
+            layoutView = null;
+            bottomView = null;
+            bottomView_2 = null;
+        }
+    }
+}