Version update - 22234
[platform/core/csapi/tizenfx.git] / test / NUIWindowLayout / NUIWindowLayout.cs
1 using System;
2 using Tizen.NUI;
3 using Tizen.NUI.BaseComponents;
4 using Tizen.NUI.Components;
5 using System.Collections.Generic;
6
7 namespace NUIWindowLayout
8 {
9     class Program : NUIApplication
10     {
11         private uint numOfWindows;
12         private List<Window> windows = new List<Window>();
13         private Color[] colors = { Color.DarkGreen, Color.Aqua, Color.Coral, Color.DimGrey };
14
15         public Program(uint numOfWindows) : base(ThemeOptions.None, new DefaultBorder())
16         {
17             if (numOfWindows > 0 && numOfWindows <= 4)
18             {
19                 this.numOfWindows = numOfWindows;
20             }
21             else
22             {
23                 Tizen.Log.Error("WindowLayout", "numOfWindows is not valid. Put 0 < numOfWindows <= 4");
24             }
25         }
26         protected override void OnCreate()
27         {
28             base.OnCreate();
29             Window window = NUIApplication.GetDefaultWindow();
30             window.KeyEvent += OnKeyEvent;
31             Initialize();
32         }
33
34         void Initialize()
35         {
36             windows.Add(NUIApplication.GetDefaultWindow());
37
38             for (int i = 1; i < numOfWindows; i++)
39             {
40                 windows.Add(new Window((i + 1).ToString() + "window", new DefaultBorder()));
41             }
42
43             for (int i = 0; i < numOfWindows; i++)
44             {
45                 Window window = windows[i];
46                 window.BackgroundColor = colors[i];
47
48                 ScrollableBase scrollableBase = new ScrollableBase();
49                 scrollableBase.WidthSpecification = LayoutParamPolicies.MatchParent;
50                 scrollableBase.HeightSpecification = LayoutParamPolicies.MatchParent;
51                 scrollableBase.ScrollingDirection = ScrollableBase.Direction.Vertical;
52
53                 scrollableBase.Layout = new LinearLayout()
54                 {
55                     LinearOrientation = LinearLayout.Orientation.Vertical,
56                     HorizontalAlignment = HorizontalAlignment.Center,
57                     VerticalAlignment = VerticalAlignment.Center,
58                 };
59
60                 for (int idxType = 0; idxType < System.Enum.GetValues(typeof(WindowLayoutType)).Length; idxType++)
61                 {
62                     Button button = new Button();
63                     button.TextLabel.Text = idxType.ToString() + "." + (WindowLayoutType)idxType; // Set text to the enum value
64                     button.Size = new Size(200, 50);
65
66                     button.Clicked += (object sender, ClickedEventArgs e) =>
67                     {
68                         int number;
69                         number = int.Parse(((Button)sender).TextLabel.Text.Split('.')[0]);
70                         WindowLayoutType type = (WindowLayoutType)number;
71                         Tizen.Log.Info("WindowLayout", type.ToString());
72                         window.SetLayout((WindowLayoutType)number);
73                     };
74                     scrollableBase.Add(button);
75                 }
76
77                 window.Add(scrollableBase);
78             }
79         }
80
81         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
82         {
83             if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
84             {
85                 Exit();
86             }
87         }
88
89         static void Main(string[] args)
90         {
91             var app = new Program(4);
92             app.Run(args);
93         }
94     }
95 }