Merge "[Telephony] Sample App implementation."
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / ScrollerTest6.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 using System.Collections.Generic;
20
21 namespace ElmSharp.Test
22 {
23     public class ScrollerTest6 : TestCaseBase
24     {
25         public override string TestName => "ScrollerTest6";
26         public override string TestDescription => "To test basic operation of Scroller";
27
28         int _currentIndex = 0;
29
30         public override void Run(Window window)
31         {
32             Conformant conformant = new Conformant(window);
33             conformant.Show();
34             Box outterBox = new Box(window)
35             {
36                 AlignmentX = -1,
37                 AlignmentY = -1,
38                 WeightX = 1,
39                 WeightY = 1,
40                 IsHorizontal = false,
41             };
42             outterBox.Show();
43             conformant.SetContent(outterBox);
44
45             Scroller scroller = new Scroller(window)
46             {
47                 AlignmentX = -1,
48                 AlignmentY = -1,
49                 WeightX = 1,
50                 WeightY = 1,
51                 ScrollBlock = ScrollBlock.Vertical
52             };
53             scroller.Show();
54
55
56             Box innerBox = new Box(window)
57             {
58                 AlignmentX = -1,
59                 AlignmentY = -1,
60                 WeightX = 1,
61                 WeightY = 1,
62                 IsHorizontal = true,
63             };
64             innerBox.Show();
65             scroller.SetContent(innerBox);
66
67             var rects = new List<Rectangle>();
68             Random rnd = new Random();
69             for(int i = 0; i < 30; i++)
70             {
71                 var rect = new Rectangle(window)
72                 {
73                     AlignmentX = -1,
74                     AlignmentY = -1,
75                     WeightX = 1,
76                     WeightY = 1,
77                     Color = Color.FromRgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)),
78                 };
79                 rect.Show();
80                 innerBox.PackEnd(rect);
81                 rects.Add(rect);
82             };
83
84             innerBox.SetLayoutCallback(() =>
85             {
86                 System.Console.WriteLine("!!!! update layout");
87                 System.Console.WriteLine("MinimumWith = {0}", innerBox.MinimumWidth);
88
89             });
90             for (int i = 0; i < rects.Count; i++)
91             {
92                 rects[i].Geometry = new Rect(i / 3 * 400 + innerBox.Geometry.X, i % 3 * 400 + innerBox.Geometry.Y, 400, 400);
93             }
94             innerBox.MinimumWidth = (int)Math.Ceiling(rects.Count / 3.0) * 400;
95
96             Button btn = new Button(window)
97             {
98                 AlignmentX = -1,
99                 WeightX = 1,
100                 Text = "Remove"
101             };
102             btn.Clicked += (s, e) =>
103             {
104                 System.Console.WriteLine("current index {0}", _currentIndex);
105                 System.Console.WriteLine("Before Current Region : {0}", scroller.CurrentRegion);
106                 int last = rects.Count - 1;
107                 innerBox.UnPack(rects[last]);
108                 rects[last].Hide();
109                 rects.RemoveAt(last);
110
111                 System.Console.WriteLine(" innerBox MinimumWith = {0}", innerBox.MinimumWidth);
112                 System.Console.WriteLine("After Current Region : {0}", scroller.CurrentRegion);
113
114                 EcoreMainloop.Post(() =>
115                 {
116                     System.Console.WriteLine("On idler Current Region : {0}", scroller.CurrentRegion);
117                 });
118
119                 EcoreMainloop.AddTimer(0, () =>
120                 {
121                     System.Console.WriteLine("After 0 sec Current Region : {0}", scroller.CurrentRegion);
122                     return false;
123                 });
124             };
125             scroller.Scrolled += (s, e) =>
126             {
127                 System.Console.WriteLine("Scrolled to {0}", scroller.CurrentRegion);
128                 System.Console.WriteLine("in scrolling MinimumWith = {0}", innerBox.MinimumWidth);
129             };
130
131             btn.Show();
132
133             outterBox.PackEnd(btn);
134             outterBox.PackEnd(scroller);
135             
136             
137         }
138     }
139 }