2 * Copyright (c) 2016 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.
19 using System.Runtime.InteropServices;
22 namespace MyCSharpExample
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
32 public bool isImplemented;
34 public Item(String name, bool isImplemented)
37 this.isImplemented = isImplemented;
41 private Dali.Application _application;
42 private TableView _contentContainer;
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)
54 public Example(Dali.Application application)
56 _application = application;
57 _application.Initialized += OnInitialize;
60 public void OnInitialize(object source, AUIApplicationInitEventArgs e)
62 Console.WriteLine("Customized Application Initialize event handler");
63 _stage = Stage.GetCurrent();
64 _stage.BackgroundColor = Color.White;
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;
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);
99 FocusManager.Instance.PreFocusChange += OnPreFocusChange;
102 // Callback for KeyboardFocusManager
103 private Actor OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
105 if (!e.Proposed && !e.Current)
107 e.Proposed = _contentContainer.GetChildAt(1);
112 private void CreateContent()
114 for (int i = 0; i < mViewList.Length; i++)
116 CreateItem(mViewList[i], i);
120 private void CreateItem(Item item, int idx)
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));
130 // If item is implemented in public, attach it on stage
131 if (item.isImplemented)
133 if (item.name.CompareTo("PushButton") == 0)
137 if (item.name.CompareTo("DropDown") == 0)
141 if (item.name.CompareTo("Toggle") == 0)
145 if (item.name.CompareTo("InputField") == 0)
149 if (item.name.CompareTo("AnimateGif") == 0)
153 if (item.name.CompareTo("Loading") == 0)
157 if (item.name.CompareTo("ProgressBar") == 0)
161 if (item.name.CompareTo("ScrollBar") == 0)
165 if (item.name.CompareTo("CheckBox") == 0)
167 CheckBoxButton checkBoxButton = new CheckBoxButton();
168 checkBoxButton.LabelText = "Yes";
170 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
172 if (item.name.CompareTo("RadioButton") == 0)
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);
178 RadioButton rButton = new RadioButton();
179 rButton.LabelText = "Yes";
180 rButton.Selected = true;
181 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
183 rButton = new RadioButton();
184 rButton.LabelText = "No";
186 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
188 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
190 if (item.name.CompareTo("Tooltip") == 0)
194 if (item.name.CompareTo("Popup") == 0)
198 if (item.name.CompareTo("Toast") == 0)
202 if (item.name.CompareTo("ItemView") == 0)
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));
216 public void MainLoop()
218 _application.MainLoop();
222 /// The main entry point for the application.
226 static void Main(string[] args)
228 Console.WriteLine("Hello Mono World");
230 Example example = new Example(Application.NewApplication());