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", 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)
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)
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) =>
143 e.Button.LabelText = "Click Me";
144 e.Button.UnselectedColor = new Vector4(0.0f,0.0f,1.0f,1.0f);
148 _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
150 if (item.name.CompareTo("DropDown") == 0)
154 if (item.name.CompareTo("Toggle") == 0)
158 if (item.name.CompareTo("InputField") == 0)
162 if (item.name.CompareTo("AnimateGif") == 0)
166 if (item.name.CompareTo("Loading") == 0)
170 if (item.name.CompareTo("ProgressBar") == 0)
174 if (item.name.CompareTo("ScrollBar") == 0)
178 if (item.name.CompareTo("CheckBox") == 0)
180 CheckBoxButton checkBoxButton = new CheckBoxButton();
181 checkBoxButton.LabelText = "Yes";
183 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
185 if (item.name.CompareTo("RadioButton") == 0)
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);
191 RadioButton rButton = new RadioButton();
192 rButton.LabelText = "Yes";
193 rButton.Selected = true;
194 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
196 rButton = new RadioButton();
197 rButton.LabelText = "No";
199 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
201 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
203 if (item.name.CompareTo("Tooltip") == 0)
207 if (item.name.CompareTo("Popup") == 0)
211 if (item.name.CompareTo("Toast") == 0)
215 if (item.name.CompareTo("ItemView") == 0)
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));
229 public void MainLoop()
231 _application.MainLoop();
235 /// The main entry point for the application.
239 static void Main(string[] args)
241 Console.WriteLine("Hello Mono World");
243 Example example = new Example(Application.NewApplication());