2 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Components;
23 namespace Tizen.NUI.StyleGuide
25 // IExample inehrited class will be automatically added in the main examples list.
26 internal class RadioButtonExample : ContentPage, IExample
28 private View rootContent;
31 private View leftbody;
32 private View rightbody;
34 private TextLabel[] createText = new TextLabel[2];
35 private TextLabel[] modeText = new TextLabel[4];
36 private TextLabel[] modeText2 = new TextLabel[4];
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];
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];
50 private static string[] mode = new string[]
58 public void Activate()
61 public void Deactivate()
65 /// Modify this method for adding other examples.
66 public RadioButtonExample() : base()
68 WidthSpecification = LayoutParamPolicies.MatchParent;
69 HeightSpecification = LayoutParamPolicies.MatchParent;
71 // Navigator bar title is added here.
74 Title = "RadioButton Default Style",
77 var path = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
79 // Example root content view.
80 // you can decorate, add children on this view.
81 rootContent = new View()
83 WidthSpecification = LayoutParamPolicies.MatchParent,
84 HeightSpecification = LayoutParamPolicies.MatchParent,
86 Layout = new LinearLayout()
88 LinearOrientation = LinearLayout.Orientation.Vertical,
89 HorizontalAlignment = HorizontalAlignment.Center,
90 VerticalAlignment = VerticalAlignment.Center,
91 CellPadding = new Size2D(10, 20),
95 // RadioButton examples.
100 Layout = new LinearLayout()
102 LinearOrientation = LinearLayout.Orientation.Vertical
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]);
113 leftbody = new View();
114 leftbody.Layout = new GridLayout() { Columns = 4 };
116 for (int i = 0; i < num; i++)
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]);
127 for (int i = 0; i < num; i++)
131 // create utility radio button.
132 utilityRadioButton[i] = new RadioButton();
133 utilityRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
135 global::System.Console.WriteLine($"Left {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
137 var utilityStyle = utilityRadioButton[i].Style;
138 utilityStyle.Icon.Opacity = new Selector<float?>
143 DisabledSelected = 0.4f
145 utilityStyle.Icon.BackgroundImage = "";
146 utilityStyle.Icon.ResourceUrl = new Selector<string>
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",
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]);
158 // create family radio button.
159 familyRadioButton[i] = new RadioButton();
160 familyRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
162 global::System.Console.WriteLine($"Left {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
164 var familyStyle = familyRadioButton[i].Style;
165 familyStyle.Icon.Opacity = new Selector<float?>
170 DisabledSelected = 0.4f
172 familyStyle.Icon.BackgroundImage = "";
173 familyStyle.Icon.ResourceUrl = new Selector<string>
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",
180 familyRadioButton[i].ApplyStyle(familyStyle);
181 familyRadioButton[i].Size = new Size(48, 48);
182 familyRadioButton[i].Icon.Size = new Size(48, 48);
184 group[1].Add(familyRadioButton[i]);
186 // create food radio button.
187 foodRadioButton[i] = new RadioButton();
188 foodRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
190 global::System.Console.WriteLine($"Left {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
192 var foodStyle = foodRadioButton[i].Style;
193 foodStyle.Icon.Opacity = new Selector<float?>
198 DisabledSelected = 0.4f
200 foodStyle.Icon.BackgroundImage = "";
201 foodStyle.Icon.ResourceUrl = new Selector<string>
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",
208 foodRadioButton[i].ApplyStyle(foodStyle);
209 foodRadioButton[i].Size = new Size(150, 48);
210 foodRadioButton[i].Icon.Size = new Size(48, 48);
212 group[2].Add(foodRadioButton[i]);
214 // create kitchen radio button.
215 kitchenRadioButton[i] = new RadioButton();
216 kitchenRadioButton[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
218 global::System.Console.WriteLine($"Left {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
220 var kitchenStyle = kitchenRadioButton[i].Style;
221 kitchenStyle.Icon.Opacity = new Selector<float?>
226 DisabledSelected = 0.4f
228 kitchenStyle.Icon.BackgroundImage = "";
229 kitchenStyle.Icon.ResourceUrl = new Selector<string>
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",
236 kitchenRadioButton[i].ApplyStyle(kitchenStyle);
237 kitchenRadioButton[i].Size = new Size(48, 48);
238 kitchenRadioButton[i].Icon.Size = new Size(48, 48);
240 group[3].Add(kitchenRadioButton[i]);
242 leftbody.Add(utilityRadioButton[i]);
243 leftbody.Add(familyRadioButton[i]);
244 leftbody.Add(foodRadioButton[i]);
245 leftbody.Add(kitchenRadioButton[i]);
248 // Create by Attributes
252 Layout = new LinearLayout()
254 LinearOrientation = LinearLayout.Orientation.Vertical,
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]);
266 for (int i = 0; i < num; i++)
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]);
277 //Create utility style of radio button.
278 ButtonStyle utilityStyle2 = new ButtonStyle
280 Icon = new ImageViewStyle
282 Size = new Size(48, 48),
283 Opacity = new Selector<float?>
288 DisabledSelected = 0.4f
290 ResourceUrl = new Selector<string>
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",
299 //Create family style of radio button.
300 ButtonStyle familyStyle2 = new ButtonStyle
302 Icon = new ImageViewStyle
304 Size = new Size(48, 48),
305 Opacity = new Selector<float?>
310 DisabledSelected = 0.4f
312 ResourceUrl = new Selector<string>
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",
321 //Create food style of radio button.
322 ButtonStyle foodStyle2 = new ButtonStyle
324 Icon = new ImageViewStyle
326 Size = new Size(48, 48),
327 Opacity = new Selector<float?>
332 DisabledSelected = 0.4f
334 ResourceUrl = new Selector<string>
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",
343 //Create kitchen style of radio button.
344 ButtonStyle kitchenStyle2 = new ButtonStyle
346 Icon = new ImageViewStyle
348 Size = new Size(48, 48),
349 Opacity = new Selector<float?>
354 DisabledSelected = 0.4f
356 ResourceUrl = new Selector<string>
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",
365 for (int i = 0; i < num; i++)
369 utilityRadioButton2[i] = new RadioButton(utilityStyle2);
370 utilityRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
372 global::System.Console.WriteLine($"Right {index}th Utility RadioButton's IsSelected is changed to {args.IsSelected}.");
374 utilityRadioButton2[i].Size = new Size(48, 48);
375 group2[0].Add(utilityRadioButton2[i]);
377 familyRadioButton2[i] = new RadioButton(familyStyle2);
378 familyRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
380 global::System.Console.WriteLine($"Right {index}th Family RadioButton's IsSelected is changed to {args.IsSelected}.");
382 familyRadioButton2[i].Size = new Size(48, 48);
383 group2[1].Add(familyRadioButton2[i]);
385 foodRadioButton2[i] = new RadioButton(foodStyle2);
386 foodRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
388 global::System.Console.WriteLine($"Right {index}th Food RadioButton's IsSelected is changed to {args.IsSelected}.");
390 foodRadioButton2[i].Size = new Size(48, 48);
391 group2[2].Add(foodRadioButton2[i]);
393 kitchenRadioButton2[i] = new RadioButton(kitchenStyle2);
394 kitchenRadioButton2[i].SelectedChanged += (object sender, SelectedChangedEventArgs args) =>
396 global::System.Console.WriteLine($"Right {index}th Kitchen RadioButton's IsSelected is changed to {args.IsSelected}.");
398 kitchenRadioButton2[i].Size = new Size(48, 48);
399 group2[3].Add(kitchenRadioButton2[i]);
401 rightbody.Add(utilityRadioButton2[i]);
402 rightbody.Add(familyRadioButton2[i]);
403 rightbody.Add(foodRadioButton2[i]);
404 rightbody.Add(kitchenRadioButton2[i]);
407 rootContent.Add(left);
408 rootContent.Add(right);
410 right.Add(rightbody);
412 utilityRadioButton[2].IsEnabled = false;
413 familyRadioButton[2].IsEnabled = false;
414 foodRadioButton[2].IsEnabled = false;
415 kitchenRadioButton[2].IsEnabled = false;
417 utilityRadioButton2[2].IsEnabled = false;
418 familyRadioButton2[2].IsEnabled = false;
419 foodRadioButton2[2].IsEnabled = false;
420 kitchenRadioButton2[2].IsEnabled = false;
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;
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;
440 Content = rootContent;