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.Constants;
27 private string _myOwnName;
28 public int _myCurrentValue;
35 public string MyOwnName
48 class MyButton : PushButton
50 private string _myOwnName;
51 public int _myCurrentValue;
58 public string MyOwnName
73 private string _myOwnName;
74 public int _myCurrentValue;
81 public string MyOwnName
94 class Example : NUIApplication
96 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
97 delegate void CallbackDelegate(IntPtr appPtr); // void, void delgate
99 public Example() : base()
103 public Example(string stylesheet) : base(stylesheet)
107 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
111 protected override void OnCreate()
117 public void Initialize()
121 NavigationPropertiesTests();
125 CustomViewPropertyTest();
127 Handle handle = new Handle();
128 int myPropertyIndex = handle.RegisterProperty("myProperty", new PropertyValue(10.0f), PropertyAccessMode.ReadWrite);
129 float myProperty = 0.0f;
130 handle.GetProperty(myPropertyIndex).Get(ref myProperty);
131 Tizen.Log.Debug("NUI", "myProperty value: " + myProperty );
133 int myPropertyIndex2 = handle.RegisterProperty("myProperty2", new PropertyValue(new Size(5.0f, 5.0f, 0.0f)), PropertyAccessMode.ReadWrite);
134 Size myProperty2 = new Size(0.0f, 0.0f, 0.0f);
135 handle.GetProperty(myPropertyIndex2).Get(myProperty2);
136 Tizen.Log.Debug("NUI", "myProperty2 value: " + myProperty2.Width + ", " + myProperty2.Height );
138 Actor actor = new Actor();
139 actor.Size = new Size(200.0f, 200.0f, 0.0f);
140 actor.Name = "MyActor";
141 //actor.MixColor = new Color(1.0f, 0.0f, 1.0f, 0.8f);
142 Tizen.Log.Debug("NUI", "Actor size: " + actor.Size.Width + ", " + actor.Size.Height);
143 Tizen.Log.Debug("NUI", "Actor name: " + actor.Name);
145 Stage stage = Stage.Instance;
146 stage.BackgroundColor = Color.White;
147 Size stageSize = new Size(stage.Size.Width, stage.Size.Height, 0.0f);
148 Tizen.Log.Debug("NUI", "Stage size: " + stageSize.Width + ", " + stageSize.Height);
149 stage.GetDefaultLayer().Add(actor);
151 TextLabel text = new TextLabel("Hello Mono World");
152 text.ParentOrigin = ParentOrigin.Center;
153 text.AnchorPoint = AnchorPoint.Center;
154 text.HorizontalAlignment = HorizontalAlignment.HorizontalAlignCenter;
155 stage.GetDefaultLayer().Add(text);
157 Tizen.Log.Debug("NUI", "Text label text: " + text.Text );
159 Tizen.Log.Debug("NUI", "Text label point size: " + text.PointSize );
160 text.PointSize = 32.0f;
161 Tizen.Log.Debug("NUI", "Text label new point size: " + text.PointSize );
163 RectanglePaddingClassTest();
165 Tizen.Log.Debug("NUI", " *************************" );
166 Size Size = new Size(100, 50, 0);
167 Tizen.Log.Debug("NUI", " Created " + Size );
168 Tizen.Log.Debug("NUI", " Size x = " + Size.Width + ", y = " + Size.Height );
169 Size += new Size(20, 20, 0);
170 Tizen.Log.Debug("NUI", " Size x = " + Size.Width + ", y = " + Size.Height );
173 Tizen.Log.Debug("NUI", " Size width = " + Size.Width + ", height = " + Size.Height );
175 Tizen.Log.Debug("NUI", " *************************" );
176 Position Position = new Position(20, 100, 50);
177 Tizen.Log.Debug("NUI", " Created " + Position );
178 Tizen.Log.Debug("NUI", " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
179 Position += new Position(20, 20, 20);
180 Tizen.Log.Debug("NUI", " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
184 Tizen.Log.Debug("NUI", " Position width = " + Position.X + ", height = " + Position.Y + ", depth = " + Position.Z );
186 Tizen.Log.Debug("NUI", " *************************" );
187 Color color = new Color(20, 100, 50, 200);
188 Tizen.Log.Debug("NUI", " Created " + color );
189 Tizen.Log.Debug("NUI", " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
190 color += new Color(20, 20, 20, 20);
191 Tizen.Log.Debug("NUI", " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
196 Tizen.Log.Debug("NUI", " Color r = " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A );
201 public void RectanglePaddingClassTest()
203 using (Rectangle r1 = new Rectangle(2, 5, 20, 30))
205 Tizen.Log.Debug("NUI", " Created " + r1 );
206 Tizen.Log.Debug("NUI", " IsEmpty() = " + r1.IsEmpty() );
207 Tizen.Log.Debug("NUI", " Left = " + r1.Left() );
208 Tizen.Log.Debug("NUI", " Right = " + r1.Right() );
209 Tizen.Log.Debug("NUI", " Top = " + r1.Top() );
210 Tizen.Log.Debug("NUI", " Bottom = " + r1.Bottom() );
211 Tizen.Log.Debug("NUI", " Area = " + r1.Area() );
214 Tizen.Log.Debug("NUI", " *************************" );
216 using (Rectangle r2 = new Rectangle(2, 5, 20, 30))
218 Tizen.Log.Debug("NUI", " Created " + r2 );
220 Tizen.Log.Debug("NUI", " IsEmpty() = " + r2.IsEmpty() );
221 Tizen.Log.Debug("NUI", " Left = " + r2.Left() );
222 Tizen.Log.Debug("NUI", " Right = " + r2.Right() );
223 Tizen.Log.Debug("NUI", " Top = " + r2.Top() );
224 Tizen.Log.Debug("NUI", " Bottom = " + r2.Bottom() );
225 Tizen.Log.Debug("NUI", " Area = " + r2.Area() );
228 Tizen.Log.Debug("NUI", " *************************" );
230 Rectangle r3 = new Rectangle(10, 10, 20, 20);
231 Rectangle r4 = new Rectangle(10, 10, 20, 20);
235 Tizen.Log.Debug("NUI", "r3 == r4");
239 Tizen.Log.Debug("NUI", "r3 != r4");
242 r4 = new Rectangle(12, 10, 20, 20);
246 Tizen.Log.Debug("NUI", "r3 == r4");
250 Tizen.Log.Debug("NUI", "r3 != r4");
253 PaddingType p1 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
254 PaddingType p2 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
258 Tizen.Log.Debug("NUI", "p1 == p2");
262 Tizen.Log.Debug("NUI", "p1 != p2");
265 p2 = new PaddingType(12.0f, 10.7f, 20.2f, 20.0f);
269 Tizen.Log.Debug("NUI", "p1 == p2");
273 Tizen.Log.Debug("NUI", "p1 != p2");
277 public void NavigationPropertiesTests()
279 View view = new View();
280 View leftView, rightView, upView, downView, tmpView;
282 leftView = new View();
283 leftView.Name = "leftView";
284 rightView = new View();
285 rightView.Name = "rightView";
287 upView.Name = "upView";
288 downView = new View();
289 downView.Name = "downView";
291 Stage.Instance.GetDefaultLayer().Add(leftView);
292 Stage.Instance.GetDefaultLayer().Add(rightView);
293 Stage.Instance.GetDefaultLayer().Add(upView);
294 Stage.Instance.GetDefaultLayer().Add(downView);
296 view.LeftFocusableView = leftView;
297 tmpView = view.LeftFocusableView;
298 if (string.Compare(tmpView.Name, "leftView") == 0)
300 Tizen.Log.Debug("NUI", "Passed: LeftFocusedView = " + tmpView.Name);
304 Tizen.Log.Debug("NUI", "Failed: LeftFocusedView = " + tmpView.Name);
307 view.RightFocusableView = rightView;
308 tmpView = view.RightFocusableView;
309 if (string.Compare(tmpView.Name, "rightView") == 0)
311 Tizen.Log.Debug("NUI", "Passed: RightFocusedView = " + tmpView.Name);
315 Tizen.Log.Debug("NUI", "Failed: RightFocusedView = " + tmpView.Name);
318 Stage.Instance.GetDefaultLayer().Add(view);
320 view.UpFocusableView = upView;
321 tmpView = view.UpFocusableView;
322 if (string.Compare(tmpView.Name, "upView") == 0)
324 Tizen.Log.Debug("NUI", "Passed: UpFocusedView = " + tmpView.Name);
328 Tizen.Log.Debug("NUI", "Failed: UpFocusedView = " + tmpView.Name);
331 view.DownFocusableView = downView;
332 tmpView = view.DownFocusableView;
333 if (string.Compare(tmpView.Name, "downView") == 0)
335 Tizen.Log.Debug("NUI", "Passed: DownFocusedView = " + tmpView.Name);
339 Tizen.Log.Debug("NUI", "Failed: DownFocusedView = " + tmpView.Name);
342 Stage.Instance.GetDefaultLayer().Remove(leftView);
343 tmpView = view.LeftFocusableView;
346 Tizen.Log.Debug("NUI", "Passed: NULL LeftFocusedView");
350 Tizen.Log.Debug("NUI", "Failed: LeftFocusedView = " + tmpView.Name);
354 public void OperatorTests()
356 Actor actor = new Actor();
357 Actor differentActor = new Actor();
358 Actor actorSame = actor;
359 Actor nullActor = null;
361 // test the true operator
364 Tizen.Log.Debug("NUI", "BaseHandle Operator true (actor) : test passed ");
368 Tizen.Log.Debug("NUI", "BaseHandle Operator true (actor): test failed ");
371 Actor parent = actor.Parent;
375 Tizen.Log.Debug("NUI", "Handle with Empty body :failed ");
379 Tizen.Log.Debug("NUI", "Valid with Empty body :passed ");
382 actor.Add( differentActor );
384 // here we test two different C# objects, which on the native side have the same body/ ref-object
385 if ( actor == differentActor.Parent )
387 Tizen.Log.Debug("NUI", "actor == differentActor.GetParent() :passed ");
391 Tizen.Log.Debug("NUI", "actor == differentActor.GetParent() :failed ");
394 if ( differentActor == differentActor.Parent )
396 Tizen.Log.Debug("NUI", "differentActor == differentActor.GetParent() :failed ");
400 Tizen.Log.Debug("NUI", "differentActor == differentActor.GetParent() :passed ");
405 Tizen.Log.Debug("NUI", "BaseHandle Operator true (nullActor) : test failed ");
409 Tizen.Log.Debug("NUI", "BaseHandle Operator true (nullActor): test passed ");
415 Tizen.Log.Debug("NUI", "BaseHandle Operator !(actor) : test failed ");
419 Tizen.Log.Debug("NUI", "BaseHandle Operator !(actor): test passed ");
424 Tizen.Log.Debug("NUI", "BaseHandle Operator !(nullActor) : test passed ");
428 Tizen.Log.Debug("NUI", "BaseHandle Operator !(nullActor): test failed ");
431 // Note: operator false only used inside & operator
432 // test equality operator ==
433 if ( actor == actorSame )
435 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == actorSame) : test passed");
439 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == actorSame) : test failed");
442 if ( actor == differentActor )
444 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == differentActor) : test failed");
448 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == differentActor) : test passed");
451 if ( actor == nullActor )
453 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == nullActor) : test failed");
457 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor == nullActor) : test passed");
460 if ( nullActor == nullActor )
462 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor == nullActor) : test passed");
466 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor == nullActor) : test failed");
470 if ( actor || actorSame )
472 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor || actorSame) : test passed");
476 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor || actorSame) : test failed");
479 if ( actor || nullActor )
481 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor || nullActor) : test passed");
485 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor || nullActor) : test failed");
488 if ( nullActor || nullActor )
490 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor || nullActor) : test failed");
494 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor || nullActor) : test passed");
498 if ( actor && actorSame )
500 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor && actorSame) : test passed");
504 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor && actorSame) : test failed");
507 if ( actor && nullActor )
509 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor && nullActor) : test failed");
513 Tizen.Log.Debug("NUI", "BaseHandle Operator (actor && nullActor) : test passed");
516 if ( nullActor && nullActor )
518 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor && nullActor) : test failed");
522 Tizen.Log.Debug("NUI", "BaseHandle Operator (nullActor && nullActor) : test passed");
526 public void CustomViewPropertyTest()
528 // Create a Spin control
529 Spin spin = new Spin();
531 // Background property
532 PropertyMap background = new PropertyMap();
533 background.Add( Visual.Property.Type, new PropertyValue((int)Visual.Type.Color) )
534 .Add( ColorVisualProperty.MixColor, new PropertyValue(Color.Red) );
535 spin.Background = background;
537 background = spin.Background;
538 Color backgroundColor = new Color();
539 background.Find(ColorVisualProperty.MixColor).Get(backgroundColor);
540 if( backgroundColor == Color.Red )
542 Tizen.Log.Debug("NUI", "Custom View Background property : test passed");
546 Tizen.Log.Debug("NUI", "Custom View Background property : test failed");
549 // BackgroundColor property
550 spin.BackgroundColor = Color.Yellow;
551 if(spin.BackgroundColor == Color.Yellow)
553 Tizen.Log.Debug("NUI", "Custom View BackgroundColor property : test passed");
557 Tizen.Log.Debug("NUI", "Custom View BackgroundColor property : test failed");
560 // BackgroundImage property
561 spin.BackgroundImage = "background-image.jpg";
562 if(spin.BackgroundImage == "background-image.jpg")
564 Tizen.Log.Debug("NUI", "Custom View BackgroundImage property : test passed");
568 Tizen.Log.Debug("NUI", "Custom View BackgroundImage property : test failed");
571 // StyleName property
572 spin.StyleName = "MyCustomStyle";
573 if(spin.StyleName == "MyCustomStyle")
575 Tizen.Log.Debug("NUI", "Custom View StyleName property : test passed");
579 Tizen.Log.Debug("NUI", "Custom View StyleName property : test failed");
583 public void ViewDownCastTest()
585 View container = new View();
586 container.Position = new Position(-800.0f, -800.0f, 0.0f);
587 Stage.Instance.GetDefaultLayer().Add(container);
589 // Test downcast for native control
590 TextLabel myLabel = new TextLabel();
591 myLabel.Name = "MyLabelName";
592 myLabel.Text = "MyText";
594 Tizen.Log.Debug("NUI", "myLabel.Name = " + myLabel.Name + ", Text = " + myLabel.Text);
596 container.Add(myLabel);
598 Actor myLabelActor = container.FindChildByName("MyLabelName");
601 TextLabel newLabel = View.DownCast<TextLabel>(myLabelActor);
604 Tizen.Log.Debug("NUI", "Downcast to TextLabel successful: newLabel Name = " + newLabel.Name + ", Text = " + newLabel.Text);
608 Tizen.Log.Debug("NUI", "Downcast to TextLabel failed!");
612 // Test downcast for class directly inherited from View
613 MyView myView = new MyView();
614 myView.Name = "MyViewName";
615 myView.MyOwnName = "MyOwnViewName";
616 myView._myCurrentValue = 5;
618 Tizen.Log.Debug("NUI", "myView.Name = " + myView.Name + ", MyOwnName = " + myView.MyOwnName + ", myCurrentValue = " + myView._myCurrentValue);
620 container.Add(myView);
622 Actor myViewActor = container.FindChildByName("MyViewName");
625 MyView newView = View.DownCast<MyView>(myViewActor);
628 Tizen.Log.Debug("NUI", "Downcast to MyView successful: newView Name = " + newView.Name + ", MyOwnName = " + newView.MyOwnName + ", myCurrentValue = " + newView._myCurrentValue);
632 Tizen.Log.Debug("NUI", "Downcast to MyView failed!");
636 // Test downcast for class directly inherited from native control
637 MyButton myButton = new MyButton();
638 myButton.Name = "MyButtonName";
639 myButton.MyOwnName = "MyOwnViewName";
640 myButton.LabelText = "MyLabelText";
641 myButton._myCurrentValue = 5;
643 Tizen.Log.Debug("NUI", "myButton.Name = " + myButton.Name + ", MyOwnName = " + myButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + myButton._myCurrentValue);
645 container.Add(myButton);
647 Actor myButtonActor = container.FindChildByName("MyButtonName");
650 MyButton newButton = View.DownCast<MyButton>(myButtonActor);
653 Tizen.Log.Debug("NUI", "Downcast to MyButton successful: newButton Name = " + newButton.Name + ", MyOwnName = " + newButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + newButton._myCurrentValue);
657 Tizen.Log.Debug("NUI", "Downcast to MyButton failed!");
661 // Test downcast for a CustomView
662 Spin spin = new Spin();
663 spin.Name = "SpinName";
664 spin.MaxValue = 8888;
666 Tizen.Log.Debug("NUI", "spin.Name = " + spin.Name + ", MaxValue = " + spin.MaxValue);
670 Actor spinActor = container.FindChildByName("SpinName");
673 Spin newSpin = View.DownCast<Spin>(spinActor);
676 Tizen.Log.Debug("NUI", "Downcast to Spin successful: newSpin Name = " + newSpin.Name + ", MaxValue = " + newSpin.MaxValue);
680 Tizen.Log.Debug("NUI", "Downcast to Spin failed!");
684 // Test downcast for class inherited from a CustomView
685 MySpin mySpin = new MySpin();
686 mySpin.Name = "MySpinName";
687 mySpin.MyOwnName = "MyOwnSpinName";
688 mySpin.MaxValue = 8888;
689 mySpin._myCurrentValue = 5;
691 Tizen.Log.Debug("NUI", "mySpin.Name = " + mySpin.Name + ", MyOwnName = " + mySpin.MyOwnName + ", MaxValue = " + mySpin.MaxValue + ", currentValue = " + mySpin._myCurrentValue);
693 container.Add(mySpin);
695 Actor mySpinActor = container.FindChildByName("MySpinName");
698 MySpin newSpin = View.DownCast<MySpin>(mySpinActor);
701 Tizen.Log.Debug("NUI", "Downcast to MySpin successful: newSpin Name = " + newSpin.Name + ", MyOwnName = " + newSpin.MyOwnName + ", MaxValue = " + newSpin.MaxValue + ", currentValue = " + newSpin._myCurrentValue);
705 Tizen.Log.Debug("NUI", "Downcast to MySpin failed!");
712 public void DowncastTest()
714 //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.
715 View parent = new View();
716 View[] childs = new View[5];
718 for (int i = 0; i < 5; i++)
720 childs[i] = new View();
721 childs[i].Name = "child_view_" + i;
722 childs[i].BackgroundColor = Color.Red;
723 parent.Add(childs[i]);
726 for (uint i = 0; i < parent.GetChildCount(); i++)
728 Actor child = parent.GetChildAt(i);
729 View childView = View.DownCast<View>(child);
732 Tizen.Log.Debug("NUI", "Type[" + childView.GetTypeName() + "] BGColor[" + childView.BackgroundColor.R + "]" + " Name[" + childView.Name + "]");
736 PushButton button = new PushButton();
737 button.LabelText = "ButtonTest!";
738 button.BackgroundColor = Color.White;
739 View parentView = new View();
740 parentView.Add(button);
741 PushButton view = PushButton.DownCast(parentView.GetChildAt(0));
744 Tizen.Log.Debug("NUI", "NUI view GetTypeName= " + view.GetTypeName());
745 Tizen.Log.Debug("NUI", "NUI view LabelText= " + view.LabelText);
746 Tizen.Log.Debug("NUI", "NUI view color= " + view.BackgroundColor.R);
753 /// The main entry point for the application.
756 static void _Main(string[] args)
758 Tizen.Log.Debug("NUI", "Hello Mono World");
760 Example example = new Example();