Add ScreenDpi API in Window class
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / ScreenInformationTest.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 ScreenInformationTest : TestCaseBase
23     {
24         public override string TestName => "ScreenInformationTest";
25         public override string TestDescription => "To get screen information";
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             Box box = new Box(window);
35             box.Show();
36             conformant.SetContent(box);
37             Label label = new Label(window);
38             label.SetAlignment(-1, 0);
39             label.SetWeight(1, 0);
40             label.Text = string.Format("<span color=#FFFFFF , font_size=50>ScreenSize : {0}x{1}", window.ScreenSize.Width, window.ScreenSize.Height);
41             label.Show();
42             box.PackEnd(label);
43             Label label2 = new Label(window);
44             label2.SetAlignment(-1, 0);
45             label2.SetWeight(1, 0);
46             label2.Text = string.Format("<span color=#FFFFFF , font_size=50>ScreenDPI : xdpi : {0} ydpi : {1}", window.ScreenDpi.X, window.ScreenDpi.Y);
47             label2.Show();
48             box.PackEnd(label2);
49         }
50
51         EvasObject CreatePage(Window parent)
52         {
53             Box box = new Box(parent);
54             box.Show();
55
56             Label label = new Label(parent)
57             {
58                 Text = string.Format("{0} Page", _sequence++),
59                 WeightX = 1,
60                 AlignmentX = -1,
61             };
62             Button push = new Button(parent)
63             {
64                 Text = "Push",
65                 WeightX = 1,
66                 AlignmentX = -1,
67             };
68             Button pop = new Button(parent)
69             {
70                 Text = "pop",
71                 WeightX = 1,
72                 AlignmentX = -1,
73             };
74
75             label.Show();
76             push.Show();
77             pop.Show();
78
79             push.Clicked += (s, e) =>
80             {
81                 _navi.Push(CreatePage(parent), string.Format("{0} Page", _sequence - 1));
82             };
83
84             pop.Clicked += (s, e) =>
85             {
86                 var item = _navi.NavigationStack.LastOrDefault();
87                 int nativePointer = (int)(IntPtr)(item.Content);
88                 Console.WriteLine("----- Before Call _navi.Pop() {0:x} ", nativePointer);
89                 _navi.Pop();
90                 Console.WriteLine("----- After Call _navi.Pop() {0:x} ", nativePointer);
91             };
92
93             push.Resize(500, 100);
94             pop.Resize(500, 100);
95             label.Resize(500, 100);
96             box.SetLayoutCallback(() =>
97             {
98                 Console.WriteLine("Layout callback with : {0}", box.Geometry);
99                 var rect = box.Geometry;
100                 label.Move(rect.X, rect.Y);
101                 push.Move(rect.X, rect.Y + 100);
102                 pop.Move(rect.X, rect.Y + 200);
103             });
104
105             box.PackEnd(label);
106             box.PackEnd(push);
107             box.PackEnd(pop);
108             return box;
109         }
110     }
111 }