[NUI] NUI samples (#1225)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / ScrollBarSample.cs
1 using Tizen.NUI;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4
5 namespace Tizen.NUI.Samples
6 {
7     public class ScrollbarSample : IExample
8     {
9         private TextLabel board1, board2, board;
10         private Button button1, button2, button3, button4, button5;
11         private ScrollBar scrollBar1_1, scrollBar1_2, scrollBar2_1, scrollBar2_2;  //1-null para 2-attributes; X_1-color; X_2 image track
12         private View root;
13
14         public void Activate()
15         {
16             Window window = Window.Instance;
17
18             root = new View()
19             {
20                 Size2D = new Size2D(1920, 1080),
21             };
22
23             CreateBoardAndButtons();
24
25             scrollBar1_1 = new ScrollBar();
26             scrollBar1_1.Position2D = new Position2D(50, 300);
27             scrollBar1_1.Size2D = new Size2D(300, 4);
28             scrollBar1_1.Style.Track.BackgroundColor = Color.Green;           
29             scrollBar1_1.MaxValue = (int)scrollBar1_1.SizeWidth / 10;
30             scrollBar1_1.MinValue = 0;
31             scrollBar1_1.Style.Thumb.Size = new Size(30, 4);
32             scrollBar1_1.CurrentValue = 0; //set after thumbsize
33             scrollBar1_1.Style.Thumb.BackgroundColor = Color.Black;
34             root.Add(scrollBar1_1);
35
36             scrollBar1_2 = new ScrollBar();
37             scrollBar1_2.Position2D = new Position2D(50, 400);
38             scrollBar1_2.Size2D = new Size2D(300, 4);
39             scrollBar1_2.Style.Track.BackgroundColor = Color.Green;
40             scrollBar1_2.MaxValue = (int)scrollBar1_2.SizeWidth / 10;
41             scrollBar1_2.MinValue = 0;
42             scrollBar1_2.Style.Thumb.Size = new Size(30, 4);
43             scrollBar1_2.CurrentValue = 0;//set after thumbsize
44             scrollBar1_2.Style.Thumb.BackgroundColor = Color.Yellow;
45             scrollBar1_2.Style.Track.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_progressbar/c_progressbar_white_buffering.png";
46
47             root.Add(scrollBar1_2);
48
49             ScrollBarStyle attr = new ScrollBarStyle
50             {
51                 Track = new ImageViewStyle
52                 {
53                     BackgroundColor = new Selector<Color>
54                     {
55                         All = new Color(0.43f, 0.43f, 0.43f, 0.1f),
56                     }
57                 },
58                 Thumb = new ImageViewStyle
59                 {
60                     BackgroundColor = new Selector<Color>
61                     {
62                         All = new Color(1.0f, 0.0f, 0.0f, 0.2f),
63                     }
64                 },
65             };
66
67             scrollBar2_1 = new ScrollBar(attr);
68             scrollBar2_1.Position2D = new Position2D(500, 300);
69             scrollBar2_1.Size2D = new Size2D(300, 4);
70             scrollBar2_1.MaxValue = (int)scrollBar2_1.SizeWidth / 10;
71             scrollBar2_1.MinValue = 0;
72             scrollBar2_1.Style.Thumb.Size = new Size(30, 4);
73             scrollBar2_1.CurrentValue = 0; //set after thumbsize
74             root.Add(scrollBar2_1);
75
76             board.UpFocusableView = button1;
77
78             window.Add(root);
79
80             FocusManager.Instance.SetCurrentFocusView(button1);
81         }
82
83         void CreateBoardAndButtons()
84         {
85
86             board = new TextLabel();
87             board.Size2D = new Size2D(1000, 100);
88             board.Position2D = new Position2D(430, 900);
89             board.PointSize = 30;
90             board.HorizontalAlignment = HorizontalAlignment.Center;
91             board.VerticalAlignment = VerticalAlignment.Center;
92             board.BackgroundColor = Color.Magenta;
93             board.Text = "log pad";
94             root.Add(board);
95             board.Focusable = true;
96             board.FocusGained += Board_FocusGained;
97             board.FocusLost += Board_FocusLost;
98
99             board1 = new TextLabel();
100             board1.Size2D = new Size2D(300, 70);
101             board1.Position2D = new Position2D(50, 150);
102             board1.PointSize = 20;
103             board1.HorizontalAlignment = HorizontalAlignment.Center;
104             board1.VerticalAlignment = VerticalAlignment.Center;
105             board1.BackgroundColor = Color.Magenta;
106             board1.Text = "NULL parameter construction";
107             root.Add(board1);
108             board1.Focusable = true;
109             board1.FocusGained += Board_FocusGained;
110             board1.FocusLost += Board_FocusLost;
111
112             board2 = new TextLabel();
113             board2.Size2D = new Size2D(300, 70);
114             board2.Position2D = new Position2D(500, 150);
115             board2.PointSize = 20;
116             board2.HorizontalAlignment = HorizontalAlignment.Center;
117             board2.VerticalAlignment = VerticalAlignment.Center;
118             board2.BackgroundColor = Color.Magenta;
119             board2.Text = "Attribute construction";
120             root.Add(board2);
121             board2.Focusable = true;
122             board2.FocusGained += Board_FocusGained;
123             board2.FocusLost += Board_FocusLost;
124
125             button1 = new Button();
126             button1.BackgroundColor = Color.Green;
127             button1.Position2D = new Position2D(100, 700);
128             button1.Size2D = new Size2D(80, 50);
129             button1.Style.Text.Text = "+";
130             root.Add(button1);
131             button1.Focusable = true;
132             button1.ClickEvent += Scroll1Add;
133
134             button2 = new Button();
135             button2.BackgroundColor = Color.Green;
136             button2.Position2D = new Position2D(200, 700);
137             button2.Size2D = new Size2D(80, 50);
138             button2.Style.Text.Text = "-";
139             root.Add(button2);
140             button2.Focusable = true;
141             button2.ClickEvent += Scroll1Minus;
142
143             button5 = new Button();
144             button5.BackgroundColor = Color.Green;
145             button5.Position2D = new Position2D(400, 800);
146             button5.Size2D = new Size2D(100, 50);
147             button5.Style.Text.Text = "+ / - 4";
148             root.Add(button5);
149             button5.Focusable = true;
150             button5.ClickEvent += Scroll1_2move;
151
152             Button  button22 = new Button();
153             button22.BackgroundColor = Color.Green;
154             button22.Position2D = new Position2D(100, 800);
155             button22.Size2D = new Size2D(200, 50);
156             button22.Style.Text.Text = "change direction";
157             root.Add(button22);
158             button22.Focusable = true;
159             button22.ClickEvent += Scroll1_2Changed;
160
161             button3 = new Button();
162             button3.BackgroundColor = Color.Green;
163             button3.Position2D = new Position2D(450, 700);
164             button3.Size2D = new Size2D(80, 50);
165             button3.Style.Text.Text = "+";
166             root.Add(button3);
167             button3.Focusable = true;
168             button3.ClickEvent += Scroll2Add;
169
170             button4 = new Button();
171             button4.BackgroundColor = Color.Green;
172             button4.Position2D = new Position2D(550, 700);
173             button4.Size2D = new Size2D(80, 50);
174             button4.Style.Text.Text = "-";
175             root.Add(button4);
176             button4.Focusable = true;
177             button4.ClickEvent += Scroll2Minus;
178         }
179
180         private void Board_FocusLost(object sender, global::System.EventArgs e)
181         {
182             board.BackgroundColor = Color.Magenta;
183         }
184
185         private void Board_FocusGained(object sender, global::System.EventArgs e)
186         {
187             board.BackgroundColor = Color.Cyan;
188         }
189
190         private void Scroll1Add(object sender, global::System.EventArgs e)
191         {
192             scrollBar1_1.CurrentValue++;
193         }
194         private void Scroll1Minus(object sender, global::System.EventArgs e)
195         {
196             scrollBar1_1.CurrentValue--;
197         }
198         private void Scroll2Add(object sender, global::System.EventArgs e)
199         {
200             scrollBar2_1.CurrentValue++;
201         }
202         private void Scroll2Minus(object sender, global::System.EventArgs e)
203         {
204             scrollBar2_1.CurrentValue--;
205         }
206
207         private void Scroll1_2Changed(object sender, global::System.EventArgs e)
208         {
209             if(scrollBar1_2.LayoutDirection == ViewLayoutDirectionType.LTR)
210                 scrollBar1_2.LayoutDirection= ViewLayoutDirectionType.RTL;
211             else
212                 scrollBar1_2.LayoutDirection = ViewLayoutDirectionType.LTR;
213         }
214
215         private void Scroll1_2move(object sender, global::System.EventArgs e)
216         {
217             if (scrollBar1_2.CurrentValue < scrollBar1_2.MaxValue / 2)
218             {
219                 scrollBar1_2.SetCurrentValue(scrollBar1_2.MaxValue - 2);
220             }
221             else
222             {
223                 scrollBar1_2.SetCurrentValue(2);
224             }
225         }
226
227         private void ScrollPan(object sender, global::System.EventArgs e)
228         {
229             board.Text = board.Text + " 1";
230             if (board.Text.Length > 20)
231                 board.Text = "";
232         }
233
234         public void Deactivate()
235         {
236             if (root != null)
237             {
238                 Window.Instance.Remove(root);
239                 root.Dispose();
240             }
241         }
242     }
243 }