Merge "Add push-button sample for dashboard" 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", true),  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             FocusManager.Instance.PreFocusChange += OnPreFocusChange;
100         }
101
102         // Callback for KeyboardFocusManager
103         private Actor OnPreFocusChange(object source, FocusManager.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                     PushButton pushButton = new PushButton();
136                     pushButton.LabelText = "Push Button";
137                     pushButton.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
138                     pushButton.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT);
139                     pushButton.UnselectedColor = new Vector4(1.0f,0.0f,0.0f,1.0f);
140                     pushButton.SelectedColor = new Vector4(0.0f,1.0f,0.0f,1.0f);
141                     pushButton.Clicked += (obj, e) =>
142                     {
143                         e.Button.LabelText = "Click Me";
144                         e.Button.UnselectedColor = new Vector4(0.0f,0.0f,1.0f,1.0f);
145                         return true;
146                     };
147
148                     _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
149                 }
150                 if (item.name.CompareTo("DropDown") == 0)
151                 {
152
153                 }
154                 if (item.name.CompareTo("Toggle") == 0)
155                 {
156
157                 }
158                 if (item.name.CompareTo("InputField") == 0)
159                 {
160
161                 }
162                 if (item.name.CompareTo("AnimateGif") == 0)
163                 {
164
165                 }
166                 if (item.name.CompareTo("Loading") == 0)
167                 {
168
169                 }
170                 if (item.name.CompareTo("ProgressBar") == 0)
171                 {
172
173                 }
174                 if (item.name.CompareTo("ScrollBar") == 0)
175                 {
176
177                 }
178                 if (item.name.CompareTo("CheckBox") == 0)
179                 {
180                     CheckBoxButton checkBoxButton = new CheckBoxButton();
181                     checkBoxButton.LabelText = "Yes";
182
183                     _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
184                 }
185                 if (item.name.CompareTo("RadioButton") == 0)
186                 {
187                     TableView tableView = new TableView(2, 1);
188                     tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
189                     tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT);
190
191                     RadioButton rButton = new RadioButton();
192                     rButton.LabelText = "Yes";
193                     rButton.Selected = true;
194                     tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
195
196                     rButton = new RadioButton();
197                     rButton.LabelText = "No";
198
199                     tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
200
201                     _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
202                 }
203                 if (item.name.CompareTo("Tooltip") == 0)
204                 {
205
206                 }
207                 if (item.name.CompareTo("Popup") == 0)
208                 {
209
210                 }
211                 if (item.name.CompareTo("Toast") == 0)
212                 {
213
214                 }
215                 if (item.name.CompareTo("ItemView") == 0)
216                 {
217
218                 }
219             }
220             else
221             {
222                 ImageView notSupportView = new ImageView("images/not_yet_sign.png");
223                 notSupportView.Size = new Vector3(_stage.GetSize().width * 0.2f, _stage.GetSize().height * 0.25f, 0.0f);
224                 notSupportView.SetKeyboardFocusable(true);
225                 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
226             }
227         }
228
229         public void MainLoop()
230         {
231             _application.MainLoop();
232         }
233
234         /// <summary>
235         /// The main entry point for the application.
236         /// </summary>
237
238         [STAThread]
239         static void Main(string[] args)
240         {
241             Console.WriteLine("Hello Mono World");
242
243             Example example = new Example(Application.NewApplication());
244             example.MainLoop();
245         }
246     }
247 }