[NUI] Remove build warning messages in NUI Samples (#4932)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / TabSample.cs
1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4
5 namespace Tizen.NUI.Samples
6 {
7     public class TabSample : IExample
8     {
9         private View root;
10         private View[] parentView = new View[3];
11
12         private TextLabel[] createText = new TextLabel[2];
13         private Tab tab = null;
14         private Tab tab2 = null;
15         private Button button = null;
16         private Button button2 = null;
17         private int index = 0;
18
19         private static string[] mode = new string[]
20         {
21             "Utility Tab",
22             "Family Tab",
23             "Food Tab",
24             "Kitchen Tab",
25         };
26         private static Color[] color = new Color[]
27         {
28         new Color(0.05f, 0.63f, 0.9f, 1),//#ff0ea1e6 Utility
29         new Color(0.14f, 0.77f, 0.28f, 1),//#ff24c447 Family
30         new Color(0.75f, 0.46f, 0.06f, 1),//#ffec7510 Food
31         new Color(0.59f, 0.38f, 0.85f, 1),//#ff9762d9 Kitchen
32         };
33
34         public void Activate()
35         {
36             Window window = NUIApplication.GetDefaultWindow();
37
38             root = new View()
39             {
40                 Size = new Size(1920, 1080),
41                 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
42             };
43             root.Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Vertical };
44             window.Add(root);
45
46             CreateTextView();
47             CreateTabView();
48             CreateButtonView();
49         }
50         private void CreateTextView()
51         {
52             // Init parent of TextView
53             parentView[0] = new View();
54             parentView[0].Size = new Size(1920, 300);
55             parentView[0].Layout = new LinearLayout() 
56             {
57                 LinearOrientation = LinearLayout.Orientation.Horizontal,
58                 HorizontalAlignment = HorizontalAlignment.Center,
59                 VerticalAlignment = VerticalAlignment.Center,
60                 CellPadding = new Size2D(100, 0)
61             };
62             root.Add(parentView[0]);
63
64             for (int i = 0; i < 2; i++)
65             {
66                 createText[i] = new TextLabel();
67                 createText[i].Size = new Size(500, 100);
68                 createText[i].PointSize = 20.0f;
69                 createText[i].BackgroundColor = Color.Magenta;
70                 createText[i].HorizontalAlignment = HorizontalAlignment.Center;
71                 createText[i].VerticalAlignment = VerticalAlignment.Center;
72                 createText[i].MultiLine = true;
73                 parentView[0].Add(createText[i]);
74             }
75
76             // Text of "Create Switch just by Properties"
77             createText[0].Text = "Create Tab just by Properties";
78
79             // Text of "Create Switch just by Style"
80             createText[1].Text = "Create Tab just by Style";
81         }
82
83         private void CreateTabView()
84         {
85             // Init parent of TabView
86             parentView[1] = new View();
87             parentView[1].Size = new Size(1920, 200);
88             parentView[1].Layout = new LinearLayout() 
89             {
90                 LinearOrientation = LinearLayout.Orientation.Horizontal,
91                 HorizontalAlignment = HorizontalAlignment.Center,
92                 VerticalAlignment = VerticalAlignment.Center,
93                 CellPadding = new Size2D(100, 0)
94             };
95             root.Add(parentView[1]);
96
97             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
98             tab = new Tab();
99             tab.Size = new Size(700, 108);
100             tab.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
101             tab.Underline.Size = new Size(1, 3);
102             tab.Underline.BackgroundColor = color[0];
103             tab.PointSize = 25;
104             tab.TextColorSelector = new ColorSelector
105             {
106                 Normal = Color.Black,
107                 Selected = color[0],
108             };
109             tab.ItemChangedEvent += TabItemChangedEvent;
110             parentView[1].Add(tab);
111
112             for (int i = 0; i < 3; i++)
113             {
114                 Tab.TabItemData item = new Tab.TabItemData();
115                 item.Text = "Tab " + i;
116                 if (i == 1)
117                 {
118                     item.Text = "Long Tab " + i;
119                 }
120                 tab.AddItem(item);
121             }
122             tab.SelectedItemIndex = 0;
123
124             ///////////////////////////////////////////////Create by Style//////////////////////////////////////////////////////////
125             TabStyle st = new TabStyle
126             {
127                 //IsNatureTextWidth = false,
128                 ItemPadding = new Extents(56, 56, 1, 0),
129                 UnderLine = new ViewStyle
130                 {
131                     Size = new Size(1, 3),
132                     PositionUsesPivotPoint = true,
133                     ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft,
134                     PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
135                     BackgroundColor = new Selector<Color> { All = color[0] },
136                 },
137                 Text = new TextLabelStyle
138                 {
139                     PointSize = new Selector<float?> { All = 25 },
140                     TextColor = new Selector<Color>
141                     {
142                         Normal = Color.Black,
143                         Selected = color[0],
144                     },
145                 },
146             };
147
148             tab2 = new Tab(st);
149             tab2.Size = new Size(500, 108);
150             tab2.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
151             tab2.ItemChangedEvent += Tab2ItemChangedEvent;
152             parentView[1].Add(tab2);
153
154             for (int i = 0; i < 3; i++)
155             {
156                 Tab.TabItemData item = new Tab.TabItemData();
157                 item.Text = "Tab " + i;
158                 tab2.AddItem(item);
159             }
160             tab2.SelectedItemIndex = 0;
161         }
162
163         private void CreateButtonView()
164         {
165             // Init parent of ButtonView
166             parentView[2] = new View();
167             parentView[2].Size = new Size(1920, 200);
168             parentView[2].Layout = new LinearLayout() 
169             {
170                 LinearOrientation = LinearLayout.Orientation.Horizontal,
171                 HorizontalAlignment = HorizontalAlignment.Center,
172                 VerticalAlignment = VerticalAlignment.Center,
173                 CellPadding = new Size2D(100, 0)
174             };
175             root.Add(parentView[2]);
176
177             // Create Buttons
178             var buttonStyle = new ButtonStyle()
179             {
180                 Size = new Size(300, 80),
181                 Overlay = new ImageViewStyle()
182                 {
183                     ResourceUrl = new Selector<string>
184                     {
185                         Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
186                         Other = ""
187                     },
188                     Border = new Rectangle(5, 5, 5, 5)
189                 },
190                 Text = new TextLabelStyle()
191                 {
192                     TextColor = new Selector<Color>
193                     {
194                         Normal = new Color(0, 0, 0, 1),
195                         Pressed = new Color(0, 0, 0, 0.7f),
196                         Selected = new Color(0.058f, 0.631f, 0.92f, 1),
197                         Disabled = new Color(0, 0, 0, 0.4f)
198                     },
199                     PointSize = 18,
200                 },
201                 BackgroundImage = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png",
202                 BackgroundImageBorder = new Rectangle(5, 5, 5, 5),
203             };
204
205             // Button of switching mode
206             button = new Button(buttonStyle);
207             button.Size = new Size(500, 80);
208             button.TextLabel.Text = mode[index];
209             button.Clicked += ButtonClicked;
210             parentView[2].Add(button);
211
212             // Button of LayoutDirection
213             button2 = new Button(buttonStyle);
214             button2.Size = new Size(500, 80);
215             button2.TextLabel.Text = "LayoutDirection is left to right";
216             button2.Clicked += ButtonClicked2;
217             parentView[2].Add(button2);
218         }
219
220         private void TabItemChangedEvent(object sender, Tab.ItemChangedEventArgs e)
221         {
222             createText[0].Text = "Create Tab just by properties, Selected index from " + e.PreviousIndex + " to " + e.CurrentIndex;
223         }
224
225         public void Deactivate()
226         {
227             if (root != null)
228             {
229                 if (button != null)
230                 {
231                     button.Dispose();
232                     button = null;
233                 }
234
235                 if (button2 != null)
236                 {
237                     button2.Dispose();
238                     button2 = null;
239                 }
240
241                 if (tab != null)
242                 {
243                     tab.Dispose();
244                     tab = null;
245                 }
246
247                 if (tab2 != null)
248                 {
249                     tab2.Dispose();
250                     tab2 = null;
251                 }
252
253                 if (createText[0] != null)
254                 {
255                     createText[0].Dispose();
256                     createText[0] = null;
257                 }
258
259                 if (createText[1] != null)
260                 {
261                     createText[1].Dispose();
262                     createText[1] = null;
263                 }
264
265                 for (int j = 0; j < 3; j++)
266                 {
267                     if (parentView[j] != null)
268                     {
269                         parentView[j].Dispose();
270                         parentView[j] = null;
271                     }
272                 }
273
274                 NUIApplication.GetDefaultWindow().Remove(root);
275                 root.Dispose();
276                 root = null;
277             }
278         }
279
280         private void Tab2ItemChangedEvent(object sender, Tab.ItemChangedEventArgs e)
281         {
282             createText[1].Text = "Create Tab just by Style, Selected index from " + e.PreviousIndex + " to " + e.CurrentIndex;
283         }
284
285         private void ButtonClicked(object sender, ClickedEventArgs e)
286         {
287             index = (index + 1) % 4;
288             button.TextLabel.Text = mode[index];
289             tab.Underline.BackgroundColor = color[index];
290             tab.TextColorSelector = new ColorSelector
291             {
292                 Normal = Color.Black,
293                 Selected = color[index],
294             };
295             tab2.Underline.BackgroundColor = color[index];
296             tab2.TextColorSelector = new ColorSelector
297             {
298                 Normal = Color.Black,
299                 Selected = color[index],
300             };
301         }
302
303         private void ButtonClicked2(object sender, ClickedEventArgs e)
304         {
305             if (tab.LayoutDirection == ViewLayoutDirectionType.LTR)
306             {
307                 tab.LayoutDirection = ViewLayoutDirectionType.RTL;
308                 tab2.LayoutDirection = ViewLayoutDirectionType.RTL;
309                 button2.TextLabel.Text = "LayoutDirection is right to left";
310             }
311             else
312             {
313                 tab.LayoutDirection = ViewLayoutDirectionType.LTR;
314                 tab2.LayoutDirection = ViewLayoutDirectionType.LTR;
315                 button2.TextLabel.Text = "LayoutDirection is left to right";
316             }
317         }
318     }
319 }