390bbfd87fe3ffe06e0cff1371f23d843749778d
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / ScrollableBaseOutOfBoundSample.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using Tizen.NUI.BaseComponents;
5
6 namespace Tizen.NUI.Samples
7 {
8     public class ScrollableBaseOutOfBoundSample : IExample
9     {
10         private View root;
11         private Components.ScrollableBase mScrollableBase = null;
12         private TextLabel[] items;
13
14         public void Activate()
15         {
16             Window window = NUIApplication.GetDefaultWindow();
17             root = new View()
18             {
19                 Size = new Size(1920, 1080),
20                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
21             };
22             root.Layout = new LinearLayout()
23             {
24                 LinearOrientation = LinearLayout.Orientation.Vertical
25             };
26             window.Add(root);
27
28             CreateScrollableBase();
29         }
30
31         private void CreateScrollableBase()
32         {
33             mScrollableBase = new Components.ScrollableBase()
34             {
35                 Position = new Position(300, 100),
36                 Size = new Size(400, 300),
37                 ScrollingDirection = Components.ScrollableBase.Direction.Vertical,
38                 EnableOverShootingEffect = true,
39             };
40             mScrollableBase.ScrollOutOfBound += OnScrollOutOfBound;
41
42             items = new TextLabel[5];
43             for (int i = 0; i < 5; i++)
44             {
45                 items[i] = new TextLabel
46                 {
47                     Position = new Position(0, i * 100),
48                     Size = new Size(800, 100),
49                     PointSize = 12.0f,
50                     TextColor = Color.Black,
51                 };
52                 if (i % 2 == 0)
53                 {
54                     items[i].BackgroundColor = Color.White;
55                 }
56                 else
57                 {
58                     items[i].BackgroundColor = Color.Cyan;
59                 }
60                 mScrollableBase.Add(items[i]);
61             }
62             root.Add(mScrollableBase);
63         }
64
65         private void OnScrollOutOfBound(object sender, Components.ScrollOutOfBoundEventArgs e)
66         {
67             if (e.Displacement > 100)
68             {
69                 if (e.PanDirection == Components.ScrollOutOfBoundEventArgs.Direction.Down)
70                 {
71                     items[0].Text = $"Reached at the top, panned displacement is {e.Displacement}.";
72                 }
73             }
74             else if (0 - e.Displacement > 100)
75             {
76                 if (e.PanDirection == Components.ScrollOutOfBoundEventArgs.Direction.Up)
77                 {
78                     items[4].Text = $"Reached at the bottom, panned displacement is {e.Displacement}.";
79                 }
80             }
81         }
82
83         public void Deactivate()
84         {
85             for (int i = 0; i < 5; i++)
86             {
87                 if (items[i] != null)
88                 {
89                     mScrollableBase.Remove(items[i]);
90                     items[i].Dispose();
91                 }
92             }
93             if (mScrollableBase != null)
94             {
95                 root.Remove(mScrollableBase);
96                 mScrollableBase.Dispose();
97             }
98             root.Dispose();
99         }
100     }
101 }