Merge "[Telephony] Sample App implementation."
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / BoxLayoutTest1.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 System.Linq;
19
20 namespace ElmSharp.Test
21 {
22     public class BoxLayoutTest1 : TestCaseBase
23     {
24         public override string TestName => "BoxLayoutTest1";
25         public override string TestDescription => "Box Layout callback test";
26
27         Naviframe _navi;
28         int _sequence = 0;
29
30         public override void Run(Window window)
31         {
32             Conformant conformant = new Conformant(window);
33             conformant.Show();
34
35             Naviframe navi = new Naviframe(window)
36             {
37                 PreserveContentOnPop = true,
38                 DefaultBackButtonEnabled = true
39             };
40             _navi = navi;
41
42             navi.Popped += (s, e) =>
43             {
44                 Console.WriteLine("----- Naviframe was popped {0:x} ", (int)(IntPtr)e.Content);
45             };
46
47             navi.Push(CreatePage(window), "0 Page");
48             navi.Show();
49             conformant.SetContent(navi);
50         }
51
52         EvasObject CreatePage(Window parent)
53         {
54             Box box = new Box(parent);
55             box.Show();
56
57             Label label = new Label(parent)
58             {
59                 Text = string.Format("{0} Page", _sequence++),
60                 WeightX = 1,
61                 AlignmentX = -1,
62             };
63             Button push = new Button(parent)
64             {
65                 Text = "Push",
66                 WeightX = 1,
67                 AlignmentX = -1,
68             };
69             Button pop = new Button(parent)
70             {
71                 Text = "pop",
72                 WeightX = 1,
73                 AlignmentX = -1,
74             };
75
76             label.Show();
77             push.Show();
78             pop.Show();
79
80             push.Clicked += (s, e) =>
81             {
82                 _navi.Push(CreatePage(parent), string.Format("{0} Page", _sequence - 1));
83             };
84
85             pop.Clicked += (s, e) =>
86             {
87                 var item = _navi.NavigationStack.LastOrDefault();
88                 int nativePointer = (int)(IntPtr)(item.Content);
89                 Console.WriteLine("----- Before Call _navi.Pop() {0:x} ", nativePointer);
90                 _navi.Pop();
91                 Console.WriteLine("----- After Call _navi.Pop() {0:x} ", nativePointer);
92             };
93
94             push.Resize(500, 100);
95             pop.Resize(500, 100);
96             label.Resize(500, 100);
97             box.SetLayoutCallback(() =>
98             {
99                 Console.WriteLine("Layout callback with : {0}", box.Geometry);
100                 var rect = box.Geometry;
101                 label.Move(rect.X, rect.Y);
102                 push.Move(rect.X, rect.Y + 100);
103                 pop.Move(rect.X, rect.Y + 200);
104             });
105
106             box.PackEnd(label);
107             box.PackEnd(push);
108             box.PackEnd(pop);
109             return box;
110         }
111     }
112 }