TC for Scroller CurrentRegion
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / ScrollerTest5.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 ScrollerTest5 : TestCaseBase
23     {
24         public override string TestName => "ScrollerTest5";
25         public override string TestDescription => "To test basic operation of Scroller";
26
27         int _currentIndex = 0;
28
29         public override void Run(Window window)
30         {
31             Conformant conformant = new Conformant(window);
32             conformant.Show();
33             Box outterBox = new Box(window)
34             {
35                 AlignmentX = -1,
36                 AlignmentY = -1,
37                 WeightX = 1,
38                 WeightY = 1,
39                 IsHorizontal = false,
40             };
41             outterBox.Show();
42             conformant.SetContent(outterBox);
43
44             Scroller scroller = new Scroller(window)
45             {
46                 AlignmentX = -1,
47                 AlignmentY = -1,
48                 WeightX = 1,
49                 WeightY = 1,
50                 ScrollBlock = ScrollBlock.Vertical
51             };
52             scroller.Show();
53
54
55             Box innerBox = new Box(window)
56             {
57                 AlignmentX = -1,
58                 AlignmentY = -1,
59                 WeightX = 1,
60                 WeightY = 1,
61                 IsHorizontal = true,
62             };
63             innerBox.Show();
64             scroller.SetContent(innerBox);
65
66             Rectangle[] rects = new Rectangle[5];
67             Random rnd = new Random();
68             for(int i = 0; i < 5; i++)
69             {
70                 rects[i] = new Rectangle(window)
71                 {
72                     AlignmentX = -1,
73                     AlignmentY = -1,
74                     WeightX = 1,
75                     WeightY = 1,
76                     Color = Color.FromRgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)),
77                 };
78                 rects[i].Show();
79                 rects[i].MinimumWidth = 300;
80                 innerBox.PackEnd(rects[i]);
81             }
82             innerBox.MinimumWidth = 300 * 5;
83             _currentIndex = 4;
84
85
86             Button btn = new Button(window)
87             {
88                 AlignmentX = -1,
89                 WeightX = 1,
90                 Text = "Remove"
91             };
92             btn.Clicked += (s, e) =>
93             {
94                 System.Console.WriteLine("current index {0}", _currentIndex);
95                 System.Console.WriteLine("Before Current Region : {0}", scroller.CurrentRegion);
96                 innerBox.UnPack(rects[_currentIndex]);
97                 innerBox.MinimumWidth = 300 * _currentIndex;
98                 rects[_currentIndex].Hide();
99                 _currentIndex--;
100                 System.Console.WriteLine("After Current Region : {0}", scroller.CurrentRegion);
101
102                 EcoreMainloop.Post(() =>
103                 {
104                     System.Console.WriteLine("On idler Current Region : {0}", scroller.CurrentRegion);
105                 });
106
107                 EcoreMainloop.AddTimer(0, () =>
108                 {
109                     System.Console.WriteLine("After 0 sec Current Region : {0}", scroller.CurrentRegion);
110                     return false;
111                 });
112             };
113             scroller.Scrolled += (s, e) =>
114             {
115                 System.Console.WriteLine("Scrolled to {0}", scroller.CurrentRegion);
116             };
117
118             btn.Show();
119
120             outterBox.PackEnd(btn);
121             outterBox.PackEnd(scroller);
122             
123             
124         }
125     }
126 }