Release 8.0.0.15408
[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() { LinearOrientation = LinearLayout.Orientation.Horizontal, LinearAlignment = LinearLayout.Alignment.Center, CellPadding = new Size2D(100, 0) };
56             root.Add(parentView[0]);
57
58             for (int i = 0; i < 2; i++)
59             {
60                 createText[i] = new TextLabel();
61                 createText[i].Size = new Size(500, 100);
62                 createText[i].PointSize = 20.0f;
63                 createText[i].BackgroundColor = Color.Magenta;
64                 createText[i].HorizontalAlignment = HorizontalAlignment.Center;
65                 createText[i].VerticalAlignment = VerticalAlignment.Center;
66                 createText[i].MultiLine = true;
67                 parentView[0].Add(createText[i]);
68             }
69
70             // Text of "Create Switch just by Properties"
71             createText[0].Text = "Create Tab just by Properties";
72
73             // Text of "Create Switch just by Style"
74             createText[1].Text = "Create Tab just by Style";
75         }
76
77         private void CreateTabView()
78         {
79             // Init parent of TabView
80             parentView[1] = new View();
81             parentView[1].Size = new Size(1920, 200);
82             parentView[1].Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, LinearAlignment = LinearLayout.Alignment.Center, CellPadding = new Size2D(100, 0) };
83             root.Add(parentView[1]);
84
85             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
86             tab = new Tab();
87             tab.Size = new Size(700, 108);
88             tab.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
89             tab.Underline.Size = new Size(1, 3);
90             tab.Underline.BackgroundColor = color[0];
91             tab.PointSize = 25;
92             tab.TextColorSelector = new ColorSelector
93             {
94                 Normal = Color.Black,
95                 Selected = color[0],
96             };
97             tab.ItemChangedEvent += TabItemChangedEvent;
98             parentView[1].Add(tab);
99
100             for (int i = 0; i < 3; i++)
101             {
102                 Tab.TabItemData item = new Tab.TabItemData();
103                 item.Text = "Tab " + i;
104                 if (i == 1)
105                 {
106                     item.Text = "Long Tab " + i;
107                 }
108                 tab.AddItem(item);
109             }
110             tab.SelectedItemIndex = 0;
111
112             ///////////////////////////////////////////////Create by Style//////////////////////////////////////////////////////////
113             TabStyle st = new TabStyle
114             {
115                 //IsNatureTextWidth = false,
116                 ItemPadding = new Extents(56, 56, 1, 0),
117                 UnderLine = new ViewStyle
118                 {
119                     Size = new Size(1, 3),
120                     PositionUsesPivotPoint = true,
121                     ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft,
122                     PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
123                     BackgroundColor = new Selector<Color> { All = color[0] },
124                 },
125                 Text = new TextLabelStyle
126                 {
127                     PointSize = new Selector<float?> { All = 25 },
128                     TextColor = new Selector<Color>
129                     {
130                         Normal = Color.Black,
131                         Selected = color[0],
132                     },
133                 },
134             };
135
136             tab2 = new Tab(st);
137             tab2.Size = new Size(500, 108);
138             tab2.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
139             tab2.ItemChangedEvent += Tab2ItemChangedEvent;
140             parentView[1].Add(tab2);
141
142             for (int i = 0; i < 3; i++)
143             {
144                 Tab.TabItemData item = new Tab.TabItemData();
145                 item.Text = "Tab " + i;
146                 tab2.AddItem(item);
147             }
148             tab2.SelectedItemIndex = 0;
149         }
150
151         private void CreateButtonView()
152         {
153             // Init parent of ButtonView
154             parentView[2] = new View();
155             parentView[2].Size = new Size(1920, 200);
156             parentView[2].Layout = new LinearLayout() { LinearOrientation = LinearLayout.Orientation.Horizontal, LinearAlignment = LinearLayout.Alignment.Center, CellPadding = new Size2D(100, 0) };
157             root.Add(parentView[2]);
158
159             // Create Buttons
160             var buttonStyle = new ButtonStyle()
161             {
162                 Size = new Size(300, 80),
163                 Overlay = new ImageViewStyle()
164                 {
165                     ResourceUrl = new Selector<string>
166                     {
167                         Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
168                         Other = ""
169                     },
170                     Border = new Rectangle(5, 5, 5, 5)
171                 },
172                 Text = new TextLabelStyle()
173                 {
174                     TextColor = new Selector<Color>
175                     {
176                         Normal = new Color(0, 0, 0, 1),
177                         Pressed = new Color(0, 0, 0, 0.7f),
178                         Selected = new Color(0.058f, 0.631f, 0.92f, 1),
179                         Disabled = new Color(0, 0, 0, 0.4f)
180                     },
181                     PointSize = 18,
182                 },
183                 BackgroundImage = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png",
184                 BackgroundImageBorder = new Rectangle(5, 5, 5, 5),
185             };
186
187             // Button of switching mode
188             button = new Button(buttonStyle);
189             button.Size = new Size(500, 80);
190             button.TextLabel.Text = mode[index];
191             button.ClickEvent += ButtonClickEvent;
192             parentView[2].Add(button);
193
194             // Button of LayoutDirection
195             button2 = new Button(buttonStyle);
196             button2.Size = new Size(500, 80);
197             button2.TextLabel.Text = "LayoutDirection is left to right";
198             button2.ClickEvent += ButtonClickEvent2;
199             parentView[2].Add(button2);
200         }
201
202         private void TabItemChangedEvent(object sender, Tab.ItemChangedEventArgs e)
203         {
204             createText[0].Text = "Create Tab just by properties, Selected index from " + e.PreviousIndex + " to " + e.CurrentIndex;
205         }
206
207         public void Deactivate()
208         {
209             if (root != null)
210             {
211                 if (button != null)
212                 {
213                     button.Dispose();
214                     button = null;
215                 }
216
217                 if (button2 != null)
218                 {
219                     button2.Dispose();
220                     button2 = null;
221                 }
222
223                 if (tab != null)
224                 {
225                     tab.Dispose();
226                     tab = null;
227                 }
228
229                 if (tab2 != null)
230                 {
231                     tab2.Dispose();
232                     tab2 = null;
233                 }
234
235                 if (createText[0] != null)
236                 {
237                     createText[0].Dispose();
238                     createText[0] = null;
239                 }
240
241                 if (createText[1] != null)
242                 {
243                     createText[1].Dispose();
244                     createText[1] = null;
245                 }
246
247                 for (int j = 0; j < 3; j++)
248                 {
249                     if (parentView[j] != null)
250                     {
251                         parentView[j].Dispose();
252                         parentView[j] = null;
253                     }
254                 }
255
256                 NUIApplication.GetDefaultWindow().Remove(root);
257                 root.Dispose();
258                 root = null;
259             }
260         }
261
262         private void Tab2ItemChangedEvent(object sender, Tab.ItemChangedEventArgs e)
263         {
264             createText[1].Text = "Create Tab just by Style, Selected index from " + e.PreviousIndex + " to " + e.CurrentIndex;
265         }
266
267         private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
268         {
269             index = (index + 1) % 4;
270             button.TextLabel.Text = mode[index];
271             tab.Underline.BackgroundColor = color[index];
272             tab.TextColorSelector = new ColorSelector
273             {
274                 Normal = Color.Black,
275                 Selected = color[index],
276             };
277             tab2.Underline.BackgroundColor = color[index];
278             tab2.TextColorSelector = new ColorSelector
279             {
280                 Normal = Color.Black,
281                 Selected = color[index],
282             };
283         }
284
285         private void ButtonClickEvent2(object sender, Button.ClickEventArgs e)
286         {
287             if (tab.LayoutDirection == ViewLayoutDirectionType.LTR)
288             {
289                 tab.LayoutDirection = ViewLayoutDirectionType.RTL;
290                 tab2.LayoutDirection = ViewLayoutDirectionType.RTL;
291                 button2.TextLabel.Text = "LayoutDirection is right to left";
292             }
293             else
294             {
295                 tab.LayoutDirection = ViewLayoutDirectionType.LTR;
296                 tab2.LayoutDirection = ViewLayoutDirectionType.LTR;
297                 button2.TextLabel.Text = "LayoutDirection is left to right";
298             }
299         }
300     }
301 }