[NUI] propose Slider's key navigation and edit mode, Add more samples in StyleGuilde
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.StyleGuide / Examples / RadioButtonExample.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 RadioButtonExample : ContentPage, IExample
27     {
28         private View rootContent;
29         private View left;
30         private View right;
31         private View leftbody;
32         private View rightbody;
33
34         private TextLabel[] createText = new TextLabel[2];
35         private TextLabel[] modeText = new TextLabel[4];
36         private TextLabel[] modeText2 = new TextLabel[4];
37
38         private RadioButton[] utilityRadioButton = new RadioButton[4];
39         private RadioButton[] familyRadioButton = new RadioButton[4];
40         private RadioButton[] foodRadioButton = new RadioButton[4];
41         private RadioButton[] kitchenRadioButton = new RadioButton[4];
42         private RadioButtonGroup[] group = new RadioButtonGroup[4];
43
44         private RadioButton[] utilityRadioButton2 = new RadioButton[4];
45         private RadioButton[] familyRadioButton2 = new RadioButton[4];
46         private RadioButton[] foodRadioButton2 = new RadioButton[4];
47         private RadioButton[] kitchenRadioButton2 = new RadioButton[4];
48         private RadioButtonGroup[] group2 = new RadioButtonGroup[4];
49
50         private static string[] mode = new string[]
51         {
52             "Style A",
53             "Style B",
54             "Style C",
55             "Style D",
56         };
57
58         public void Activate()
59         {
60         }
61         public void Deactivate()
62         {
63         }
64
65         /// Modify this method for adding other examples.
66         public RadioButtonExample() : base()
67         {
68             WidthSpecification = LayoutParamPolicies.MatchParent;
69             HeightSpecification = LayoutParamPolicies.MatchParent;
70
71             // Navigator bar title is added here.
72             AppBar = new AppBar()
73             {
74                 Title = "RadioButton Default Style",
75             };
76
77             var path = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
78
79             // Example root content view.
80             // you can decorate, add children on this view.
81             rootContent = new View()
82             {
83                 WidthSpecification = LayoutParamPolicies.MatchParent,
84                 HeightSpecification = LayoutParamPolicies.MatchParent,
85
86                 Layout = new LinearLayout()
87                 {
88                     LinearOrientation = LinearLayout.Orientation.Vertical,
89                     HorizontalAlignment = HorizontalAlignment.Center,
90                     VerticalAlignment = VerticalAlignment.Center,
91                     CellPadding = new Size2D(10, 20),
92                 },
93             };
94
95             // RadioButton examples.
96             // Create by Property
97             left = new View()
98             {
99                 Weight = 0.5f,
100                 Layout = new LinearLayout()
101                 {
102                     LinearOrientation = LinearLayout.Orientation.Vertical
103                 }
104             };
105
106             //Create left description text.
107             createText[0] = new TextLabel();
108             createText[0].Text = "Create RadioButton just by properties";
109             createText[0].TextColor = Color.White;
110             createText[0].Size = new Size(800, 100);
111             left.Add(createText[0]);
112
113             leftbody = new View();
114             leftbody.Layout = new GridLayout() { Columns = 4 };
115             int num = 4;
116             for (int i = 0; i < num; i++)
117             {
118                 group[i] = new RadioButtonGroup();
119                 modeText[i] = new TextLabel();
120                 modeText[i].Text = mode[i];
121                 modeText[i].Size = new Size(200, 48);
122                 modeText[i].HorizontalAlignment = HorizontalAlignment.Center;
123                 modeText[i].VerticalAlignment = VerticalAlignment.Center;
124                 leftbody.Add(modeText[i]);
125             }
126
127             for (int i = 0; i < num; i++)
128             {
129                 int index = i + 1;
130
131                 // create utility radio button.
132                 utilityRadioButton[i] = new RadioButton();
133                 utilityRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
134                 {
135                     global::System.Console.WriteLine($"Left {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
136                 };
137                 var utilityStyle = utilityRadioButton[i].Style;
138                 utilityStyle.Icon.Opacity = new Selector<float?>
139                 {
140                     Normal = 1.0f,
141                     Selected = 1.0f,
142                     Disabled = 0.4f,
143                     DisabledSelected = 0.4f
144                 };
145                 utilityStyle.Icon.BackgroundImage = "";
146                 utilityStyle.Icon.ResourceUrl = new Selector<string>
147                 {
148                     Normal = path + "/radiobutton/controller_btn_radio_off.png",
149                     Selected = path + "/radiobutton/controller_btn_radio_on.png",
150                     Disabled = path + "/radiobutton/controller_btn_radio_off.png",
151                     DisabledSelected = path + "/radiobutton/controller_btn_radio_on.png",
152                 };
153                 utilityRadioButton[i].ApplyStyle(utilityStyle);
154                 utilityRadioButton[i].Size = new Size(48, 48);
155                 utilityRadioButton[i].Icon.Size = new Size(48, 48);
156                 group[0].Add(utilityRadioButton[i]);
157
158                 // create family radio button.
159                 familyRadioButton[i] = new RadioButton();
160                 familyRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
161                 {
162                     global::System.Console.WriteLine($"Left {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
163                 };
164                 var familyStyle = familyRadioButton[i].Style;
165                 familyStyle.Icon.Opacity = new Selector<float?>
166                 {
167                     Normal = 1.0f,
168                     Selected = 1.0f,
169                     Disabled = 0.4f,
170                     DisabledSelected = 0.4f
171                 };
172                 familyStyle.Icon.BackgroundImage = "";
173                 familyStyle.Icon.ResourceUrl = new Selector<string>
174                 {
175                     Normal = path + "/radiobutton/controller_btn_radio_off.png",
176                     Selected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
177                     Disabled = path + "/radiobutton/controller_btn_radio_off.png",
178                     DisabledSelected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
179                 };
180                 familyRadioButton[i].ApplyStyle(familyStyle);
181                 familyRadioButton[i].Size = new Size(48, 48);
182                 familyRadioButton[i].Icon.Size = new Size(48, 48);
183
184                 group[1].Add(familyRadioButton[i]);
185
186                 // create food radio button.
187                 foodRadioButton[i] = new RadioButton();
188                 foodRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
189                 {
190                     global::System.Console.WriteLine($"Left {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
191                 };
192                 var foodStyle = foodRadioButton[i].Style;
193                 foodStyle.Icon.Opacity = new Selector<float?>
194                 {
195                     Normal = 1.0f,
196                     Selected = 1.0f,
197                     Disabled = 0.4f,
198                     DisabledSelected = 0.4f
199                 };
200                 foodStyle.Icon.BackgroundImage = "";
201                 foodStyle.Icon.ResourceUrl = new Selector<string>
202                 {
203                     Normal = path + "/radiobutton/controller_btn_radio_off.png",
204                     Selected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
205                     Disabled = path + "/radiobutton/controller_btn_radio_off.png",
206                     DisabledSelected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
207                 };
208                 foodRadioButton[i].ApplyStyle(foodStyle);
209                 foodRadioButton[i].Size = new Size(150, 48);
210                 foodRadioButton[i].Icon.Size = new Size(48, 48);
211
212                 group[2].Add(foodRadioButton[i]);
213
214                 // create kitchen radio button.
215                 kitchenRadioButton[i] = new RadioButton();
216                 kitchenRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
217                 {
218                     global::System.Console.WriteLine($"Left {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
219                 };
220                 var kitchenStyle = kitchenRadioButton[i].Style;
221                 kitchenStyle.Icon.Opacity = new Selector<float?>
222                 {
223                     Normal = 1.0f,
224                     Selected = 1.0f,
225                     Disabled = 0.4f,
226                     DisabledSelected = 0.4f
227                 };
228                 kitchenStyle.Icon.BackgroundImage = "";
229                 kitchenStyle.Icon.ResourceUrl = new Selector<string>
230                 {
231                     Normal = path + "/radiobutton/controller_btn_radio_off.png",
232                     Selected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
233                     Disabled = path + "/radiobutton/controller_btn_radio_off.png",
234                     DisabledSelected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
235                 };
236                 kitchenRadioButton[i].ApplyStyle(kitchenStyle);
237                 kitchenRadioButton[i].Size = new Size(48, 48);
238                 kitchenRadioButton[i].Icon.Size = new Size(48, 48);
239
240                 group[3].Add(kitchenRadioButton[i]);
241
242                 leftbody.Add(utilityRadioButton[i]);
243                 leftbody.Add(familyRadioButton[i]);
244                 leftbody.Add(foodRadioButton[i]);
245                 leftbody.Add(kitchenRadioButton[i]);
246             }
247
248             // Create by Attributes
249             right = new View()
250             {
251                 Weight = 0.5f,
252                 Layout = new LinearLayout()
253                 {
254                     LinearOrientation = LinearLayout.Orientation.Vertical,
255                 }
256             };
257
258             rightbody = new View();
259             rightbody.Layout = new GridLayout() { Columns = 4 };
260             createText[1] = new TextLabel();
261             createText[1].Text = "Create RadioButton just by styles";
262             createText[1].TextColor = Color.White;
263             createText[1].Size = new Size(800, 100);
264             right.Add(createText[1]);
265
266             for (int i = 0; i < num; i++)
267             {
268                 group2[i] = new RadioButtonGroup();
269                 modeText2[i] = new TextLabel();
270                 modeText2[i].Text = mode[i];
271                 modeText2[i].Size = new Size(200, 48);
272                 modeText2[i].HorizontalAlignment = HorizontalAlignment.Center;
273                 modeText2[i].VerticalAlignment = VerticalAlignment.Center;
274                 rightbody.Add(modeText2[i]);
275             }
276
277             //Create utility style of radio button.
278             ButtonStyle utilityStyle2 = new ButtonStyle
279             {
280                 Icon = new ImageViewStyle
281                 {
282                     Size = new Size(48, 48),
283                     Opacity = new Selector<float?>
284                     {
285                         Normal = 1.0f,
286                         Selected = 1.0f,
287                         Disabled = 0.4f,
288                         DisabledSelected = 0.4f
289                     },
290                     ResourceUrl = new Selector<string>
291                     {
292                         Normal = path + "/radiobutton/controller_btn_radio_off.png",
293                         Selected = path + "/radiobutton/controller_btn_radio_on.png",
294                         Disabled = path + "/radiobutton/controller_btn_radio_off.png",
295                         DisabledSelected = path + "/radiobutton/controller_btn_radio_on.png",
296                     },
297                 },
298             };
299             //Create family style of radio button.
300             ButtonStyle familyStyle2 = new ButtonStyle
301             {
302                 Icon = new ImageViewStyle
303                 {
304                     Size = new Size(48, 48),
305                     Opacity = new Selector<float?>
306                     {
307                         Normal = 1.0f,
308                         Selected = 1.0f,
309                         Disabled = 0.4f,
310                         DisabledSelected = 0.4f
311                     },
312                     ResourceUrl = new Selector<string>
313                     {
314                         Normal = path + "/radiobutton/controller_btn_radio_off.png",
315                         Selected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
316                         Disabled = path + "/radiobutton/controller_btn_radio_off.png",
317                         DisabledSelected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_24c447.png",
318                     },
319                 },
320             };
321             //Create food style of radio button.
322             ButtonStyle foodStyle2 = new ButtonStyle
323             {
324                 Icon = new ImageViewStyle
325                 {
326                     Size = new Size(48, 48),
327                     Opacity = new Selector<float?>
328                     {
329                         Normal = 1.0f,
330                         Selected = 1.0f,
331                         Disabled = 0.4f,
332                         DisabledSelected = 0.4f
333                     },
334                     ResourceUrl = new Selector<string>
335                     {
336                         Normal = path + "/radiobutton/controller_btn_radio_off.png",
337                         Selected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
338                         Disabled = path + "/radiobutton/controller_btn_radio_off.png",
339                         DisabledSelected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_ec7510.png",
340                     },
341                 },
342             };
343             //Create kitchen style of radio button.
344             ButtonStyle kitchenStyle2 = new ButtonStyle
345             {
346                 Icon = new ImageViewStyle
347                 {
348                     Size = new Size(48, 48),
349                     Opacity = new Selector<float?>
350                     {
351                         Normal = 1.0f,
352                         Selected = 1.0f,
353                         Disabled = 0.4f,
354                         DisabledSelected = 0.4f
355                     },
356                     ResourceUrl = new Selector<string>
357                     {
358                         Normal = path + "/radiobutton/controller_btn_radio_off.png",
359                         Selected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
360                         Disabled = path + "/radiobutton/controller_btn_radio_off.png",
361                         DisabledSelected = path + "/radiobutton/[Controller] App Primary Color/controller_btn_radio_on_9762d9.png",
362                     },
363                 },
364             };
365             for (int i = 0; i < num; i++)
366             {
367                 int index = i + 1;
368
369                 utilityRadioButton2[i] = new RadioButton(utilityStyle2);
370                 utilityRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
371                 {
372                     global::System.Console.WriteLine($"Right {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
373                 };
374                 utilityRadioButton2[i].Size = new Size(48, 48);
375                 group2[0].Add(utilityRadioButton2[i]);
376
377                 familyRadioButton2[i] = new RadioButton(familyStyle2);
378                 familyRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
379                 {
380                     global::System.Console.WriteLine($"Right {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
381                 };
382                 familyRadioButton2[i].Size = new Size(48, 48);
383                 group2[1].Add(familyRadioButton2[i]);
384
385                 foodRadioButton2[i] = new RadioButton(foodStyle2);
386                 foodRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
387                 {
388                     global::System.Console.WriteLine($"Right {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
389                 };
390                 foodRadioButton2[i].Size = new Size(48, 48);
391                 group2[2].Add(foodRadioButton2[i]);
392
393                 kitchenRadioButton2[i] = new RadioButton(kitchenStyle2);
394                 kitchenRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
395                 {
396                     global::System.Console.WriteLine($"Right {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
397                 };
398                 kitchenRadioButton2[i].Size = new Size(48, 48);
399                 group2[3].Add(kitchenRadioButton2[i]);
400
401                 rightbody.Add(utilityRadioButton2[i]);
402                 rightbody.Add(familyRadioButton2[i]);
403                 rightbody.Add(foodRadioButton2[i]);
404                 rightbody.Add(kitchenRadioButton2[i]);
405             }
406
407             rootContent.Add(left);
408             rootContent.Add(right);
409             left.Add(leftbody);
410             right.Add(rightbody);
411
412             utilityRadioButton[2].IsEnabled = false;
413             familyRadioButton[2].IsEnabled = false;
414             foodRadioButton[2].IsEnabled = false;
415             kitchenRadioButton[2].IsEnabled = false;
416
417             utilityRadioButton2[2].IsEnabled = false;
418             familyRadioButton2[2].IsEnabled = false;
419             foodRadioButton2[2].IsEnabled = false;
420             kitchenRadioButton2[2].IsEnabled = false;
421
422             utilityRadioButton[3].IsEnabled = false;
423             familyRadioButton[3].IsEnabled = false;
424             foodRadioButton[3].IsEnabled = false;
425             kitchenRadioButton[3].IsEnabled = false;
426             utilityRadioButton[3].IsSelected = true;
427             familyRadioButton[3].IsSelected = true;
428             foodRadioButton[3].IsSelected = true;
429             kitchenRadioButton[3].IsSelected = true;
430
431             utilityRadioButton2[3].IsEnabled = false;
432             familyRadioButton2[3].IsEnabled = false;
433             foodRadioButton2[3].IsEnabled = false;
434             kitchenRadioButton2[3].IsEnabled = false;
435             utilityRadioButton2[3].IsSelected = true;
436             familyRadioButton2[3].IsSelected = true;
437             foodRadioButton2[3].IsSelected = true;
438             kitchenRadioButton2[3].IsSelected = true;
439
440             Content = rootContent;
441         }
442     }
443 }