[NUI] Support Refactoring key focusable feature for non-focusable browsing.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / ScrollableFocus / ScrollableFocusSample2.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 ScrollableFocusSample2 : IExample
10     {
11         public View root;
12         TextLabel _label;
13
14         public void Activate()
15         {
16             Window window = NUIApplication.GetDefaultWindow();
17
18             root = new View();
19             root.Layout = new AbsoluteLayout();
20             root.Size = new Size(300, 800);
21
22             root.BackgroundColor = Color.White;
23             window.Add(root);
24
25             FocusManager.Instance.EnableDefaultAlgorithm(true);
26             root.Layout = new AbsoluteLayout();
27             root.WidthSpecification = LayoutParamPolicies.MatchParent;
28             root.HeightSpecification = LayoutParamPolicies.MatchParent;
29
30
31             _label = new TextLabel();
32             root.Add(_label);
33             _label.Position = new Position(0, 0);
34             _label.SizeWidth = 300;
35             _label.SizeHeight = 100;
36
37             var topPanel = new View
38             {
39                 Layout = new LinearLayout
40                 {
41                     LinearOrientation = LinearLayout.Orientation.Vertical
42                 },
43                 WidthSpecification = LayoutParamPolicies.MatchParent,
44                 HeightSpecification = LayoutParamPolicies.MatchParent,
45             };
46
47             for (int i = 0; i < 10; i++)
48             {
49                 topPanel.Add(CreateButton(i, false));
50             }
51             root.Add(topPanel);
52             topPanel.Position = new Position(0, 100);
53
54             var bottomPanel = new View
55             {
56                 Layout = new LinearLayout
57                 {
58                     LinearOrientation = LinearLayout.Orientation.Vertical,
59                 },
60                 BackgroundColor = Color.Yellow,
61                 WidthSpecification = LayoutParamPolicies.MatchParent,
62                 SizeHeight = 500,
63             };
64
65             for (int i = 0; i < 10; i++)
66             {
67                 bottomPanel.Add(CreateButton(11 + i, true));
68             }
69
70             root.Add(bottomPanel);
71             bottomPanel.Position = new Position(0, 500);
72
73             topPanel.RaiseToTop();
74
75         }
76
77         View CreateButton(int index, bool second)
78         {
79             var rnd = new Random();
80
81             var btn = new Button
82             {
83                 Focusable = true,
84                 FocusableInTouch = true,
85                 Text = $"Item {index}",
86             };
87             if (second)
88                 btn.BackgroundColor = Color.Red;
89
90             btn.WidthSpecification = LayoutParamPolicies.MatchParent;
91             btn.SizeHeight = 60;
92
93             btn.FocusGained += (s, e) =>
94             {
95                 btn.Text = $"[Item {index}]";
96                 _label.Text = btn.Text;
97             };
98             btn.FocusLost += (s, e) =>
99             {
100                 btn.Text = $"Item {index}";
101             };
102
103             return btn;
104         }
105
106         public void Deactivate()
107         {
108             if (root != null)
109             {
110                 NUIApplication.GetDefaultWindow().Remove(root);
111                 root.Dispose();
112             }
113         }
114     }
115
116 }