1e094f227061a962bf84453d87d21e0b865cc5c2
[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
11         private TextLabel[] createText = new TextLabel[2];
12
13         private Tab tab = null;
14         private Tab tab2 = null;
15
16         private Button button = null;
17         private Button button2 = null;
18         private int index = 0;
19
20         private static string[] mode = new string[]
21         {
22             "Utility Tab",
23             "Family Tab",
24             "Food Tab",
25             "Kitchen Tab",
26         };
27         private static Color[] color = new Color[]
28         {
29         new Color(0.05f, 0.63f, 0.9f, 1),//#ff0ea1e6 Utility
30         new Color(0.14f, 0.77f, 0.28f, 1),//#ff24c447 Family
31         new Color(0.75f, 0.46f, 0.06f, 1),//#ffec7510 Food
32         new Color(0.59f, 0.38f, 0.85f, 1),//#ff9762d9 Kitchen
33         };
34         public void Activate()
35         {
36             Window window = Window.Instance;
37
38             root = new View()
39             {
40                 Size2D = new Size2D(1920, 1080),
41             };
42             window.Add(root);
43
44             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
45             createText[0] = new TextLabel();
46             createText[0].Text = "Create Tab just by properties";
47             createText[0].Size2D = new Size2D(450, 100);
48             createText[0].Position2D = new Position2D(200, 100);
49             createText[0].MultiLine = true;
50             root.Add(createText[0]);
51
52             tab = new Tab();
53             tab.Size2D = new Size2D(700, 108);
54             tab.Position2D = new Position2D(100, 300);
55             tab.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
56             //tab.IsNatureTextWidth = true;
57             //tab.ItemGap = 40;
58             //tab.LeftSpace = 56;
59             //tab.RightSpace = 56;
60             //tab.TopSpace = 1;
61             //tab.BottomSpace = 0;
62             tab.Style.UnderLine.Size = new Size(1, 3);
63             tab.Style.UnderLine.BackgroundColor = color[0];
64             tab.Style.Text.PointSize = 25;
65             tab.Style.Text.TextColor = new Selector<Color>
66             {
67                 Normal = Color.Black,
68                 Selected = color[0],
69             };
70             tab.ItemChangedEvent += TabItemChangedEvent;
71             root.Add(tab);
72
73             for (int i = 0; i < 3; i++)
74             {
75                 Tab.TabItemData item = new Tab.TabItemData();
76                 item.Text = "Tab " + i;
77                 if(i==1)
78                 {
79                     item.Text = "Long Tab " + i;
80                 }
81                 tab.AddItem(item);
82             }
83             tab.SelectedItemIndex = 0;
84
85             ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
86             createText[1] = new TextLabel();
87             createText[1].Text = "Create Tab just by Attributes";
88             createText[1].Size2D = new Size2D(450, 100);
89             createText[1].Position2D = new Position2D(1000, 100);
90             createText[1].MultiLine = true;
91             root.Add(createText[1]);
92
93             TabStyle attrs = new TabStyle
94             {
95                 //IsNatureTextWidth = false,
96                 ItemPadding = new Extents(56, 56, 1, 0),
97                 UnderLine = new ViewStyle
98                 {
99                     Size = new Size(1, 3),
100                     PositionUsesPivotPoint = true,
101                     ParentOrigin = Tizen.NUI.ParentOrigin.BottomLeft,
102                     PivotPoint = Tizen.NUI.PivotPoint.BottomLeft,
103                     BackgroundColor = new Selector<Color> { All = color[0]},
104                 },
105                 Text = new TextLabelStyle
106                 {
107                     PointSize = new Selector<float?> { All = 25 },
108                     TextColor = new Selector<Color>
109                     {
110                         Normal = Color.Black,
111                         Selected = color[0],
112                     },
113                 },                
114             };
115
116             tab2 = new Tab(attrs);
117             tab2.Size2D = new Size2D(500, 108);
118             tab2.Position2D = new Position2D(900, 300);
119             tab2.BackgroundColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
120             tab2.ItemChangedEvent += Tab2ItemChangedEvent;
121             root.Add(tab2);
122
123             for (int i = 0; i < 3; i++)
124             {
125                 Tab.TabItemData item = new Tab.TabItemData();
126                 item.Text = "Tab " + i;
127                 tab2.AddItem(item);
128             }
129             tab2.SelectedItemIndex = 0;
130
131             button = new Button();
132             button.Style.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
133             button.Style.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
134             button.Size2D = new Size2D(280, 80);
135             button.Position2D = new Position2D(400, 700);
136             button.Style.Text.Text = mode[index];
137             button.ClickEvent += ButtonClickEvent;
138             root.Add(button);
139
140             button2 = new Button();
141             button2.Style.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
142             button2.Style.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
143             button2.Size2D = new Size2D(580, 80);
144             button2.Position2D = new Position2D(250, 500);
145             button2.Style.Text.Text = "LayoutDirection is left to right";
146             button2.ClickEvent += ButtonClickEvent2;
147             root.Add(button2);
148         }
149
150         private void TabItemChangedEvent(object sender, Tab.ItemChangedEventArgs e)
151         {
152             createText[0].Text = "Create Tab just by properties, Selected index from " + e.PreviousIndex + " to " + e.CurrentIndex;
153         }
154
155         public void Deactivate()
156         {
157             if (root != null)
158             {
159                 if (button != null)
160                 {
161                     root.Remove(button);
162                     button.Dispose();
163                     button = null;
164                 }
165
166                 if (button2 != null)
167                 {
168                     root.Remove(button2);
169                     button2.Dispose();
170                     button2 = null;
171                 }
172
173                 if (tab != null)
174                 {
175                     root.Remove(tab);
176                     tab.Dispose();
177                     tab = null;
178                 }
179                 if (tab2 != null)
180                 {
181                     root.Remove(tab2);
182                     tab2.Dispose();
183                     tab2 = null;
184                 }
185
186                 if (createText[0] != null)
187                 {
188                     root.Remove(createText[0]);
189                     createText[0].Dispose();
190                     createText[0] = null;
191                 }
192                 if (createText[1] != null)
193                 {
194                     root.Remove(createText[1]);
195                     createText[1].Dispose();
196                     createText[1] = null;
197                 }
198
199                 Window.Instance.Remove(root);
200                 root.Dispose();
201                 root = null;
202             }
203         }
204
205         private void Tab2ItemChangedEvent(object sender, Tab.ItemChangedEventArgs e)
206         {
207             createText[1].Text = "Create Tab just by Attributes, Selected index from " + e.PreviousIndex + " to " + e.CurrentIndex;
208         }
209
210         private void ButtonClickEvent(object sender, Button.ClickEventArgs e)
211         {
212             index = (index + 1) % 4;
213             button.Style.Text.Text = mode[index];
214             tab.Style.UnderLine.BackgroundColor = color[index];
215             tab.Style.Text.TextColor = new Selector<Color>
216             {
217                 Normal = Color.Black,
218                 Selected = color[index],
219             };
220             tab2.Style.UnderLine.BackgroundColor = color[index];
221             tab2.Style.Text.TextColor = new Selector<Color>
222             {
223                 Normal = Color.Black,
224                 Selected = color[index],
225             };
226         }
227
228         private void ButtonClickEvent2(object sender, Button.ClickEventArgs e)
229         {
230             if (tab.LayoutDirection == ViewLayoutDirectionType.LTR)
231             {
232                 tab.LayoutDirection = ViewLayoutDirectionType.RTL;
233                 tab2.LayoutDirection = ViewLayoutDirectionType.RTL;
234                 button2.Style.Text.Text = "LayoutDirection is right to left";
235             }
236             else
237             {
238                 tab.LayoutDirection = ViewLayoutDirectionType.LTR;
239                 tab2.LayoutDirection = ViewLayoutDirectionType.LTR;
240                 button2.Style.Text.Text = "LayoutDirection is left to right";
241             }
242         }
243     }
244 }