[NUI] Add TabItem to support TabView in xaml
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / TabViewTest / TabViewWithIconOnlyTestPage.xaml.cs
1 /*
2  * Copyright(c) 2023 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.BaseComponents;
19 using Tizen.NUI.Components;
20
21 namespace NUITizenGallery
22 {
23     public partial class TabViewWithIconOnlyTestPage : ContentPage
24     {
25         private int tabCount = 2;
26
27         public TabViewWithIconOnlyTestPage()
28         {
29             InitializeComponent();
30         }
31
32         private TabButton CreateTabButton()
33         {
34             return new TabButton() { IconURL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "home.png", };
35         }
36
37         private void AddTabClickedCb(object sender, ClickedEventArgs args)
38         {
39             if (tabCount < 4)
40             {
41                 tabView.AddTab(CreateTabButton(), CreateView());
42                 tabCount++;
43             }
44         }
45
46         private void RemoveTabClickedCb(object sender, ClickedEventArgs args)
47         {
48             if (tabCount > 1)
49             {
50                 tabView.RemoveTab(tabCount - 1);
51                 tabCount--;
52             }
53         }
54
55         private View CreateView()
56         {
57             Color backgroundColor;
58             Color buttonBackgroundColor;
59
60             if ((tabCount + 1) % 4 == 0)
61             {
62                 backgroundColor = Color.DarkGreen;
63                 buttonBackgroundColor = Color.Green;
64             }
65             else if ((tabCount + 1) % 4 == 1)
66             {
67                 backgroundColor = Color.DarkRed;
68                 buttonBackgroundColor = Color.Red;
69             }
70             else if ((tabCount + 1) % 4 == 2)
71             {
72                 backgroundColor = Color.DarkBlue;
73                 buttonBackgroundColor = Color.Blue;
74             }
75             else
76             {
77                 backgroundColor = Color.SaddleBrown;
78                 buttonBackgroundColor = Color.Orange;
79             }
80
81             var container = new View()
82             {
83                 Layout = new LinearLayout()
84                 {
85                     LinearOrientation = LinearLayout.Orientation.Vertical,
86                     HorizontalAlignment = HorizontalAlignment.Center,
87                     VerticalAlignment = VerticalAlignment.Center,
88                     CellPadding = new Size2D(0, 20),
89                 },
90                 BackgroundColor = backgroundColor,
91                 WidthSpecification = LayoutParamPolicies.MatchParent,
92                 HeightSpecification = LayoutParamPolicies.MatchParent,
93             };
94
95             var buttonAddTab = new Button()
96             {
97                 Text = "Add Tab",
98                 BackgroundColor = buttonBackgroundColor,
99             };
100             buttonAddTab.Clicked += AddTabClickedCb;
101             container.Add(buttonAddTab);
102
103             var buttonRemoveTab = new Button()
104             {
105                 Text = "Remove Tab",
106                 BackgroundColor = buttonBackgroundColor,
107             };
108             buttonRemoveTab.Clicked += RemoveTabClickedCb;
109             container.Add(buttonRemoveTab);
110
111             return container;
112         }
113     }
114 }