[NUI] propose Slider's key navigation and edit mode, Add more samples in StyleGuilde
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.StyleGuide / Examples / SwitchExample.cs
1 /*
2  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19 using Tizen.NUI;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Components;
22
23 namespace Tizen.NUI.StyleGuide
24 {
25     // IExample inehrited class will be automatically added in the main examples list.
26     internal class SwitchExample : ContentPage, IExample
27     {
28         private View rootContent;
29         private Switch[] switchTest = new Switch[4];
30         private string path;
31
32         public void Activate()
33         {
34         }
35         public void Deactivate()
36         {
37         }
38
39         /// Modify this method for adding other examples.
40         public SwitchExample() : base()
41         {
42             Log.Info(this.GetType().Name, $"{this.GetType().Name} is contructed\n");
43
44             WidthSpecification = LayoutParamPolicies.MatchParent;
45             HeightSpecification = LayoutParamPolicies.MatchParent;
46             // Navigator bar title is added here.
47             AppBar = new AppBar()
48             {
49                 Title = "Switch Default Style",
50             };
51
52             // Example root content view.
53             // you can decorate, add children on this view.
54             rootContent = new View()
55             {
56                 WidthSpecification = LayoutParamPolicies.MatchParent,
57                 HeightSpecification = LayoutParamPolicies.MatchParent,
58
59                 Layout = new LinearLayout()
60                 {
61                     LinearOrientation = LinearLayout.Orientation.Vertical,
62                     HorizontalAlignment = HorizontalAlignment.Center,
63                     VerticalAlignment = VerticalAlignment.Center,
64                     CellPadding = new Size2D(10, 20),
65                 },
66             };
67
68             path = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
69
70             CreateSwitchView();
71
72             Content = rootContent;
73         }
74
75         private void CreateSwitchView()
76         {
77             // Create switch styles
78             SwitchStyle styleTest = new SwitchStyle
79             {
80                 Size = new Size(100, 100),
81                 IsSelectable = true,
82                 Track = new ImageViewStyle
83                 {
84                     ResourceUrl = new Selector<string>
85                     {
86                         Normal = path + "/switch/controller_switch_bg_off.png",
87                         Selected = path + "/switch/controller_switch_bg_on.png",
88                         Disabled = path + "/switch/controller_switch_bg_off_dim.png",
89                         DisabledSelected = path + "/switch/controller_switch_bg_on_dim.png",
90                     },
91                     Size = new Size(200, 100),
92                     Border = new Rectangle(30, 30, 30, 30),
93                 },
94                 Thumb = new ImageViewStyle
95                 {
96                     Size = new Size(100, 100),
97                     ResourceUrl = new Selector<string>
98                     {
99                         Normal = path + "/switch/controller_switch_handler.png",
100                         Selected = path + "/switch/controller_switch_handler.png",
101                         Disabled = path + "/switch/controller_switch_handler_dim.png",
102                         DisabledSelected = path + "/switch/controller_switch_handler_dim.png",
103                     },
104                 },
105             };
106
107             // Create by Property
108             for (int i = 0; i < 4; i++)
109             {
110                 switchTest[i] = new Switch();
111                 switchTest[i].ApplyStyle(styleTest);
112                 switchTest[i].Size = new Size(200, 100);
113                 switchTest[i].Margin = new Extents(10, 10, 10, 10);
114                 switchTest[i].Feedback = true;
115                 rootContent.Add(switchTest[i]);
116             }
117             switchTest[2].IsEnabled = false;
118             switchTest[3].IsSelected = true;
119         }
120     }
121 }