[NUI] add style guide sample. (#3944)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.StyleGuide / Examples / ScrollableBase / ScrollableBaseExample.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 System.Collections.Generic;
20 using Tizen.NUI;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.Components;
23 using Tizen.NUI.Binding;
24
25 namespace Tizen.NUI.StyleGuide
26 {
27     // IExample inehrited class will be automatically added in the main examples list.
28     internal class ScrollableBaseExample : ContentPage, IExample
29     {
30         private Window window;
31         private List<DirectionOption> directionMenu;
32         public void Activate()
33         {
34             Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Activate()\n");
35         }
36         public void Deactivate()
37         {
38             Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Deactivate()\n");
39             window = null;
40             directionMenu = null;
41         }
42
43         /// Modify this method for adding other examples.
44         public ScrollableBaseExample() : base()
45         {
46             Log.Info(this.GetType().Name, $"{this.GetType().Name} is contructed\n");
47
48             // Navigator bar title is added here.
49             AppBar = new AppBar()
50             {
51                 Title = "ScrollableBase Default Style",
52             };
53
54             directionMenu = new List<DirectionOption>();
55             directionMenu.Add(new DirectionOption("Vertical"));
56             directionMenu.Add(new DirectionOption("Horizontal"));
57
58             // Example root content view.
59             // you can decorate, add children on this view.
60             // ScrollableBase need two different style guide.
61             // so here we adding new CollectionView for 2-depth option.
62             var directionListView = new CollectionView()
63             {
64                 WidthSpecification = LayoutParamPolicies.MatchParent,
65                 HeightSpecification = LayoutParamPolicies.MatchParent,
66                 ItemsSource = directionMenu,
67                 ItemsLayouter = new LinearLayouter(),
68                 ItemTemplate = new DataTemplate(() =>
69                 {
70                     DefaultLinearItem item = new DefaultLinearItem()
71                     {
72                         WidthSpecification = LayoutParamPolicies.MatchParent,
73                     };
74                     item.Label.SetBinding(TextLabel.TextProperty, "Direction");
75                     item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
76                     return item;
77                 }),
78                 ScrollingDirection = ScrollableBase.Direction.Vertical,
79                 SelectionMode = ItemSelectionMode.SingleAlways,
80             };
81             directionListView.SelectionChanged += (object colView, SelectionChangedEventArgs ev) =>
82             {
83                 if (ev.CurrentSelection.Count == 0) return;
84                 if (ev.CurrentSelection[0] is DirectionOption directionItem)
85                 {
86                     Log.Info(this.GetType().Name, $"{directionItem.Direction} will be activated!\n");
87                     Page scrollDirPage = new ScrollableBaseDirectionExample(directionItem.Direction);
88                     window = NUIApplication.GetDefaultWindow();
89                     window.GetDefaultNavigator().Push(scrollDirPage);
90                 }
91                 directionListView.SelectedItem = null;
92             };
93
94             Content = directionListView;
95         }
96     }
97
98     internal class DirectionOption
99     {
100         private string direction;
101         public string Direction { get => direction; }
102
103         public DirectionOption(string dir)
104         {
105             direction = dir;
106         }
107     }
108 }