Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / PropertyNotificationTest.cs
1 
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4
5 namespace Tizen.NUI.Samples
6 {
7     public class PropertyNotificationTest : IExample
8     {
9         Window win;
10         int cnt;
11         public void Activate()
12         {
13             win = NUIApplication.GetDefaultWindow();
14             win.BackgroundColor = Color.White;
15
16             View view = new View()
17             {
18                 Size = new Size(100, 100),
19                 BackgroundColor = Color.Red,
20                 Name = "test view",
21             };
22
23             PropertyNotification propertyNotification = view.AddPropertyNotification("size", PropertyCondition.Step(1.0f));
24
25             propertyNotification.Notified += (object source, PropertyNotification.NotifyEventArgs args) =>
26             {
27                 View target = args.PropertyNotification.GetTarget() as View;
28                 if (target != null)
29                 {
30                     Tizen.Log.Error("NUI", $"Size changed! ({target.SizeWidth},{target.SizeHeight})");
31                     global::System.Console.WriteLine($"Size changed! ({target.SizeWidth},{target.SizeHeight})");
32                 }
33                 Tizen.Log.Error("NUI", "Size changed");
34             };
35
36             Button button = new Button()
37             {
38                 Size = new Size(100, 100),
39                 Position = new Position(200, 200),
40                 Text = "Click me",
41                 Name = "test button",
42             };
43
44             button.Clicked += (object source, ClickedEventArgs args) =>
45             {
46                 if (++cnt % 2 == 0)
47                 {
48                     view.Size += new Size(5, 5);
49                 }
50                 else
51                 {
52                     view.Position += new Position(10, 10);
53                 }
54             };
55
56             win.GetDefaultLayer().Add(view);
57             win.GetDefaultLayer().Add(button);
58         }
59
60         public void Deactivate()
61         {
62             win.GetDefaultLayer().FindChildByName("test view")?.Unparent();
63             win.GetDefaultLayer().FindChildByName("test button")?.Unparent();
64         }
65     }
66 }