[NUI] Merge NUI.Samples to TizenFX (#1222)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / ButtonSample.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 ButtonSample : IExample
8     {
9         private static readonly int XBase = 100;
10         private static readonly int YBase = 300;
11         private static readonly int XPadding = 350;
12         private View root;
13         Button textButton;
14         Button iconButton;
15
16         Button iconTextButton;
17
18         Button utilityBasicButton;
19         Button utilityServiceButton;
20         Button utilityToggleButton;
21         Button utilityOvalButton;
22
23         Button familyBasicButton;
24         Button familyServiceButton;
25         Button familyToggleButton;
26         Button familyOvalButton;
27
28         public void Activate()
29         {
30             Window window = Window.Instance;
31
32             //ImageView imageView1 = new ImageView();
33             //imageView1.Size2D = new Size2D(48, 48);
34             //imageView1.Position2D = new Position2D(200, 200);
35             //imageView1.ResourceUrl = CommonResource.GetFHResourcePath() + "9. Controller/controller_btn_check.png";
36             //window.Add(imageView1);
37
38             //ImageView imageView2 = new ImageView();
39             //imageView2.Size2D = new Size2D(48, 48);
40             //imageView2.Position2D = new Position2D(500, 200);
41             //imageView2.ResourceUrl = CommonResource.GetFHResourcePath() + "9. Controller/[Controller] App Primary Color/controller_btn_check_on_24c447.png";
42             //window.Add(imageView2);
43
44             root = new View()
45             {
46                 Size2D = new Size2D(1920, 1080),
47             };
48             window.Add(root);
49             window.KeyEvent += Window_KeyEvent;
50
51             textButton = new Button();
52             textButton.Style.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
53             textButton.Style.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
54             textButton.Size2D = new Size2D(300, 80);
55             textButton.Position2D = new Position2D(100, 100);
56             textButton.Style.Text.Text = "Button";
57             root.Add(textButton);
58
59             iconButton = new Button();
60             iconButton.Style.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
61             iconButton.Style.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
62             iconButton.Size2D = new Size2D(100, 100);
63             iconButton.Position2D = new Position2D(600, 100);
64             iconButton.Style.Icon.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_radiobutton/c_radiobutton_white_check.png";
65             root.Add(iconButton);
66
67             iconTextButton = new Button();
68             iconTextButton.Style.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
69             iconTextButton.Style.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
70             iconTextButton.IconRelativeOrientation = Button.IconOrientation.Left;
71             iconTextButton.Style.Icon.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_radiobutton/c_radiobutton_white_check.png";
72             iconTextButton.Style.IconPadding.Top = 20;
73             iconTextButton.Style.IconPadding.Bottom = 20;
74             iconTextButton.Style.IconPadding.Start = 20;
75             iconTextButton.Style.IconPadding.End = 20;
76             iconTextButton.Style.Text.Text = "IconTextButton";
77             iconTextButton.Style.TextPadding.Top = 20;
78             iconTextButton.Style.TextPadding.Bottom = 20;
79             iconTextButton.Style.TextPadding.Start = 20;
80             iconTextButton.Style.TextPadding.End = 50;
81             iconTextButton.Size2D = new Size2D(500, 300);
82             iconTextButton.Position2D = new Position2D(900, 100);
83             root.Add(iconTextButton);
84
85             ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
86             utilityBasicButton = new Button();
87             utilityBasicButton.IsSelectable = true;
88             utilityBasicButton.Style.BackgroundImage = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png";
89             utilityBasicButton.Style.BackgroundImageBorder = new Rectangle(5, 5, 5, 5);
90             utilityBasicButton.Style.Shadow.ResourceUrl = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png";
91             utilityBasicButton.Style.Shadow.Border = new Rectangle(5, 5, 5, 5);
92             utilityBasicButton.Style.Overlay.ResourceUrl = new Selector<string>
93             {
94                 Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
95                 Other = ""
96             };
97             utilityBasicButton.Style.Overlay.Border = new Rectangle(5, 5, 5, 5);
98
99             utilityBasicButton.Style.Text.TextColor = new Selector<Color>
100             {
101                 Normal = new Color(0, 0, 0, 1),
102                 Pressed = new Color(0, 0, 0, 0.7f),
103                 Selected = new Color(0.058f, 0.631f, 0.92f, 1),
104                 Disabled = new Color(0, 0, 0, 0.4f)
105             };
106
107             utilityBasicButton.Size2D = new Size2D(300, 80);
108             utilityBasicButton.Position2D = new Position2D(XBase, 300);
109             utilityBasicButton.Style.Text.PointSize = 20;
110             utilityBasicButton.Style.Text.Text = "UtilityBasicButton";
111             utilityBasicButton.IsEnabled = false;
112             root.Add(utilityBasicButton);
113
114             /////////////////////////////////////////////////////////////////////////////////////////////////////////
115             utilityServiceButton = new Button();
116             utilityServiceButton.Style.BackgroundImage = CommonResource.GetFHResourcePath() + "3. Button/rectangle_point_btn_normal.png";
117             utilityServiceButton.Style.BackgroundImageBorder = new Rectangle(5, 5, 5, 5);
118             utilityServiceButton.Style.Shadow.ResourceUrl = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png";
119             utilityServiceButton.Style.Shadow.Border = new Rectangle(5, 5, 5, 5);
120             utilityServiceButton.Style.Overlay.ResourceUrl = new Selector<string>
121             {
122                 Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
123                 Other = ""
124             };
125             utilityServiceButton.Style.Overlay.Border = new Rectangle(5, 5, 5, 5);
126             utilityServiceButton.Style.Text.TextColor = new Selector<Color>
127             {
128                 Normal = new Color(1, 1, 1, 1),
129                 Pressed = new Color(1, 1, 1, 0.7f),
130                 Disabled = new Color(1, 1, 1, 0.4f)
131             };
132
133             utilityServiceButton.Size2D = new Size2D(300, 80);
134             utilityServiceButton.Position2D = new Position2D(XBase, 500);
135             utilityServiceButton.Style.Text.PointSize = 20;
136             utilityServiceButton.Style.Text.Text = "ServiceBasicButton";
137             root.Add(utilityServiceButton);
138             /////////////////////////////////////////////////////////////////////////////////////////////////////////
139             utilityToggleButton = new Button();
140             utilityToggleButton.IsSelectable = true;
141             utilityToggleButton.Style.BackgroundImage = new Selector<string>
142             {
143                 Normal = CommonResource.GetFHResourcePath() + "3. Button/rectangle_toggle_btn_normal.png",
144                 Selected = CommonResource.GetFHResourcePath() + "3. Button/rectangle_point_btn_normal.png",
145             };
146
147             utilityToggleButton.Style.BackgroundImageBorder = new Rectangle(5, 5, 5, 5);
148             utilityToggleButton.Style.Shadow.ResourceUrl = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png";
149             utilityToggleButton.Style.Shadow.Border = new Rectangle(5, 5, 5, 5);
150             utilityToggleButton.Style.Overlay.ResourceUrl = new Selector<string>
151             {
152                 Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
153                 Other = ""
154             };
155             utilityToggleButton.Style.Overlay.Border = new Rectangle(5, 5, 5, 5);
156
157
158             utilityToggleButton.Style.Text.TextColor = new Selector<Color>
159             {
160                 Normal = new Color(0.058f, 0.631f, 0.92f, 1),
161                 Selected = new Color(1, 1, 1, 1),
162             };
163
164             utilityToggleButton.Size2D = new Size2D(300, 80);
165             utilityToggleButton.Position2D = new Position2D(XBase, 700);
166             utilityToggleButton.Style.Text.PointSize = 20;
167             utilityToggleButton.Style.Text.Text = new Selector<string>
168             {
169                 Normal = "Toggle Off",
170                 Selected = "Toggle On"
171             };
172             root.Add(utilityToggleButton);
173             /////////////////////////////////////////////////////////////////////////////////////////////////////////
174             utilityOvalButton = new Button();
175             utilityOvalButton.IsSelectable = true;
176             utilityOvalButton.Style.BackgroundImage = new Selector<string>
177             {
178                 Normal = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_normal.png",
179                 Selected = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_select.png",
180             };
181             utilityOvalButton.Style.BackgroundImageBorder = new Rectangle(5, 5, 5, 5);
182             utilityOvalButton.Style.Shadow.ResourceUrl = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_shadow.png";
183             utilityOvalButton.Style.Shadow.Border = new Rectangle(5, 5, 5, 5);
184             utilityOvalButton.Style.Overlay.ResourceUrl = new Selector<string>
185             {
186                 Pressed = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_press_overlay.png",
187                 Other = ""
188             };
189             utilityOvalButton.Style.Overlay.Border = new Rectangle(5, 5, 5, 5);
190
191             utilityOvalButton.Size2D = new Size2D(104, 104);
192             utilityOvalButton.Position2D = new Position2D(XBase, 900);
193             utilityOvalButton.Style.Text.PointSize = 20;
194             root.Add(utilityOvalButton);
195
196             ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
197             ButtonStyle familyBasicButtonAttributes = new ButtonStyle
198             {
199                 IsSelectable = true,
200                 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png" },
201                 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
202                 Shadow = new ImageViewStyle
203                 {
204                     ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png" },
205                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) }
206                 },
207
208                 Overlay = new ImageViewStyle
209                 {
210                     ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
211                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
212                 },
213
214                 Text = new TextLabelStyle
215                 {
216                     PointSize = new Selector<float?> { All = 20 },
217                     HorizontalAlignment = HorizontalAlignment.Center,
218                     VerticalAlignment = VerticalAlignment.Center,
219                     WidthResizePolicy = ResizePolicyType.FillToParent,
220                     HeightResizePolicy = ResizePolicyType.FillToParent,
221
222                     TextColor = new Selector<Color>
223                     {
224                         Normal = new Color(0, 0, 0, 1),
225                         Pressed = new Color(0, 0, 0, 0.7f),
226                         Selected = new Color(0.141f, 0.769f, 0.278f, 1),
227                         Disabled = new Color(0, 0, 0, 0.4f),
228                     },
229                 }
230             };
231             familyBasicButton = new Button(familyBasicButtonAttributes);
232             familyBasicButton.Size2D = new Size2D(300, 80);
233             familyBasicButton.Position2D = new Position2D(XBase + XPadding, 300);
234             familyBasicButton.Style.Text.PointSize = 20;
235             familyBasicButton.Style.Text.Text = "FamilyBasicButton";
236             root.Add(familyBasicButton);
237
238             //////////////////////////////////////////////////////////////////////////////////////////////////
239             ButtonStyle familyServiceButtonAttributes = new ButtonStyle
240             {
241                 IsSelectable = false,
242                 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_point_btn_normal_24c447.png" },
243                 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
244
245                 Shadow = new ImageViewStyle
246                 {
247                     ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png" },
248                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) }
249                 },
250
251                 Overlay = new ImageViewStyle
252                 {
253                     ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
254                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
255                 },
256
257                 Text = new TextLabelStyle
258                 {
259                     PointSize = new Selector<float?> { All = 20 },
260                     HorizontalAlignment = HorizontalAlignment.Center,
261                     VerticalAlignment = VerticalAlignment.Center,
262                     WidthResizePolicy = ResizePolicyType.FillToParent,
263                     HeightResizePolicy = ResizePolicyType.FillToParent,
264
265                     TextColor = new Selector<Color>
266                     {
267                         Normal = new Color(1, 1, 1, 1),
268                         Pressed = new Color(1, 1, 1, 0.7f),
269                         Disabled = new Color(1, 1, 1, 0.4f),
270                     },
271                 }
272             };
273             familyServiceButton = new Button(familyServiceButtonAttributes);
274             familyServiceButton.Size2D = new Size2D(300, 80);
275             familyServiceButton.Position2D = new Position2D(XBase + XPadding, 500);
276             familyServiceButton.Style.Text.PointSize = 20;
277             familyServiceButton.Style.Text.Text = "FamilySeviceButton";
278             root.Add(familyServiceButton);
279             //////////////////////////////////////////////////////////////////////////////////////////////////
280             ButtonStyle familyToggleButtonAttributes = new ButtonStyle
281             {
282                 IsSelectable = true,
283                 BackgroundImage = new Selector<string>
284                 {
285                     Normal = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_toggle_btn_normal_24c447.png",
286                     Selected = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_point_btn_normal_24c447.png",
287                 },
288                 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
289
290                 Shadow = new ImageViewStyle
291                 {
292                     ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png" },
293                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) }
294                 },
295
296                 Overlay = new ImageViewStyle
297                 {
298                     ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
299                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
300                 },
301
302                 Text = new TextLabelStyle
303                 {
304                     PointSize = new Selector<float?> { All = 20 },
305                     HorizontalAlignment = HorizontalAlignment.Center,
306                     VerticalAlignment = VerticalAlignment.Center,
307                     WidthResizePolicy = ResizePolicyType.FillToParent,
308                     HeightResizePolicy = ResizePolicyType.FillToParent,
309
310                     TextColor = new Selector<Color>
311                     {
312                         Normal = new Color(0.141f, 0.769f, 0.278f, 1),
313                         Selected = new Color(1, 1, 1, 1),
314                     },
315                 }
316             };
317             familyToggleButton = new Button(familyToggleButtonAttributes);
318             familyToggleButton.Size2D = new Size2D(300, 80);
319             familyToggleButton.Position2D = new Position2D(XBase + XPadding, 700);
320             familyToggleButton.Style.Text.PointSize = 20;
321             familyToggleButton.Style.Text.Text = new Selector<string>
322             {
323                 Normal = "Toggle Off",
324                 Selected = "Toggle On"
325             };
326             root.Add(familyToggleButton);
327             //////////////////////////////////////////////////////////////////////////////////////////////////
328             ButtonStyle familyOvalButtonAttributes = new ButtonStyle
329             {
330                 IsSelectable = true,
331                 BackgroundImage = new Selector<string>
332                 {
333                     Normal = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_normal.png",
334                     Selected = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/oval_toggle_btn_select_24c447.png",
335                 },
336                 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
337
338                 Shadow = new ImageViewStyle
339                 {
340                     ResourceUrl = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_shadow.png" },
341                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) }
342                 },
343
344                 Overlay = new ImageViewStyle
345                 {
346                     ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_press_overlay.png", Other = "" },
347                     Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
348                 },
349             };
350             familyOvalButton = new Button(familyOvalButtonAttributes);
351             familyOvalButton.Size2D = new Size2D(104, 104);
352             familyOvalButton.Position2D = new Position2D(XBase + XPadding, 900);
353             familyOvalButton.Style.Text.PointSize = 20;
354             root.Add(familyOvalButton);
355         }
356
357         private void Window_KeyEvent(object sender, Window.KeyEventArgs e)
358         {
359             if(e.Key.State == Key.StateType.Up)
360             {
361                 switch(e.Key.KeyPressedName)
362                 {
363                     case "1":
364                         iconTextButton.IconRelativeOrientation = Button.IconOrientation.Right;
365                         break;
366                     case "2":
367                         iconTextButton.IconRelativeOrientation = Button.IconOrientation.Top;
368                         break;
369                     case "3":
370                         iconTextButton.IconRelativeOrientation = Button.IconOrientation.Bottom;
371                         break;
372                     case "4":
373                         iconTextButton.IconRelativeOrientation = Button.IconOrientation.Left;
374                         break;
375                     case "5":
376                         iconTextButton.Style.Icon.Padding.Start = 50;
377                         break;
378                     case "6":
379                         iconTextButton.Style.Icon.Padding.End = 50;
380                         break;
381                     case "7":
382                         iconTextButton.LayoutDirection = ViewLayoutDirectionType.RTL;
383                         break;
384                     case "8":
385                         iconTextButton.LayoutDirection = ViewLayoutDirectionType.LTR;
386                         break;
387                 }
388             }
389         }
390
391         public void Deactivate()
392         {
393             if (root != null)
394             {
395                 Window.Instance.Remove(root);
396                 root.Dispose();
397             }
398         }
399     }
400 }