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;
47 private Item[] mViewList = {
48 new Item("PushButton", true), new Item("DropDown", false), new Item("Toggle", false),
49 new Item("InputField", false), new Item("AnimateGif", false), new Item("Loading", false),
50 new Item("ProgressBar", false), new Item("CheckBox", false), new Item("RadioButton", true),
51 new Item("Tooltip", true), new Item("Popup", true), new Item("Toast", true),
52 new Item("ItemView", false), new Item("CheckBox", true)
55 public Example(Dali.Application application)
57 _application = application;
58 _application.Initialized += OnInitialize;
61 public void OnInitialize(object source, NUIApplicationInitEventArgs e)
63 Console.WriteLine("Customized Application Initialize event handler");
64 _stage = Stage.GetCurrent();
65 _stage.BackgroundColor = Color.White;
68 TextLabel topLabel = new TextLabel();
69 topLabel.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
70 topLabel.SetResizePolicy(ResizePolicyType.SIZE_RELATIVE_TO_PARENT, DimensionType.HEIGHT);
71 topLabel.AnchorPoint = NDalic.AnchorPointTopCenter;
72 topLabel.ParentOrigin = NDalic.ParentOriginTopCenter;
73 topLabel.SetSizeModeFactor(new Vector3( 0.0f, 0.1f, 0.0f ) );
74 topLabel.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f);
75 topLabel.TextColor = NDalic.WHITE;
76 topLabel.Text = " DALi Views";
77 topLabel.HorizontalAlignment = "BEGIN";
78 topLabel.VerticalAlignment = "CENTER";
79 topLabel.PointSize = 42.0f;
82 // Grid container to contain items. Use tableView because FlexContainer support focus navigation just two direction ( up/down or left/right )
83 _contentContainer = new TableView(6, 5);
84 _contentContainer.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
85 _contentContainer.SetResizePolicy(ResizePolicyType.SIZE_RELATIVE_TO_PARENT, DimensionType.HEIGHT);
86 _contentContainer.SetSizeModeFactor(new Vector3( 0.0f, 0.9f, 0.0f ) );
87 _contentContainer.AnchorPoint = NDalic.AnchorPointBottomCenter;
88 _contentContainer.ParentOrigin = NDalic.ParentOriginBottomCenter;
89 _contentContainer.SetRelativeHeight(0, 0.07f);
90 _contentContainer.SetRelativeHeight(1, 0.26f);
91 _contentContainer.SetRelativeHeight(2, 0.07f);
92 _contentContainer.SetRelativeHeight(3, 0.26f);
93 _contentContainer.SetRelativeHeight(4, 0.07f);
94 _contentContainer.SetRelativeHeight(5, 0.26f);
95 _contentContainer.SetKeyboardFocusable(true);
96 _stage.Add(_contentContainer);
100 FocusManager.Instance.PreFocusChange += OnPreFocusChange;
103 // Callback for KeyboardFocusManager
104 private Actor OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
106 if (!e.Proposed && !e.Current)
108 e.Proposed = _contentContainer.GetChildAt(1);
113 private void CreateContent()
115 for (int i = 0; i < mViewList.Length; i++)
117 CreateItem(mViewList[i], i);
121 private void CreateItem(Item item, int idx)
123 // Make label for item
124 TextLabel itemLabel = new TextLabel(" " + item.name);
125 itemLabel.Size = new Vector3(_stage.GetSize().Width * 0.2f, _stage.GetSize().Height * 0.05f, 0.0f);
126 itemLabel.HorizontalAlignment = "BEGIN";
127 itemLabel.VerticalAlignment = "BOTTOM";
128 itemLabel.PointSize = 18.0f;
129 _contentContainer.AddChild(itemLabel, new TableView.CellPosition(((uint)idx / 5) * 2, (uint)idx % 5));
131 // If item is implemented in public, attach it on stage
132 if (item.isImplemented)
134 if (item.name.CompareTo("PushButton") == 0)
136 PushButton pushButton = new PushButton();
137 pushButton.LabelText = "Push Button";
138 pushButton.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
139 pushButton.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT);
140 pushButton.UnselectedColor = new Vector4(1.0f,0.0f,0.0f,1.0f);
141 pushButton.SelectedColor = new Vector4(0.0f,1.0f,0.0f,1.0f);
142 pushButton.Clicked += (obj, e) =>
144 e.Button.LabelText = "Click Me";
145 e.Button.UnselectedColor = new Vector4(0.0f,0.0f,1.0f,1.0f);
149 _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
151 if (item.name.CompareTo("DropDown") == 0)
155 if (item.name.CompareTo("Toggle") == 0)
159 if (item.name.CompareTo("InputField") == 0)
163 if (item.name.CompareTo("AnimateGif") == 0)
167 if (item.name.CompareTo("Loading") == 0)
171 if (item.name.CompareTo("ProgressBar") == 0)
175 if (item.name.CompareTo("ScrollBar") == 0)
179 if (item.name.CompareTo("CheckBox") == 0)
181 CheckBoxButton checkBoxButton = new CheckBoxButton();
182 checkBoxButton.LabelText = "Yes";
184 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
186 if (item.name.CompareTo("RadioButton") == 0)
188 TableView tableView = new TableView(2, 1);
189 tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
190 tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT);
192 RadioButton rButton = new RadioButton();
193 rButton.LabelText = "Yes";
194 rButton.Selected = true;
195 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
197 rButton = new RadioButton();
198 rButton.LabelText = "No";
200 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
202 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
204 if (item.name.CompareTo("Tooltip") == 0)
206 TableView tableView = new TableView(2, 1);
207 tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
208 tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT);
210 // Create two push buttons and add them to a table view
211 PushButton buttonWithSimpleTooltip = new PushButton();
212 buttonWithSimpleTooltip.LabelText = "Tooltip with text only";
213 buttonWithSimpleTooltip.UnselectedColor = new Vector4(0.5f,0.5f,0.7f,1.0f);
214 buttonWithSimpleTooltip.SelectedColor = new Vector4(0.7f,0.5f,0.7f,1.0f);
215 buttonWithSimpleTooltip.WidthResizePolicy = "FILL_TO_PARENT";
216 tableView.AddChild(buttonWithSimpleTooltip, new TableView.CellPosition(0, 0));
218 PushButton buttonWithIconTooltip = new PushButton();
219 buttonWithIconTooltip.LabelText = "Tooltip with Text and Icon";
220 buttonWithIconTooltip.WidthResizePolicy = "FILL_TO_PARENT";
221 buttonWithIconTooltip.UnselectedColor = new Vector4(0.5f,0.5f,0.7f,1.0f);
222 buttonWithIconTooltip.SelectedColor = new Vector4(0.7f,0.5f,0.7f,1.0f);
223 tableView.AddChild(buttonWithIconTooltip, new TableView.CellPosition(1, 0));
225 // Add a simple text only tooltip to the first push button
226 buttonWithSimpleTooltip.TooltipText = "Simple Tooltip";
228 // Create a property map for a tooltip with one icon and one text
229 Property.Array iconTooltipContent = new Property.Array();
231 Property.Map iconVisual = new Property.Map();
232 iconVisual.Add( Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Image) )
233 .Add( Dali.Constants.ImageVisualProperty.URL, new Property.Value("./images/star-highlight.png") );
234 iconTooltipContent.Add(new Property.Value(iconVisual));
236 Property.Map textVisual = new Property.Map();
237 textVisual.Add( Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Text) )
238 .Add( Dali.Constants.TextVisualProperty.Text, new Property.Value("Tooltip with Icon") );
239 iconTooltipContent.Add(new Property.Value(textVisual));
241 Property.Map iconTooltip = new Property.Map();
242 iconTooltip.Add( Dali.Constants.Tooltip.Property.Content, new Property.Value(iconTooltipContent) )
243 .Add( Dali.Constants.Tooltip.Property.Tail, new Property.Value(true) );
245 // Add the tooltip with icon and text to the second push button
246 buttonWithIconTooltip.Tooltip = iconTooltip;
248 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
250 if (item.name.CompareTo("Popup") == 0)
252 PushButton button = new PushButton();
253 button.LabelText = "Popup";
254 button.ParentOrigin = NDalic.ParentOriginCenter;
255 button.AnchorPoint = NDalic.AnchorPointCenter;
256 button.MaximumSize = new Vector2(90.0f,50.0f);
257 _popup = CreatePopup();
258 _popup.SetTitle(CreateTitle("Popup"));
260 TextLabel text = new TextLabel("This will erase the file permanently. Are you sure?");
261 text.BackgroundColor = Color.White;
262 text.MultiLine = true;
263 text.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
264 text.SetResizePolicy(ResizePolicyType.DIMENSION_DEPENDENCY, DimensionType.HEIGHT);
265 text.SetPadding(new RectFloat(10.0f, 10.0f, 20.0f, 0.0f));
266 _popup.SetContent(text);
267 _popup.SetKeyboardFocusable(true);
268 _popup.SetDisplayState(Popup.DisplayStateType.HIDDEN);
270 button.Clicked += (obj, ee) =>
273 _popup.SetDisplayState(Popup.DisplayStateType.SHOWN);
274 FocusManager.Instance.SetCurrentFocusActor((_popup.FindChildByName( "Footer" )).FindChildByName("OKButton"));
277 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
279 if (item.name.CompareTo("Toast") == 0)
281 PushButton button = new PushButton();
282 button.LabelText = "Toast";
283 button.ParentOrigin = NDalic.ParentOriginCenter;
284 button.AnchorPoint = NDalic.AnchorPointCenter;
285 button.Clicked += (obj, ee) =>
287 TypeInfo typeInfo = new TypeInfo(TypeRegistry.Get().GetTypeInfo( "PopupToast" ));
290 BaseHandle baseHandle = typeInfo.CreateInstance();
293 Popup toast = Popup.DownCast( baseHandle );
294 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
295 text.TextColor = Color.White;
296 text.MultiLine = true;
297 text.HorizontalAlignment = "center";
298 toast.SetTitle( text);
300 toast.SetDisplayState( Popup.DisplayStateType.SHOWN);
305 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
307 if (item.name.CompareTo("ItemView") == 0)
314 ImageView notSupportView = new ImageView("images/not_yet_sign.png");
315 notSupportView.Size = new Vector3(_stage.GetSize().Width * 0.2f, _stage.GetSize().Height * 0.25f, 0.0f);
316 notSupportView.SetKeyboardFocusable(true);
317 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
322 Popup confirmationPopup = new Popup();
324 Actor footer = new Actor();
325 footer.SetName("Footer");
326 footer.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
327 footer.SetResizePolicy(ResizePolicyType.FIXED, DimensionType.HEIGHT);
328 footer.SetSize(0.0f, 80.0f);
329 footer.ParentOrigin = NDalic.ParentOriginCenter;
330 footer.AnchorPoint = NDalic.AnchorPointCenter;
332 PushButton okButton = CreateOKButton();
333 okButton.ParentOrigin = NDalic.ParentOriginCenter;
334 okButton.AnchorPoint = NDalic.AnchorPointCenter;
335 okButton.SetResizePolicy(ResizePolicyType.SIZE_FIXED_OFFSET_FROM_PARENT, DimensionType.ALL_DIMENSIONS);
336 okButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
338 PushButton cancelButton = CreateCancelButton();
339 cancelButton.ParentOrigin = NDalic.ParentOriginCenter;
340 cancelButton.AnchorPoint = NDalic.AnchorPointCenter;
341 cancelButton.SetResizePolicy(ResizePolicyType.SIZE_FIXED_OFFSET_FROM_PARENT, DimensionType.ALL_DIMENSIONS);
342 cancelButton.SetSizeModeFactor(new Vector3(-20.0f, -20.0f, 0.0f));
344 TableView controlLayout = new TableView(1, 2);
345 controlLayout.ParentOrigin = NDalic.ParentOriginCenter;
346 controlLayout.AnchorPoint = NDalic.AnchorPointCenter;
347 controlLayout.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.ALL_DIMENSIONS);
348 controlLayout.SetCellPadding(new Size(10.0f, 10.0f));
349 controlLayout.SetRelativeWidth(0, 0.5f);
350 controlLayout.SetRelativeWidth(1, 0.5f);
351 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.CENTER, VerticalAlignmentType.CENTER);
352 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.CENTER, VerticalAlignmentType.CENTER);
353 controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
354 controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
356 footer.Add(controlLayout);
358 confirmationPopup.SetFooter(footer);
359 return confirmationPopup;
361 Actor CreateTitle(string title)
363 TextLabel titleActor = new TextLabel(title);
364 titleActor.TextColor = Color.White;
365 titleActor.MultiLine = true;
366 titleActor.HorizontalAlignment = "center";
370 PushButton CreateOKButton()
372 PushButton okayButton = new PushButton();
373 okayButton.SetName("OKButton");
374 okayButton.LabelText = "OK";
375 okayButton.SetKeyboardFocusable(true);
376 okayButton.Clicked += (obj, ee) =>
378 _popup.SetDisplayState(Popup.DisplayStateType.HIDDEN);
383 PushButton CreateCancelButton()
385 PushButton cancelButton = new PushButton();
386 cancelButton.LabelText = "Cancel";
387 cancelButton.SetKeyboardFocusable(true);
388 cancelButton.Clicked += (obj, ee) =>
390 _popup.SetDisplayState(Popup.DisplayStateType.HIDDEN);
396 public void MainLoop()
398 _application.MainLoop();
402 /// The main entry point for the application.
406 static void Main(string[] args)
408 Console.WriteLine("Hello Mono World");
410 Example example = new Example(Application.NewApplication());