[ElmSharp] Add scroll animation start/stop event for Scroller
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / ScrollerTest3.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using ElmSharp;
19
20 namespace ElmSharp.Test
21 {
22     public class ScrollerTest3 : TestCaseBase
23     {
24         public override string TestName => "ScrollerTest3";
25         public override string TestDescription => "To test ScrollTo operation of Scroller";
26         Scroller _scroller;
27
28         public override void Run(Window window)
29         {
30             Conformant conformant = new Conformant(window);
31             conformant.Show();
32             Box outterBox = new Box(window)
33             {
34                 BackgroundColor = Color.Gray,
35                 AlignmentX = -1,
36                 AlignmentY = -1,
37                 WeightX = 1,
38                 WeightY = 1,
39                 IsHorizontal = false,
40             };
41             outterBox.Show();
42             _scroller = new Scroller(window)
43             {
44                 AlignmentX = -1,
45                 AlignmentY = -1,
46                 WeightX = 1,
47                 WeightY = 1,
48                 HorizontalPageScrollLimit = 1,
49             };
50             _scroller.SetPageSize(1.0, 1.0);
51             _scroller.Show();
52
53             Box box = new Box(window)
54             {
55                 AlignmentX = -1,
56                 AlignmentY = -1,
57                 WeightX = 1,
58                 WeightY = 1
59             };
60             box.Show();
61             _scroller.SetContent(box);
62
63             for (int i = 0; i < 150; i++)
64             {
65                 Label addlabel = new Label(window)
66                 {
67                     Text = i + " Label Test",
68                     AlignmentX = -1,
69                     AlignmentY = -1,
70                     WeightX = 1,
71                     WeightY = 1,
72                 };
73                 addlabel.Show();
74                 box.PackEnd(addlabel);
75             }
76
77             conformant.SetContent(outterBox);
78             outterBox.PackEnd(_scroller);
79
80             Button prev = new Button(window)
81             {
82                 AlignmentX = -1,
83                 WeightX = 1,
84                 Text = "Prev"
85             };
86             Button next = new Button(window)
87             {
88                 AlignmentX = -1,
89                 WeightX = 1,
90                 Text = "next"
91             };
92
93             int index = 0;
94
95             prev.Clicked += (s, e) =>
96             {
97                 Rect region = new Rect(0, _scroller.Geometry.Height * --index, _scroller.Geometry.Width * index, _scroller.Geometry.Height);
98                 Console.WriteLine("index : {0} [{1}, {2}]\n", index, _scroller.Geometry.Width, _scroller.Geometry.Height);
99                 _scroller.ScrollTo(region, false);
100             };
101
102             next.Clicked += (s, e) =>
103             {
104                 Rect region = new Rect(0, _scroller.Geometry.Height * ++index, _scroller.Geometry.Width, _scroller.Geometry.Height);
105                 Console.WriteLine("index : {0} [{1}, {2}]\n", index, _scroller.Geometry.Width, _scroller.Geometry.Height);
106                 _scroller.ScrollTo(region, false);
107             };
108             prev.Show();
109             next.Show();
110
111             Button prev2 = new Button(window)
112             {
113                 AlignmentX = -1,
114                 WeightX = 1,
115                 Text = "animation Prev"
116             };
117             Button next2 = new Button(window)
118             {
119                 AlignmentX = -1,
120                 WeightX = 1,
121                 Text = "animation next"
122             };
123
124             prev2.Clicked += (s, e) =>
125             {
126                 Rect region = new Rect(0, _scroller.Geometry.Height * --index, _scroller.Geometry.Width * index, _scroller.Geometry.Height);
127                 Console.WriteLine("animation index : {0} [{1}, {2}]\n", index, _scroller.Geometry.Width, _scroller.Geometry.Height);
128                 _scroller.ScrollTo(region, true);
129             };
130
131             next2.Clicked += (s, e) =>
132             {
133                 Rect region = new Rect(0, _scroller.Geometry.Height * ++index, _scroller.Geometry.Width, _scroller.Geometry.Height);
134                 Console.WriteLine("animation index : {0} [{1}, {2}]\n", index, _scroller.Geometry.Width, _scroller.Geometry.Height);
135                 _scroller.ScrollTo(region, true);
136             };
137             prev2.Show();
138             next2.Show();
139
140             outterBox.PackEnd(prev);
141             outterBox.PackEnd(next);
142             outterBox.PackEnd(prev2);
143             outterBox.PackEnd(next2);
144
145             _scroller.DragStart += Scroller_DragStart;
146             _scroller.DragStop += Scroller_DragStop;
147             _scroller.ScrollAnimationStarted += Scroller_ScrollStart;
148             _scroller.ScrollAnimationStopped += Scroller_ScrollStop;
149             _scroller.Scrolled += Scroller_Scrolled;
150         }
151
152         private void Scroller_Scrolled(object sender, EventArgs e)
153         {
154             Console.WriteLine($"scrolled : {_scroller.CurrentRegion}");
155         }
156
157         private void Scroller_ScrollStop(object sender, EventArgs e)
158         {
159             Console.WriteLine("scroll animation stop");
160         }
161
162         private void Scroller_ScrollStart(object sender, EventArgs e)
163         {
164              Console.WriteLine("scroll animation start");
165         }
166
167         private void Scroller_DragStop(object sender, EventArgs e)
168         {
169             Console.WriteLine("Drag stop");
170         }
171
172         private void Scroller_DragStart(object sender, EventArgs e)
173         {
174             Console.WriteLine("Drag start");
175         }
176     }
177 }