ac76986439010e65c9bea8204fb669893041e55b
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / ScrollableFocus / ScrollableFocusSample.cs
1 using System;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI;
4 using Tizen.NUI.Components;
5
6
7 namespace Tizen.NUI.Samples
8 {
9     public class ScrollableFocusSample : IExample
10     {
11         public View root;
12
13         public void Activate()
14         {
15             Window window = NUIApplication.GetDefaultWindow();
16
17             root = new View();
18             root.Layout = new AbsoluteLayout();
19             root.Size = new Size(500, 800);
20
21             root.BackgroundColor = Color.White;
22             window.Add(root);
23
24             FocusManager.Instance.EnableDefaultAlgorithm(true);
25             root.Layout = new LinearLayout
26             {
27                 LinearOrientation = LinearLayout.Orientation.Vertical
28             };
29             root.WidthSpecification = LayoutParamPolicies.MatchParent;
30             root.HeightSpecification = LayoutParamPolicies.MatchParent;
31
32
33             var topbtn = new Button
34             {
35                 Focusable = true,
36                 FocusableInTouch = true,
37                 Text = "Top"
38             };
39             root.Add(topbtn);
40
41             var scrollview = new ScrollableBase
42             {
43                 ScrollingDirection = ScrollableBase.Direction.Vertical,
44                 WidthSpecification = LayoutParamPolicies.MatchParent,
45                 HeightSpecification = LayoutParamPolicies.MatchParent,
46                 BackgroundColor = Color.Gray
47             };
48             scrollview.ContentContainer.Layout = new AbsoluteLayout();
49             scrollview.ContentContainer.WidthSpecification = LayoutParamPolicies.MatchParent;
50             scrollview.ContentContainer.SizeHeight = 1800;
51             root.Add(scrollview);
52             for (int i = 0; i < 40; i++)
53             {
54                 scrollview.ContentContainer.Add(CreateButton(i));
55             }
56
57             var middle = new Button
58             {
59                 Focusable = true,
60                 FocusableInTouch = true,
61                 Text = "Middle"
62             };
63             root.Add(middle);
64
65             var myscrollview = new ScrollableBase
66             {
67                 ScrollingDirection = ScrollableBase.Direction.Vertical,
68                 WidthSpecification = LayoutParamPolicies.MatchParent,
69                 HeightSpecification = LayoutParamPolicies.MatchParent,
70                 BackgroundColor = Color.Yellow
71             };
72             myscrollview.ContentContainer.Layout = new AbsoluteLayout();
73             myscrollview.ContentContainer.WidthSpecification = LayoutParamPolicies.MatchParent;
74             myscrollview.ContentContainer.SizeHeight = 1800;
75             root.Add(myscrollview);
76             for (int i = 0; i < 40; i++)
77             {
78                 myscrollview.ContentContainer.Add(CreateButton(i));
79             }
80
81             var bottom = new Button
82             {
83                 Focusable = true,
84                 FocusableInTouch = true,
85                 Text = "bottom"
86             };
87             root.Add(bottom);
88
89         }
90
91         static View CreateButton(int index)
92         {
93             var rnd = new Random();
94
95             var btn = new Button
96             {
97                 Focusable = true,
98                 FocusableInTouch = true,
99                 Text = $"Item {index}",
100             };
101             // btn.FocusGained += (s, e) =>
102             // {
103             //   Tizen.Log.Error("NUI", $"[[{btn.Text}]] \n");
104             // };
105
106             var item = Wrapping(btn);
107             item.SizeWidth = 200;
108             item.SizeHeight = 90;
109
110             item.Position = new Position(220 * (index % 3), 100 * (index / 3) );
111
112             if (item is Button button)
113             {
114                 button.Text = $"[{button.Text}]";
115             }
116
117             return item;
118         }
119
120         static View Wrapping(View view)
121         {
122             int cnt = new Random().Next(0, 4);
123
124             for (int i = 0; i < cnt; i++)
125             {
126                 var wrapper = new View();
127                 view.WidthSpecification = LayoutParamPolicies.MatchParent;
128                 view.HeightSpecification = LayoutParamPolicies.MatchParent;
129                 wrapper.Add(view);
130                 view = wrapper;
131             }
132
133             return view;
134         }
135
136         public void Deactivate()
137         {
138             if (root != null)
139             {
140                 NUIApplication.GetDefaultWindow().Remove(root);
141                 root.Dispose();
142             }
143         }
144     }
145
146 }