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 NUI.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", false), new Item("Popup", true), new Item("Toast", true),
52 new Item("ItemView", false), new Item("CheckBox", true)
55 public Example(NUI.Application application)
57 _application = application;
58 _application.Initialized += OnInitialize;
61 public void OnInitialize(object source, EventArgs 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.SizeModeFactor = 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.SetStyleName("TextLabelFontSize4");
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.SizeModeFactor = 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.StateFocusEnable = true;
96 _stage.Add(_contentContainer);
100 FocusManager.Instance.PreFocusChange += OnPreFocusChange;
103 // Callback for KeyboardFocusManager
104 private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
106 if (!e.Proposed && !e.Current)
108 e.Proposed = _contentContainer.GetChildViewAt(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 = 10.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 Button sender = (Button)(obj);
145 sender.LabelText = "Click Me";
146 sender.UnselectedColor = new Vector4(0.0f,0.0f,1.0f,1.0f);
150 _contentContainer.AddChild(pushButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
152 if (item.name.CompareTo("DropDown") == 0)
156 if (item.name.CompareTo("Toggle") == 0)
160 if (item.name.CompareTo("InputField") == 0)
164 if (item.name.CompareTo("AnimateGif") == 0)
168 if (item.name.CompareTo("Loading") == 0)
172 if (item.name.CompareTo("ProgressBar") == 0)
176 if (item.name.CompareTo("ScrollBar") == 0)
180 if (item.name.CompareTo("CheckBox") == 0)
182 CheckBoxButton checkBoxButton = new CheckBoxButton();
183 checkBoxButton.LabelText = "Yes";
185 _contentContainer.AddChild(checkBoxButton, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
187 if (item.name.CompareTo("RadioButton") == 0)
189 TableView tableView = new TableView(2, 1);
190 tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
191 tableView.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.HEIGHT);
193 RadioButton rButton = new RadioButton();
194 rButton.LabelText = "Yes";
195 rButton.Selected = true;
196 tableView.AddChild(rButton, new TableView.CellPosition(0, 0));
198 rButton = new RadioButton();
199 rButton.LabelText = "No";
201 tableView.AddChild(rButton, new TableView.CellPosition(1, 0));
203 _contentContainer.AddChild(tableView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
205 if (item.name.CompareTo("Tooltip") == 0)
209 if (item.name.CompareTo("Popup") == 0)
211 PushButton button = new PushButton();
212 button.LabelText = "Popup";
213 button.ParentOrigin = NDalic.ParentOriginCenter;
214 button.AnchorPoint = NDalic.AnchorPointCenter;
215 //button.MaximumSize = new Vector2(90.0f,50.0f);
216 _popup = CreatePopup();
217 _popup.SetTitle(CreateTitle("Popup"));
219 TextLabel text = new TextLabel("This will erase the file permanently. Are you sure?");
220 text.BackgroundColor = Color.White;
221 text.MultiLine = true;
222 text.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
223 text.SetResizePolicy(ResizePolicyType.DIMENSION_DEPENDENCY, DimensionType.HEIGHT);
224 text.SetPadding(new RectFloat(10.0f, 10.0f, 20.0f, 0.0f));
225 _popup.SetContent(text);
226 _popup.StateFocusEnable = true;
227 _popup.SetDisplayState(Popup.DisplayStateType.HIDDEN);
229 button.Clicked += (obj, ee) =>
232 _popup.SetDisplayState(Popup.DisplayStateType.SHOWN);
233 FocusManager.Instance.SetCurrentFocusView(View.DownCast((_popup.FindChildByName( "Footer" )).FindChildByName("OKButton")));
236 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
238 if (item.name.CompareTo("Toast") == 0)
240 PushButton button = new PushButton();
241 button.LabelText = "Toast";
242 button.ParentOrigin = NDalic.ParentOriginCenter;
243 button.AnchorPoint = NDalic.AnchorPointCenter;
244 button.Clicked += (obj, ee) =>
246 TypeInfo typeInfo = new TypeInfo(TypeRegistry.Get().GetTypeInfo( "PopupToast" ));
249 BaseHandle baseHandle = typeInfo.CreateInstance();
252 Popup toast = Popup.DownCast( baseHandle );
253 TextLabel text = new TextLabel("This is a Toast.\nIt will auto-hide itself");
254 text.TextColor = Color.White;
255 text.MultiLine = true;
256 text.HorizontalAlignment = "center";
257 toast.SetTitle( text);
259 toast.SetDisplayState( Popup.DisplayStateType.SHOWN);
264 _contentContainer.AddChild(button, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
266 if (item.name.CompareTo("ItemView") == 0)
273 ImageView notSupportView = new ImageView("/home/owner/apps_rw/NUISamples.Tizen/res/images/not_yet_sign.png");
274 notSupportView.Size = new Vector3(_stage.GetSize().Width * 0.2f, _stage.GetSize().Height * 0.25f, 0.0f);
275 notSupportView.StateFocusEnable = true;
276 _contentContainer.AddChild(notSupportView, new TableView.CellPosition(((uint)idx / 5) * 2 + 1, (uint)idx % 5));
281 Popup confirmationPopup = new Popup();
283 Actor footer = new Actor();
284 footer.SetName("Footer");
285 footer.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.WIDTH);
286 footer.SetResizePolicy(ResizePolicyType.FIXED, DimensionType.HEIGHT);
287 footer.Size = new Size3D(new Size(0.0f, 80.0f));
288 footer.ParentOrigin = NDalic.ParentOriginCenter;
289 footer.AnchorPoint = NDalic.AnchorPointCenter;
291 PushButton okButton = CreateOKButton();
292 okButton.ParentOrigin = NDalic.ParentOriginCenter;
293 okButton.AnchorPoint = NDalic.AnchorPointCenter;
294 okButton.SetResizePolicy(ResizePolicyType.SIZE_FIXED_OFFSET_FROM_PARENT, DimensionType.ALL_DIMENSIONS);
295 okButton.SizeModeFactor = new Vector3(-20.0f, -20.0f, 0.0f);
297 PushButton cancelButton = CreateCancelButton();
298 cancelButton.ParentOrigin = NDalic.ParentOriginCenter;
299 cancelButton.AnchorPoint = NDalic.AnchorPointCenter;
300 cancelButton.SetResizePolicy(ResizePolicyType.SIZE_FIXED_OFFSET_FROM_PARENT, DimensionType.ALL_DIMENSIONS);
301 cancelButton.SizeModeFactor = new Vector3(-20.0f, -20.0f, 0.0f);
303 TableView controlLayout = new TableView(1, 2);
304 controlLayout.ParentOrigin = NDalic.ParentOriginCenter;
305 controlLayout.AnchorPoint = NDalic.AnchorPointCenter;
306 controlLayout.SetResizePolicy(ResizePolicyType.FILL_TO_PARENT, DimensionType.ALL_DIMENSIONS);
307 controlLayout.SetCellPadding(new Size(10.0f, 10.0f));
308 controlLayout.SetRelativeWidth(0, 0.5f);
309 controlLayout.SetRelativeWidth(1, 0.5f);
310 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 0), HorizontalAlignmentType.CENTER, VerticalAlignmentType.CENTER);
311 controlLayout.SetCellAlignment(new TableView.CellPosition(0, 1), HorizontalAlignmentType.CENTER, VerticalAlignmentType.CENTER);
312 controlLayout.AddChild(okButton, new TableView.CellPosition(0, 0));
313 controlLayout.AddChild(cancelButton, new TableView.CellPosition(0, 1));
315 footer.Add(controlLayout);
317 confirmationPopup.SetFooter(footer);
318 return confirmationPopup;
320 Actor CreateTitle(string title)
322 TextLabel titleActor = new TextLabel(title);
323 titleActor.TextColor = Color.White;
324 titleActor.MultiLine = true;
325 titleActor.HorizontalAlignment = "center";
329 PushButton CreateOKButton()
331 PushButton okayButton = new PushButton();
332 okayButton.SetName("OKButton");
333 okayButton.LabelText = "OK";
334 okayButton.StateFocusEnable = true;
335 okayButton.Clicked += (obj, ee) =>
337 _popup.SetDisplayState(Popup.DisplayStateType.HIDDEN);
342 PushButton CreateCancelButton()
344 PushButton cancelButton = new PushButton();
345 cancelButton.LabelText = "Cancel";
346 cancelButton.StateFocusEnable = true;
347 cancelButton.Clicked += (obj, ee) =>
349 _popup.SetDisplayState(Popup.DisplayStateType.HIDDEN);
355 public void MainLoop()
357 _application.MainLoop();
361 /// The main entry point for the application.
365 static void Main(string[] args)
367 Console.WriteLine("Hello Mono World");
369 Example example = new Example(Application.NewApplication());