Merge "[Telephony] Sample App implementation."
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / IndexTest2.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 IndexTest2 : TestCaseBase
24     {
25         Dictionary<IndexItem, int> _indexTable = new Dictionary<IndexItem, int>();
26
27         public override string TestName => "IndexTest2";
28         public override string TestDescription => "To test basic operation of Index";
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             Scroller scroller = new Scroller(window)
43             {
44                 AlignmentX = -1,
45                 AlignmentY = -1,
46                 WeightX = 1,
47                 WeightY = 1,
48                 ScrollBlock = ScrollBlock.Vertical,
49                 HorizontalPageScrollLimit = 1,
50             };
51             scroller.SetPageSize(1.0, 1.0);
52             scroller.Show();
53
54             Box box = new Box(window)
55             {
56                 AlignmentX = -1,
57                 AlignmentY = -1,
58                 WeightX = 1,
59                 WeightY = 1,
60                 IsHorizontal = true,
61             };
62             box.Show();
63             scroller.SetContent(box);
64
65             Index index = new Index(window)
66             {
67                 IsHorizontal = true,
68                 Style = "pagecontrol",
69                 AlignmentX = -1,
70                 WeightX = 1,
71                 MinimumHeight = 200,
72             };
73             index.Show();
74
75             var rnd = new Random();
76             for (int i = 0; i < 10; i++)
77             {
78                 int r = rnd.Next(255);
79                 int g = rnd.Next(255);
80                 int b = rnd.Next(255);
81                 Color color = Color.FromRgb(r, g, b);
82                 Rectangle colorBox = new Rectangle(window)
83                 {
84                     AlignmentX = -1,
85                     AlignmentY = -1,
86                     WeightX = 1,
87                     WeightY = 1,
88                     Color = color,
89                     MinimumWidth = window.ScreenSize.Width,
90                 };
91                 colorBox.Show();
92                 Console.WriteLine("Height = {0}", colorBox.Geometry.Height);
93                 box.PackEnd(colorBox);
94                 var item = index.Append(string.Format("{0}", i));
95                 item.Selected += (s, e) =>
96                 {
97                     scroller.ScrollTo(_indexTable[(IndexItem)s], 0, true);
98                 };
99                 _indexTable[item] = i;
100             }
101
102             conformant.SetContent(outterBox);
103             outterBox.PackEnd(scroller);
104
105             Button prev = new Button(window)
106             {
107                 AlignmentX = -1,
108                 WeightX = 1,
109                 Text = "Prev"
110             };
111             Button next = new Button(window)
112             {
113                 AlignmentX = -1,
114                 WeightX = 1,
115                 Text = "next"
116             };
117             prev.Clicked += (s, e) =>
118             {
119                 scroller.ScrollTo(scroller.HorizontalPageIndex > 0 ? scroller.HorizontalPageIndex - 1 : 0, scroller.VerticalPageIndex, true);
120             };
121             next.Clicked += (s, e) =>
122             {
123                 scroller.ScrollTo(scroller.HorizontalPageIndex + 1, scroller.VerticalPageIndex, true);
124             };
125             prev.Show();
126             next.Show();
127             outterBox.PackEnd(prev);
128             outterBox.PackEnd(next);
129             outterBox.PackEnd(index);
130
131             scroller.DragStart += Scroller_DragStart;
132             scroller.DragStop += Scroller_DragStop;
133         }
134
135         private void Scroller_DragStop(object sender, EventArgs e)
136         {
137             Console.WriteLine("Drag stop");
138         }
139
140         private void Scroller_DragStart(object sender, EventArgs e)
141         {
142             Console.WriteLine("Drag start");
143         }
144     }
145 }