baafd8a2c6b736f8adc551b6b10b47cffda4d20e
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.StyleGuide / Examples / PaginationExample.cs
1 /*
2  * Copyright(c) 2022 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 System;
18 using System.ComponentModel;
19 using Tizen.NUI;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Components;
22
23 namespace Tizen.NUI.StyleGuide
24 {
25     // IExample inehrited class will be automatically added in the main examples list.
26     internal class PaginationExample : ContentPage, IExample
27     {
28         private View rootContent;
29         private Button buttonLeft, buttonRight;
30         private TextLabel[] board = new TextLabel[2];
31         private Pagination[] pagination = new Pagination[2];
32         private View[] layout = new View[3];
33         private readonly int PAGE_COUNT = 5;
34
35
36
37         public void Activate()
38         {
39         }
40         public void Deactivate()
41         {
42         }
43
44         /// Modify this method for adding other examples.
45         public PaginationExample() : base()
46         {
47             WidthSpecification = LayoutParamPolicies.MatchParent;
48             HeightSpecification = LayoutParamPolicies.MatchParent;
49
50             // Navigator bar title is added here.
51             AppBar = new AppBar()
52             {
53                 Title = "Pagination Default Style",
54             };
55
56             // Example root content view.
57             // you can decorate, add children on this view.
58             rootContent = new View()
59             {
60                 WidthSpecification = LayoutParamPolicies.MatchParent,
61                 HeightSpecification = LayoutParamPolicies.MatchParent,
62
63                 Layout = new LinearLayout()
64                 {
65                     LinearOrientation = LinearLayout.Orientation.Vertical,
66                     HorizontalAlignment = HorizontalAlignment.Center,
67                     VerticalAlignment = VerticalAlignment.Center,
68                     CellPadding = new Size2D(10, 20),
69                 },
70             };
71
72             createBorads();
73
74             buttonLeft = new Button
75             {
76                 Name = "buttonLeft",
77                 Text = "Left",
78                 WidthSpecification = LayoutParamPolicies.MatchParent,
79             };
80             rootContent.Add(buttonLeft);
81
82             buttonLeft.Clicked += (s, e) =>
83             {
84                 if (pagination[0].SelectedIndex > 0)
85                 {
86                     pagination[0].SelectedIndex = pagination[0].SelectedIndex - 1;
87                 }
88                 if (pagination[1].SelectedIndex > 0)
89                 {
90                     pagination[1].SelectedIndex = pagination[1].SelectedIndex - 1;
91                 }
92             };
93
94             buttonRight = new Button
95             {
96                 Name = "buttonRight",
97                 Text = "Right",
98                 WidthSpecification = LayoutParamPolicies.MatchParent,
99             };
100             rootContent.Add(buttonRight);
101
102             buttonRight.Clicked += (s, e) =>
103             {
104                 if (pagination[0].SelectedIndex < pagination[0].IndicatorCount - 1)
105                 {
106                     pagination[0].SelectedIndex = pagination[0].SelectedIndex + 1;
107                 }
108                 if (pagination[1].SelectedIndex < pagination[1].IndicatorCount - 1)
109                 {
110                     pagination[1].SelectedIndex = pagination[1].SelectedIndex + 1;
111                 }
112             };
113
114             Content = rootContent;
115         }
116         void createBorads()
117         {
118             board[0] = new TextLabel();
119             board[0].Size = new Size(300, 50);
120             board[0].PointSize = 15;
121             board[0].HorizontalAlignment = HorizontalAlignment.Center;
122             board[0].VerticalAlignment = VerticalAlignment.Center;
123             board[0].BackgroundColor = Color.Magenta;
124             board[0].Text = "Property construction";
125             rootContent.Add(board[0]);
126
127             // Create by Properties
128             pagination[0] = new Pagination();
129             var path = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
130             var indicatorImageUrlStyle = new PaginationStyle()
131             {
132                 IndicatorSize = new Size(26, 26),
133                 IndicatorSpacing = 8,
134                 IndicatorImageUrl = new Selector<string>
135                 {
136                     Normal = path + "/pagination/pagination_ic_nor.png",
137                     Selected = path + "/pagination/pagination_ic_sel.png"
138                 }
139             };
140             pagination[0].ApplyStyle(indicatorImageUrlStyle);
141             pagination[0].Name = "Pagination1";
142             pagination[0].Size = new Size(300, 50);
143             pagination[0].BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.6f);
144             pagination[0].IndicatorCount = PAGE_COUNT;
145             pagination[0].SelectedIndex = 0;
146             rootContent.Add(pagination[0]);
147
148             board[1] = new TextLabel();
149             board[1].Size = new Size(300, 50);
150             board[1].PointSize = 15;
151             board[1].HorizontalAlignment = HorizontalAlignment.Center;
152             board[1].VerticalAlignment = VerticalAlignment.Center;
153             board[1].BackgroundColor = Color.Magenta;
154             board[1].Text = "Attribute construction";
155             rootContent.Add(board[1]);
156
157             // Create by Attributes
158             PaginationStyle style = new PaginationStyle()
159             {
160                 IndicatorSize = new Size(15, 15),
161                 IndicatorSpacing = 20,
162                 IndicatorImageUrl = new Selector<string>
163                 {
164                     Normal = path + "/pagination/pagination_ic_nor.png",
165                     Selected = path + "/pagination/pagination_ic_sel.png"
166                 }
167             };
168             pagination[1] = new Pagination(style);
169             pagination[1].Name = "Pagination2";
170             pagination[1].Size = new Size(300, 50);
171             pagination[1].BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.6f);
172             pagination[1].IndicatorCount = PAGE_COUNT;
173             pagination[1].SelectedIndex = 0;
174             rootContent.Add(pagination[1]);
175         }
176     }
177 }