Merge "C# control dashboard demo" into devel/master
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / examples / control-dashboard.cs
1 /*
2  * Copyright (c) 2016 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
18 using System;
19 using System.Runtime.InteropServices;
20 using Dali;
21
22 namespace MyCSharpExample
23 {
24     class Example
25     {
26         // This is simple structure to contain Control name and implement state at once
27         // name : control name
28         // isImplemented : the state which the control is implemented in public or not
29         private struct Item
30         {
31             public String name;
32             public bool isImplemented;
33
34             public Item(String name, bool isImplemented)
35             {
36                 this.name = name;
37                 this.isImplemented = isImplemented;
38             }
39         }
40
41         private Dali.Application _application;
42         private TableView _contentContainer;
43         private Stage _stage;
44
45         // List of items
46         private Item[] mViewList = {
47             new Item("PushButton", false),  new Item("DropDown", false),    new Item("Toggle", false),
48             new Item("InputField", false),  new Item("AnimateGif", false),  new Item("Loading", false),
49             new Item("ProgressBar", false), new Item("CheckBox", false),    new Item("RadioButton", true),
50             new Item("Tooltip", false),     new Item("Popup", false),       new Item("Toast", false),
51             new Item("ItemView", false),    new Item("CheckBox", true)
52         };
53
54         public Example(Dali.Application application)
55         {
56             _application = application;
57             _application.Initialized += OnInitialize;
58         }
59
60         public void OnInitialize(object source, AUIApplicationInitEventArgs e)
61         {
62             Console.WriteLine("Customized Application Initialize event handler");
63             _stage = Stage.GetCurrent();
64             _stage.BackgroundColor = Color.White;
65
66             // Top label
67             TextLabel topLabel = new TextLabel();
68             topLabel.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
69             topLabel.SetResizePolicy(ResizePolicyType.SIZE_RELATIVE_TO_PARENT, DimensionType.HEIGHT);
70             topLabel.AnchorPoint = NDalic.AnchorPointTopCenter;
71             topLabel.ParentOrigin = NDalic.ParentOriginTopCenter;
72             topLabel.SetSizeModeFactor(new Vector3( 0.0f, 0.1f, 0.0f ) );
73             topLabel.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
74             topLabel.TextColor = NDalic.WHITE;
75             topLabel.Text = " DALi Views";
76             topLabel.HorizontalAlignment = "BEGIN";
77             topLabel.VerticalAlignment = "CENTER";
78             topLabel.PointSize = 42.0f;
79             _stage.Add(topLabel);
80
81             // Grid container to contain items. Use tableView because FlexContainer support focus navigation just two direction ( up/down or left/right )
82             _contentContainer = new TableView(6, 5);
83             _contentContainer.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
84             _contentContainer.SetResizePolicy(ResizePolicyType.SIZE_RELATIVE_TO_PARENT, DimensionType.HEIGHT);
85             _contentContainer.SetSizeModeFactor(new Vector3( 0.0f, 0.9f, 0.0f ) );
86             _contentContainer.AnchorPoint = NDalic.AnchorPointBottomCenter;
87             _contentContainer.ParentOrigin = NDalic.ParentOriginBottomCenter;
88             _contentContainer.SetRelativeHeight(0, 0.07f);
89             _contentContainer.SetRelativeHeight(1, 0.26f);
90             _contentContainer.SetRelativeHeight(2, 0.07f);
91             _contentContainer.SetRelativeHeight(3, 0.26f);
92             _contentContainer.SetRelativeHeight(4, 0.07f);
93             _contentContainer.SetRelativeHeight(5, 0.26f);
94             _contentContainer.SetKeyboardFocusable(true);
95             _stage.Add(_contentContainer);
96
97             CreateContent();
98
99             KeyboardFocusManager.Get().PreFocusChange += OnPreFocusChange;
100         }
101
102         // Callback for KeyboardFocusManager
103         private Actor OnPreFocusChange(object source, KeyboardFocusManager.PreFocusChangeEventArgs e)
104         {
105             if (!e.Proposed && !e.Current)
106             {
107                 e.Proposed = _contentContainer.GetChildAt(1);
108             }
109             return e.Proposed;
110         }
111
112         private void CreateContent()
113         {
114             for (int i = 0; i < mViewList.Length; i++)
115             {
116                 CreateItem(mViewList[i], i);
117             }
118         }
119
120         private void CreateItem(Item item, int idx)
121         {
122             // Make label for item
123             TextLabel itemLabel = new TextLabel("    " + item.name);
124             itemLabel.Size = new Vector3(_stage.GetSize().width * 0.2f, _stage.GetSize().height * 0.05f, 0.0f);
125             itemLabel.HorizontalAlignment = "BEGIN";
126             itemLabel.VerticalAlignment = "BOTTOM";
127             itemLabel.PointSize = 18.0f;
128             _contentContainer.AddChild(itemLabel, new TableView.CellPosition(((uint)idx / 5) * 2, (uint)idx % 5));
129
130             // If item is implemented in public, attach it on stage
131             if (item.isImplemented)
132             {
133                 if (item.name.CompareTo("PushButton") == 0)
134                 {
135
136                 }
137                 if (item.name.CompareTo("DropDown") == 0)
138                 {
139
140                 }
141                 if (item.name.CompareTo("Toggle") == 0)
142                 {
143
144                 }
145                 if (item.name.CompareTo("InputField") == 0)
146                 {
147
148                 }
149                 if (item.name.CompareTo("AnimateGif") == 0)
150                 {
151
152                 }
153                 if (item.name.CompareTo("Loading") == 0)
154                 {
155
156                 }
157                 if (item.name.CompareTo("ProgressBar") == 0)
158                 {
159
160                 }
161                 if (item.name.CompareTo("ScrollBar") == 0)
162                 {
163
164                 }
165                 if (item.name.CompareTo("CheckBox") == 0)
166                 {
167                     CheckBoxButton checkBoxButton = new CheckBoxButton();
168                     checkBoxButton.LabelText = "Yes";
169
170                     _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
171                 }
172                 if (item.name.CompareTo("RadioButton") == 0)
173                 {
174                     TableView tableView = new TableView(2, 1);
175                     tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
176                     tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT);
177
178                     RadioButton rButton = new RadioButton();
179                     rButton.LabelText = "Yes";
180                     rButton.Selected = true;
181                     tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
182
183                     rButton = new RadioButton();
184                     rButton.LabelText = "No";
185
186                     tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
187
188                     _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
189                 }
190                 if (item.name.CompareTo("Tooltip") == 0)
191                 {
192
193                 }
194                 if (item.name.CompareTo("Popup") == 0)
195                 {
196
197                 }
198                 if (item.name.CompareTo("Toast") == 0)
199                 {
200
201                 }
202                 if (item.name.CompareTo("ItemView") == 0)
203                 {
204
205                 }
206             }
207             else
208             {
209                 ImageView notSupportView = new ImageView("images/not_yet_sign.png");
210                 notSupportView.Size = new Vector3(_stage.GetSize().width * 0.2f, _stage.GetSize().height * 0.25f, 0.0f);
211                 notSupportView.SetKeyboardFocusable(true);
212                 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
213             }
214         }
215
216         public void MainLoop()
217         {
218             _application.MainLoop();
219         }
220
221         /// <summary>
222         /// The main entry point for the application.
223         /// </summary>
224
225         [STAThread]
226         static void Main(string[] args)
227         {
228             Console.WriteLine("Hello Mono World");
229
230             Example example = new Example(Application.NewApplication());
231             example.MainLoop();
232         }
233     }
234 }