[NUI] Change for Size2D property to own internalSize2D which is cashed to prevent...
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / NavigatorTest1 / NavigatorTest1Page.xaml.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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 Tizen.NUI;
18 using Tizen.NUI.Components;
19
20 namespace NUITizenGallery
21 {
22     public partial class NavigatorTest1Page : ContentPage
23     {
24         public NavigatorTest1Page()
25         {
26             InitializeComponent();
27         }
28
29         private void SetButtonColor(NavigatorTest1Page page, int type)
30         {
31             Color backgroundColor;
32
33             if (type == 0)
34             {
35                 backgroundColor = Color.DarkGreen;
36             }
37             else if (type == 1)
38             {
39                 backgroundColor = Color.DarkRed;
40             }
41             else if (type == 2)
42             {
43                 backgroundColor = Color.DarkBlue;
44             }
45             else
46             {
47                 backgroundColor = Color.SaddleBrown;
48             }
49
50             page.buttonPush.BackgroundColor = backgroundColor;
51             page.buttonPop.BackgroundColor = backgroundColor;
52             page.buttonInsert.BackgroundColor = backgroundColor;
53             page.buttonInsertBefore.BackgroundColor = backgroundColor;
54             page.buttonRemove.BackgroundColor = backgroundColor;
55             page.buttonRemoveAt.BackgroundColor = backgroundColor;
56         }
57
58         private void ButtonPushClicked(object sender, ClickedEventArgs args)
59         {
60             if (Navigator == null)
61             {
62                 Tizen.Log.Error("NUI", "The page should be pushed to a Navigator.\n");
63                 return;
64             }
65
66             var newPage = new NavigatorTest1Page();
67             SetButtonColor(newPage, Navigator.PageCount % 4);
68             newPage.AppBar.Title = "NavigatorTest1Page" + Navigator.PageCount.ToString();
69             Navigator.Push(newPage);
70             Tizen.Log.Info("NUI", newPage.AppBar.Title + " has been pushed.\n");
71         }
72
73         private void ButtonPopClicked(object sender, ClickedEventArgs args)
74         {
75             if (Navigator == null)
76             {
77                 Tizen.Log.Error("NUI", "The page should be pushed to a Navigator.\n");
78                 return;
79             }
80
81             var poppedPage = Navigator.Pop() as NavigatorTest1Page;
82             Tizen.Log.Info("NUI", poppedPage.AppBar.Title + " has been popped.\n");
83         }
84
85         private void ButtonInsertClicked(object sender, ClickedEventArgs args)
86         {
87             if (Navigator == null)
88             {
89                 Tizen.Log.Error("NUI", "The page should be pushed to a Navigator.\n");
90                 return;
91             }
92
93             var newPage = new NavigatorTest1Page();
94             SetButtonColor(newPage, Navigator.PageCount % 4);
95             newPage.AppBar.Title = "NavigatorTest1Page" + Navigator.PageCount.ToString();
96             Navigator.Insert(Navigator.PageCount, newPage);
97             Tizen.Log.Info("NUI", newPage.AppBar.Title + " has been inserted.\n");
98         }
99
100         private void ButtonInsertBeforeClicked(object sender, ClickedEventArgs args)
101         {
102             if (Navigator == null)
103             {
104                 Tizen.Log.Error("NUI", "The page should be pushed to a Navigator.\n");
105                 return;
106             }
107
108             var newPage = new NavigatorTest1Page();
109             SetButtonColor(newPage, Navigator.PageCount % 4);
110             newPage.AppBar.Title = "NavigatorTest1Page" + Navigator.PageCount.ToString();
111             Navigator.InsertBefore(Navigator.Peek(), newPage);
112             Tizen.Log.Info("NUI", newPage.AppBar.Title + " has been inserted before the peek page.\n");
113         }
114
115         private void ButtonRemoveClicked(object sender, ClickedEventArgs args)
116         {
117             if (Navigator == null)
118             {
119                 Tizen.Log.Error("NUI", "The page should be pushed to a Navigator.\n");
120                 return;
121             }
122
123             var removedPage = Navigator.Peek() as NavigatorTest1Page;
124             Navigator.Remove(removedPage);
125             Tizen.Log.Info("NUI", removedPage.AppBar.Title + " has been removed.\n");
126         }
127
128         private void ButtonRemoveAtClicked(object sender, ClickedEventArgs args)
129         {
130             if (Navigator == null)
131             {
132                 Tizen.Log.Error("NUI", "This page should be pushed to a Navigator.\n");
133                 return;
134             }
135
136             if (Navigator.PageCount <= 2)
137             {
138                 Tizen.Log.Info("NUI", "This test removes the previous page unless the previous page is the main page.\n");
139                 return;
140             }
141
142             int removedIndex = Navigator.PageCount - 2;
143             var removedPage = Navigator.GetPage(removedIndex) as NavigatorTest1Page;
144             Navigator.RemoveAt(removedIndex);
145             Tizen.Log.Info("NUI", removedPage.AppBar.Title + " has been removed.\n");
146         }
147     }
148 }