Release 8.0.0.15408
[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 text_nullstyle, text_style;
10         private Button[] button = new Button[4];
11         private ScrollBar[] scrollBar = new ScrollBar[3];
12         private View root;
13         private View top_parent, bottom_parent, null_style_parent, style_parent;
14
15         public void Activate()
16         {
17             Window window = NUIApplication.GetDefaultWindow();
18             root = new View()
19             {
20                 Size = new Size(1920, 1080),
21                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
22             };
23             root.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical };
24             window.Add(root);
25
26             // TextLabel of Null style construction and Style construction
27             CreateTopView();
28
29             // Buttons for moving thumbnail
30             CreateBottomView();
31         }
32         private void CreateTopView()
33         {
34             top_parent = new View() { Size = new Size(1920, 540) };
35             top_parent.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal };
36             root.Add(top_parent);
37             CreateNullStylePart();
38             CreateStylePart();
39         }
40
41         private void CreateNullStylePart()
42         {
43             null_style_parent = new View() { Size = new Size(960, 540) };
44             null_style_parent.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical, LinearAlignment = LinearLayout.Alignment.Center, CellPadding = new Size2D(0, 50) };
45             top_parent.Add(null_style_parent);
46
47             // Add Textlabel of "Null style construction"
48             text_nullstyle = new TextLabel();
49             text_nullstyle.Size = new Size(400, 70);
50             text_nullstyle.PointSize = 20;
51             text_nullstyle.HorizontalAlignment = HorizontalAlignment.Center;
52             text_nullstyle.VerticalAlignment = VerticalAlignment.Center;
53             text_nullstyle.BackgroundColor = Color.Magenta;
54             text_nullstyle.Text = "Null style construction";
55             text_nullstyle.Focusable = true;
56             null_style_parent.Add(text_nullstyle);
57
58             // Add ScrollBar of Null style construction
59             scrollBar[0] = new ScrollBar();
60             scrollBar[0].Size = new Size(400, 4);
61             scrollBar[0].TrackColor = Color.Green;
62             scrollBar[0].MaxValue = (int)scrollBar[0].SizeWidth / 10;
63             scrollBar[0].MinValue = 0;
64             scrollBar[0].ThumbSize = new Size(30, 4);
65             scrollBar[0].CurrentValue = 0; //set after thumbsize
66             scrollBar[0].ThumbColor = Color.Black;
67             null_style_parent.Add(scrollBar[0]);
68
69             scrollBar[1] = new ScrollBar();
70             scrollBar[1].Size = new Size(400, 4);
71             scrollBar[1].TrackColor = Color.Green;
72             scrollBar[1].MaxValue = (int)scrollBar[1].SizeWidth / 10;
73             scrollBar[1].MinValue = 0;
74             scrollBar[1].ThumbSize = new Size(30, 4);
75             scrollBar[1].CurrentValue = 0;//set after thumbsize
76             scrollBar[1].ThumbColor = Color.Yellow;
77             scrollBar[1].TrackImageURL = CommonResource.GetTVResourcePath() + "component/c_progressbar/c_progressbar_white_buffering.png";
78             null_style_parent.Add(scrollBar[1]);
79         }
80         
81         private void CreateStylePart()
82         {
83             style_parent = new View() { Size = new Size(960, 540) };
84             style_parent.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical, LinearAlignment = LinearLayout.Alignment.CenterVertical, CellPadding = new Size2D(0, 50) };
85             top_parent.Add(style_parent);
86
87             // Add Textlabel of "Style construction"
88             text_style = new TextLabel();
89             text_style.Size = new Size(400, 70);
90             text_style.PointSize = 20;
91             text_style.HorizontalAlignment = HorizontalAlignment.Center;
92             text_style.VerticalAlignment = VerticalAlignment.Center;
93             text_style.BackgroundColor = Color.Magenta;
94             text_style.Text = "Style construction";
95             text_style.Focusable = true;
96             style_parent.Add(text_style);
97
98             // Add ScrollBar of Style construction
99             ScrollBarStyle st = new ScrollBarStyle
100             {
101                 Track = new ImageViewStyle
102                 {
103                     BackgroundColor = new Selector<Color>
104                     {
105                         All = new Color(0.43f, 0.43f, 0.43f, 0.1f),
106                     }
107                 },
108                 Thumb = new ImageViewStyle
109                 {
110                     BackgroundColor = new Selector<Color>
111                     {
112                         All = new Color(1.0f, 0.0f, 0.0f, 0.2f),
113                     }
114                 },
115             };
116             scrollBar[2] = new ScrollBar(st);
117             scrollBar[2].Size = new Size(400, 4);
118             scrollBar[2].MaxValue = (int)scrollBar[2].SizeWidth / 10;
119             scrollBar[2].MinValue = 0;
120             scrollBar[2].ThumbSize = new Size(30, 4);
121             scrollBar[2].CurrentValue = 0;//set after thumbsize
122             style_parent.Add(scrollBar[2]);
123         }
124
125         private void CreateBottomView()
126         {
127             bottom_parent = new View() { Size = new Size(1920, 540) };
128             bottom_parent.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, LinearAlignment = LinearLayout.Alignment.Center, CellPadding = new Size2D(50, 50) };
129             root.Add(bottom_parent);
130
131             // Create buttons
132             CreateButtons();
133         }
134
135         void CreateButtons()
136         {
137             for (int i = 0; i < 4; i++)
138             {
139                 button[i] = new Button();
140                 button[i].BackgroundColor = Color.Green;
141                 button[i].Size = new Size(80, 50);
142                 button[i].Focusable = true;
143                 bottom_parent.Add(button[i]);
144             }
145
146             button[0].Text = "+";
147             button[0].ClickEvent += Scroll1Add;
148
149             button[1].Text = "-";
150             button[1].ClickEvent += Scroll1Minus;
151
152             button[2].Text = "+ / - 4";
153             button[2].ClickEvent += Scroll1_2move;
154
155             button[3].Text = "change direction";
156             button[3].ClickEvent += Scroll1_2Changed;
157             button[3].Size = new Size(180, 50);
158
159             // Set focus to Add Button
160             FocusManager.Instance.SetCurrentFocusView(button[0]);
161         }
162
163         private void Scroll1Add(object sender, global::System.EventArgs e)
164         {
165             scrollBar[0].CurrentValue++;
166             scrollBar[2].CurrentValue++;
167         }
168         private void Scroll1Minus(object sender, global::System.EventArgs e)
169         {
170             scrollBar[0].CurrentValue--;
171             scrollBar[2].CurrentValue--;
172         }
173
174         private void Scroll1_2Changed(object sender, global::System.EventArgs e)
175         {
176             if (scrollBar[1].LayoutDirection == ViewLayoutDirectionType.LTR)
177             {
178                 scrollBar[1].LayoutDirection = ViewLayoutDirectionType.RTL;
179             }
180             else
181             {
182                 scrollBar[1].LayoutDirection = ViewLayoutDirectionType.LTR;
183             }
184         }
185
186         private void Scroll1_2move(object sender, global::System.EventArgs e)
187         {
188             if (scrollBar[1].CurrentValue < scrollBar[1].MaxValue / 2)
189             {
190                 scrollBar[1].SetCurrentValue(scrollBar[1].MaxValue - 2);
191             }
192             else
193             {
194                 scrollBar[1].SetCurrentValue(2);
195             }
196         }
197
198         public void Deactivate()
199         {
200             if (root != null)
201             {
202                 NUIApplication.GetDefaultWindow().Remove(root);
203                 if (text_nullstyle != null)
204                 {
205                     text_nullstyle.Dispose();
206                     text_nullstyle = null;
207                 }
208
209                 if (text_style != null)
210                 {
211                     text_style.Dispose();
212                     text_style = null;
213                 }
214
215                 for (int i = 0; i < 4; i++)
216                 {
217                     if (button[i] != null)
218                     {
219                         button[i].Dispose();
220                         button[i] = null;
221                     }
222                 }
223
224                 for (int i = 0; i < 3; i++)
225                 {
226                     if (scrollBar[i] != null)
227                     {
228                         scrollBar[i].Dispose();
229                         scrollBar[i] = null;
230                     }
231                 }
232
233                 if (top_parent != null)
234                 {
235                     top_parent.Dispose();
236                     top_parent = null;
237                 }
238
239                 if (bottom_parent != null)
240                 {
241                     bottom_parent.Dispose();
242                     bottom_parent = null;
243                 }
244
245                 if (null_style_parent != null)
246                 {
247                     null_style_parent.Dispose();
248                     null_style_parent = null;
249                 }
250
251                 if (style_parent != null)
252                 {
253                     style_parent.Dispose();
254                     style_parent = null;
255                 }
256
257                 root.Dispose();
258                 root = null;
259             }
260         }
261     }
262 }