2 * Copyright (c) 2017 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;
21 using Tizen.NUI.UIComponents;
22 using Tizen.NUI.Constants;
28 private string _myOwnName;
29 public int _myCurrentValue;
36 public string MyOwnName
49 class MyButton : PushButton
51 private string _myOwnName;
52 public int _myCurrentValue;
59 public string MyOwnName
74 private string _myOwnName;
75 public int _myCurrentValue;
82 public string MyOwnName
95 class Example : NUIApplication
97 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
98 delegate void CallbackDelegate(IntPtr appPtr); // void, void delgate
100 public Example() : base()
104 public Example(string stylesheet) : base(stylesheet)
108 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
112 protected override void OnCreate()
118 public void Initialize()
122 NavigationPropertiesTests();
126 CustomViewPropertyTest();
128 Handle handle = new Handle();
129 int myPropertyIndex = handle.RegisterProperty("myProperty", new PropertyValue(10.0f), PropertyAccessMode.ReadWrite);
130 float myProperty = 0.0f;
131 handle.GetProperty(myPropertyIndex).Get(ref myProperty);
132 Tizen.Log.Debug("NUI", "myProperty value: " + myProperty );
134 int myPropertyIndex2 = handle.RegisterProperty("myProperty2", new PropertyValue(new Size(5.0f, 5.0f, 0.0f)), PropertyAccessMode.ReadWrite);
135 Size myProperty2 = new Size(0.0f, 0.0f, 0.0f);
136 handle.GetProperty(myPropertyIndex2).Get(myProperty2);
137 Tizen.Log.Debug("NUI", "myProperty2 value: " + myProperty2.Width + ", " + myProperty2.Height );
139 Actor actor = new Actor();
140 actor.Size = new Size(200.0f, 200.0f, 0.0f);
141 actor.Name = "MyActor";
142 //actor.MixColor = new Color(1.0f, 0.0f, 1.0f, 0.8f);
143 Tizen.Log.Debug("NUI", "Actor size: " + actor.Size.Width + ", " + actor.Size.Height);
144 Tizen.Log.Debug("NUI", "Actor name: " + actor.Name);
146 Stage stage = Stage.Instance;
147 stage.BackgroundColor = Color.White;
148 Size stageSize = new Size(stage.Size.Width, stage.Size.Height, 0.0f);
149 Tizen.Log.Debug("NUI", "Stage size: " + stageSize.Width + ", " + stageSize.Height);
150 stage.GetDefaultLayer().Add(actor);
152 TextLabel text = new TextLabel("Hello Mono World");
153 text.ParentOrigin = ParentOrigin.Center;
154 text.AnchorPoint = AnchorPoint.Center;
155 text.HorizontalAlignment = HorizontalAlignment.Center;
156 stage.GetDefaultLayer().Add(text);
158 Tizen.Log.Debug("NUI", "Text label text: " + text.Text );
160 Tizen.Log.Debug("NUI", "Text label point size: " + text.PointSize );
161 text.PointSize = 32.0f;
162 Tizen.Log.Debug("NUI", "Text label new point size: " + text.PointSize );
164 RectanglePaddingClassTest();
166 Tizen.Log.Debug("NUI", " *************************" );
167 Size Size = new Size(100, 50, 0);
168 Tizen.Log.Debug("NUI", " Created " + Size );
169 Tizen.Log.Debug("NUI", " Size x = " + Size.Width + ", y = " + Size.Height );
170 Size += new Size(20, 20, 0);
171 Tizen.Log.Debug("NUI", " Size x = " + Size.Width + ", y = " + Size.Height );
174 Tizen.Log.Debug("NUI", " Size width = " + Size.Width + ", height = " + Size.Height );
176 Tizen.Log.Debug("NUI", " *************************" );
177 Position Position = new Position(20, 100, 50);
178 Tizen.Log.Debug("NUI", " Created " + Position );
179 Tizen.Log.Debug("NUI", " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
180 Position += new Position(20, 20, 20);
181 Tizen.Log.Debug("NUI", " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
185 Tizen.Log.Debug("NUI", " Position width = " + Position.X + ", height = " + Position.Y + ", depth = " + Position.Z );
187 Tizen.Log.Debug("NUI", " *************************" );
188 Color color = new Color(20, 100, 50, 200);
189 Tizen.Log.Debug("NUI", " Created " + color );
190 Tizen.Log.Debug("NUI", " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
191 color += new Color(20, 20, 20, 20);
192 Tizen.Log.Debug("NUI", " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
197 Tizen.Log.Debug("NUI", " Color r = " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A );
202 public void RectanglePaddingClassTest()
204 using (Rectangle r1 = new Rectangle(2, 5, 20, 30))
206 Tizen.Log.Debug("NUI", " Created " + r1 );
207 Tizen.Log.Debug("NUI", " IsEmpty() = " + r1.IsEmpty() );
208 Tizen.Log.Debug("NUI", " Left = " + r1.Left() );
209 Tizen.Log.Debug("NUI", " Right = " + r1.Right() );
210 Tizen.Log.Debug("NUI", " Top = " + r1.Top() );
211 Tizen.Log.Debug("NUI", " Bottom = " + r1.Bottom() );
212 Tizen.Log.Debug("NUI", " Area = " + r1.Area() );
215 Tizen.Log.Debug("NUI", " *************************" );
217 using (Rectangle r2 = new Rectangle(2, 5, 20, 30))
219 Tizen.Log.Debug("NUI", " Created " + r2 );
221 Tizen.Log.Debug("NUI", " IsEmpty() = " + r2.IsEmpty() );
222 Tizen.Log.Debug("NUI", " Left = " + r2.Left() );
223 Tizen.Log.Debug("NUI", " Right = " + r2.Right() );
224 Tizen.Log.Debug("NUI", " Top = " + r2.Top() );
225 Tizen.Log.Debug("NUI", " Bottom = " + r2.Bottom() );
226 Tizen.Log.Debug("NUI", " Area = " + r2.Area() );
229 Tizen.Log.Debug("NUI", " *************************" );
231 Rectangle r3 = new Rectangle(10, 10, 20, 20);
232 Rectangle r4 = new Rectangle(10, 10, 20, 20);
236 Tizen.Log.Debug("NUI", "r3 == r4");
240 Tizen.Log.Debug("NUI", "r3 != r4");
243 r4 = new Rectangle(12, 10, 20, 20);
247 Tizen.Log.Debug("NUI", "r3 == r4");
251 Tizen.Log.Debug("NUI", "r3 != r4");
254 PaddingType p1 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
255 PaddingType p2 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
259 Tizen.Log.Debug("NUI", "p1 == p2");
263 Tizen.Log.Debug("NUI", "p1 != p2");
266 p2 = new PaddingType(12.0f, 10.7f, 20.2f, 20.0f);
270 Tizen.Log.Debug("NUI", "p1 == p2");
274 Tizen.Log.Debug("NUI", "p1 != p2");
278 public void NavigationPropertiesTests()
280 View view = new View();
281 View leftView, rightView, upView, downView, tmpView;
283 leftView = new View();
284 leftView.Name = "leftView";
285 rightView = new View();
286 rightView.Name = "rightView";
288 upView.Name = "upView";
289 downView = new View();
290 downView.Name = "downView";
292 Stage.Instance.GetDefaultLayer().Add(leftView);
293 Stage.Instance.GetDefaultLayer().Add(rightView);
294 Stage.Instance.GetDefaultLayer().Add(upView);
295 Stage.Instance.GetDefaultLayer().Add(downView);
297 view.LeftFocusableView = leftView;
298 tmpView = view.LeftFocusableView;
299 if (string.Compare(tmpView.Name, "leftView") == 0)
301 Tizen.Log.Debug("NUI", "Passed: LeftFocusedView = " + tmpView.Name);
305 Tizen.Log.Debug("NUI", "Failed: LeftFocusedView = " + tmpView.Name);
308 view.RightFocusableView = rightView;
309 tmpView = view.RightFocusableView;
310 if (string.Compare(tmpView.Name, "rightView") == 0)
312 Tizen.Log.Debug("NUI", "Passed: RightFocusedView = " + tmpView.Name);
316 Tizen.Log.Debug("NUI", "Failed: RightFocusedView = " + tmpView.Name);
319 Stage.Instance.GetDefaultLayer().Add(view);
321 view.UpFocusableView = upView;
322 tmpView = view.UpFocusableView;
323 if (string.Compare(tmpView.Name, "upView") == 0)
325 Tizen.Log.Debug("NUI", "Passed: UpFocusedView = " + tmpView.Name);
329 Tizen.Log.Debug("NUI", "Failed: UpFocusedView = " + tmpView.Name);
332 view.DownFocusableView = downView;
333 tmpView = view.DownFocusableView;
334 if (string.Compare(tmpView.Name, "downView") == 0)
336 Tizen.Log.Debug("NUI", "Passed: DownFocusedView = " + tmpView.Name);
340 Tizen.Log.Debug("NUI", "Failed: DownFocusedView = " + tmpView.Name);
343 Stage.Instance.GetDefaultLayer().Remove(leftView);
344 tmpView = view.LeftFocusableView;
347 Tizen.Log.Debug("NUI", "Passed: NULL LeftFocusedView");
351 Tizen.Log.Debug("NUI", "Failed: LeftFocusedView = " + tmpView.Name);
355 public void OperatorTests()
357 Actor actor = new Actor();
358 Actor differentActor = new Actor();
359 Actor actorSame = actor;
360 Actor nullActor = null;
362 // test the true operator
365 Tizen.Log.Debug("NUI", "BaseHandle Operator true (actor) : test passed ");
369 Tizen.Log.Debug("NUI", "BaseHandle Operator true (actor): test failed ");
372 Actor parent = actor.Parent;
376 Tizen.Log.Debug("NUI", "Handle with Empty body :failed ");
380 Tizen.Log.Debug("NUI", "Valid with Empty body :passed ");
383 actor.Add( differentActor );
385 // here we test two different C# objects, which on the native side have the same body/ ref-object
386 if ( actor == differentActor.Parent )
388 Tizen.Log.Debug("NUI", "actor == differentActor.GetParent() :passed ");
392 Tizen.Log.Debug("NUI", "actor == differentActor.GetParent() :failed ");
395 if ( differentActor == differentActor.Parent )
397 Tizen.Log.Debug("NUI", "differentActor == differentActor.GetParent() :failed ");
401 Tizen.Log.Debug("NUI", "differentActor == differentActor.GetParent() :passed ");
406 Tizen.Log.Debug("NUI", "BaseHandle Operator true (nullActor) : test failed ");
410 Tizen.Log.Debug("NUI", "BaseHandle Operator true (nullActor): test passed ");
416 Tizen.Log.Debug("NUI", "BaseHandle Operator !(actor) : test failed ");
420 Tizen.Log.Debug("NUI", "BaseHandle Operator !(actor): test passed ");
425 Tizen.Log.Debug("NUI", "BaseHandle Operator !(nullActor) : test passed ");
429 Tizen.Log.Debug("NUI", "BaseHandle Operator !(nullActor): test failed ");
432 // Note: operator false only used inside & operator
433 // test equality operator ==
434 if ( actor == actorSame )
436 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == actorSame) : test passed");
440 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == actorSame) : test failed");
443 if ( actor == differentActor )
445 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == differentActor) : test failed");
449 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == differentActor) : test passed");
452 if ( actor == nullActor )
454 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == nullActor) : test failed");
458 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == nullActor) : test passed");
461 if ( nullActor == nullActor )
463 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor == nullActor) : test passed");
467 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor == nullActor) : test failed");
471 if ( actor || actorSame )
473 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor || actorSame) : test passed");
477 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor || actorSame) : test failed");
480 if ( actor || nullActor )
482 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor || nullActor) : test passed");
486 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor || nullActor) : test failed");
489 if ( nullActor || nullActor )
491 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor || nullActor) : test failed");
495 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor || nullActor) : test passed");
499 if ( actor && actorSame )
501 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor && actorSame) : test passed");
505 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor && actorSame) : test failed");
508 if ( actor && nullActor )
510 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor && nullActor) : test failed");
514 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor && nullActor) : test passed");
517 if ( nullActor && nullActor )
519 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor && nullActor) : test failed");
523 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor && nullActor) : test passed");
527 public void CustomViewPropertyTest()
529 // Create a Spin control
530 Spin spin = new Spin();
532 // Background property
533 PropertyMap background = new PropertyMap();
534 background.Add( Visual.Property.Type, new PropertyValue((int)Visual.Type.Color) )
535 .Add( ColorVisualProperty.MixColor, new PropertyValue(Color.Red) );
536 spin.Background = background;
538 background = spin.Background;
539 Color backgroundColor = new Color();
540 background.Find(ColorVisualProperty.MixColor).Get(backgroundColor);
541 if( backgroundColor == Color.Red )
543 Tizen.Log.Debug("NUI", "Custom View Background property : test passed");
547 Tizen.Log.Debug("NUI", "Custom View Background property : test failed");
550 // BackgroundColor property
551 spin.BackgroundColor = Color.Yellow;
552 if(spin.BackgroundColor == Color.Yellow)
554 Tizen.Log.Debug("NUI", "Custom View BackgroundColor property : test passed");
558 Tizen.Log.Debug("NUI", "Custom View BackgroundColor property : test failed");
561 // BackgroundImage property
562 spin.BackgroundImage = "background-image.jpg";
563 if(spin.BackgroundImage == "background-image.jpg")
565 Tizen.Log.Debug("NUI", "Custom View BackgroundImage property : test passed");
569 Tizen.Log.Debug("NUI", "Custom View BackgroundImage property : test failed");
572 // StyleName property
573 spin.StyleName = "MyCustomStyle";
574 if(spin.StyleName == "MyCustomStyle")
576 Tizen.Log.Debug("NUI", "Custom View StyleName property : test passed");
580 Tizen.Log.Debug("NUI", "Custom View StyleName property : test failed");
584 public void ViewDownCastTest()
586 View container = new View();
587 container.Position = new Position(-800.0f, -800.0f, 0.0f);
588 Stage.Instance.GetDefaultLayer().Add(container);
590 // Test downcast for native control
591 TextLabel myLabel = new TextLabel();
592 myLabel.Name = "MyLabelName";
593 myLabel.Text = "MyText";
595 Tizen.Log.Debug("NUI", "myLabel.Name = " + myLabel.Name + ", Text = " + myLabel.Text);
597 container.Add(myLabel);
599 Actor myLabelActor = container.FindChildByName("MyLabelName");
602 TextLabel newLabel = View.DownCast<TextLabel>(myLabelActor);
605 Tizen.Log.Debug("NUI", "Downcast to TextLabel successful: newLabel Name = " + newLabel.Name + ", Text = " + newLabel.Text);
609 Tizen.Log.Debug("NUI", "Downcast to TextLabel failed!");
613 // Test downcast for class directly inherited from View
614 MyView myView = new MyView();
615 myView.Name = "MyViewName";
616 myView.MyOwnName = "MyOwnViewName";
617 myView._myCurrentValue = 5;
619 Tizen.Log.Debug("NUI", "myView.Name = " + myView.Name + ", MyOwnName = " + myView.MyOwnName + ", myCurrentValue = " + myView._myCurrentValue);
621 container.Add(myView);
623 Actor myViewActor = container.FindChildByName("MyViewName");
626 MyView newView = View.DownCast<MyView>(myViewActor);
629 Tizen.Log.Debug("NUI", "Downcast to MyView successful: newView Name = " + newView.Name + ", MyOwnName = " + newView.MyOwnName + ", myCurrentValue = " + newView._myCurrentValue);
633 Tizen.Log.Debug("NUI", "Downcast to MyView failed!");
637 // Test downcast for class directly inherited from native control
638 MyButton myButton = new MyButton();
639 myButton.Name = "MyButtonName";
640 myButton.MyOwnName = "MyOwnViewName";
641 myButton.LabelText = "MyLabelText";
642 myButton._myCurrentValue = 5;
644 Tizen.Log.Debug("NUI", "myButton.Name = " + myButton.Name + ", MyOwnName = " + myButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + myButton._myCurrentValue);
646 container.Add(myButton);
648 Actor myButtonActor = container.FindChildByName("MyButtonName");
651 MyButton newButton = View.DownCast<MyButton>(myButtonActor);
654 Tizen.Log.Debug("NUI", "Downcast to MyButton successful: newButton Name = " + newButton.Name + ", MyOwnName = " + newButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + newButton._myCurrentValue);
658 Tizen.Log.Debug("NUI", "Downcast to MyButton failed!");
662 // Test downcast for a CustomView
663 Spin spin = new Spin();
664 spin.Name = "SpinName";
665 spin.MaxValue = 8888;
667 Tizen.Log.Debug("NUI", "spin.Name = " + spin.Name + ", MaxValue = " + spin.MaxValue);
671 Actor spinActor = container.FindChildByName("SpinName");
674 Spin newSpin = View.DownCast<Spin>(spinActor);
677 Tizen.Log.Debug("NUI", "Downcast to Spin successful: newSpin Name = " + newSpin.Name + ", MaxValue = " + newSpin.MaxValue);
681 Tizen.Log.Debug("NUI", "Downcast to Spin failed!");
685 // Test downcast for class inherited from a CustomView
686 MySpin mySpin = new MySpin();
687 mySpin.Name = "MySpinName";
688 mySpin.MyOwnName = "MyOwnSpinName";
689 mySpin.MaxValue = 8888;
690 mySpin._myCurrentValue = 5;
692 Tizen.Log.Debug("NUI", "mySpin.Name = " + mySpin.Name + ", MyOwnName = " + mySpin.MyOwnName + ", MaxValue = " + mySpin.MaxValue + ", currentValue = " + mySpin._myCurrentValue);
694 container.Add(mySpin);
696 Actor mySpinActor = container.FindChildByName("MySpinName");
699 MySpin newSpin = View.DownCast<MySpin>(mySpinActor);
702 Tizen.Log.Debug("NUI", "Downcast to MySpin successful: newSpin Name = " + newSpin.Name + ", MyOwnName = " + newSpin.MyOwnName + ", MaxValue = " + newSpin.MaxValue + ", currentValue = " + newSpin._myCurrentValue);
706 Tizen.Log.Debug("NUI", "Downcast to MySpin failed!");
713 public void DowncastTest()
715 //Create a View as a child of parent View, get it use parent.GetChildAt(i), then DownCast to View handle, but call BackgroundColor property will crash.
716 View parent = new View();
717 View[] childs = new View[5];
719 for (int i = 0; i < 5; i++)
721 childs[i] = new View();
722 childs[i].Name = "child_view_" + i;
723 childs[i].BackgroundColor = Color.Red;
724 parent.Add(childs[i]);
727 for (uint i = 0; i < parent.GetChildCount(); i++)
729 Actor child = parent.GetChildAt(i);
730 View childView = View.DownCast<View>(child);
733 Tizen.Log.Debug("NUI", "Type[" + childView.GetTypeName() + "] BGColor[" + childView.BackgroundColor.R + "]" + " Name[" + childView.Name + "]");
737 PushButton button = new PushButton();
738 button.LabelText = "ButtonTest!";
739 button.BackgroundColor = Color.White;
740 View parentView = new View();
741 parentView.Add(button);
742 PushButton view = PushButton.DownCast(parentView.GetChildAt(0));
745 Tizen.Log.Debug("NUI", "NUI view GetTypeName= " + view.GetTypeName());
746 Tizen.Log.Debug("NUI", "NUI view LabelText= " + view.LabelText);
747 Tizen.Log.Debug("NUI", "NUI view color= " + view.BackgroundColor.R);
754 /// The main entry point for the application.
757 static void _Main(string[] args)
759 Tizen.Log.Debug("NUI", "Hello Mono World");
761 Example example = new Example();