[NUI] Fix NUITizenGallery to run on Ubuntu VS-Code debugging
[platform/core/csapi/tizenfx.git] / test / NUITizenGallery / Examples / IndicatorViewTest / IndicatorViewTest2Page.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
18 using System.Collections.Generic;
19
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Components;
22 using Tizen.NUI;
23
24 namespace NUITizenGallery
25 {
26     public partial class IndicatorViewTest2Page : ContentPage
27     {
28         private readonly string ResourcePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "/images/";
29         private readonly int PagesCount = 5;
30         private List<Position> IndicatorPositions;
31
32         public IndicatorViewTest2Page()
33         {
34             InitializeComponent();
35             Scroller.ScrollAnimationEnded += OnScrollAnimationEnded;
36
37             PaginationStyle paginationStyle = new PaginationStyle()
38             {
39                 IndicatorSize = new Size(26, 26),
40                 IndicatorSpacing = 8,
41             };
42
43             Index.ApplyStyle(paginationStyle);
44             Index.IndicatorCount = PagesCount;
45             Index.SelectedIndex = 0;
46             Index.BackgroundColor = Tizen.NUI.Color.Gray;
47             Index.TouchEvent += OnIndexTouchEvent;
48
49             IndicatorPositions = new List<Position>();
50             for (int i = 0; i < PagesCount; ++i)
51             {
52                 IndicatorPositions.Add(Index.GetIndicatorPosition(i));
53             }
54         }
55
56         private bool OnIndexTouchEvent(object sender, TouchEventArgs args)
57         {
58             if (args.Touch.GetState(0) == Tizen.NUI.PointStateType.Finished)
59             {
60                 for (int i = PagesCount -1 ; i >= 0; i--)
61                 {
62                     if (args.Touch.GetLocalPosition(0).X >= IndicatorPositions[i].X)
63                     {
64                         Scroller.ScrollToIndex(i);
65                         break;
66                     }
67                 }
68             }
69
70             return true;
71         }
72
73         private void OnScrollAnimationEnded(object sender, ScrollEventArgs args)
74         {
75             Index.SelectedIndex = Scroller.CurrentPage;
76         }
77     }
78 }