1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
5 namespace Tizen.NUI.Samples
7 public class ButtonSample : IExample
16 Button iconTextButton;
18 Button utilityBasicButton;
19 Button utilityServiceButton;
20 Button utilityToggleButton;
21 Button utilityOvalButton;
23 Button familyBasicButton;
24 Button familyServiceButton;
25 Button familyToggleButton;
26 Button familyOvalButton;
28 public void Activate()
30 Window window = NUIApplication.GetDefaultWindow();
33 Size = new Size(1920, 1080),
34 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
35 Layout = new LinearLayout()
37 LinearAlignment = LinearLayout.Alignment.Center,
38 LinearOrientation = LinearLayout.Orientation.Horizontal,
39 CellPadding = new Size(50, 50),
43 window.KeyEvent += Window_KeyEvent;
47 Size = new Size(300, 900),
48 Layout = new LinearLayout()
50 LinearAlignment = LinearLayout.Alignment.Top,
51 LinearOrientation = LinearLayout.Orientation.Vertical,
52 CellPadding = new Size(50, 50),
58 Size = new Size(300, 900),
59 Layout = new LinearLayout()
61 LinearAlignment = LinearLayout.Alignment.Top,
62 LinearOrientation = LinearLayout.Orientation.Vertical,
63 CellPadding = new Size(50, 50),
67 // Only show a text button.
68 textButton = new Button();
69 textButton.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
70 textButton.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
71 textButton.Size = new Size(300, 80);
72 textButton.TextLabel.Text = "Button";
73 parent1.Add(textButton);
75 //Only show an icon button.
76 iconButton = new Button();
78 iconButton.Name = "IconButton";
79 iconButton.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
80 iconButton.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
81 iconButton.Size = new Size(80, 80);
82 iconButton.Icon.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_radiobutton/c_radiobutton_white_check.png";
83 parent2.Add(iconButton);
84 iconButton.Clicked += (ojb, e) => {
85 var btn = iconButton.Icon.GetParent() as Button;
86 string name = btn.Name;
91 Size = new Size(600, 400),
92 Layout = new LinearLayout()
94 LinearAlignment = LinearLayout.Alignment.Top,
95 LinearOrientation = LinearLayout.Orientation.Vertical,
96 CellPadding = new Size(50, 50),
100 //Show a button with icon and text.
101 iconTextButton = new Button();
102 iconTextButton.Text = "IconTextButton";
103 iconTextButton.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
104 iconTextButton.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
105 iconTextButton.IconRelativeOrientation = Button.IconOrientation.Left;
106 iconTextButton.Icon.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_radiobutton/c_radiobutton_white_check.png";
107 iconTextButton.IconPadding = new Extents(20, 20, 20, 20);
108 iconTextButton.TextPadding = new Extents(20, 50, 20, 20);
109 iconTextButton.Size = new Size(500, 300);
110 parent3.Add(iconTextButton);
112 ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
113 //Create utility basic style of button.
114 var utilityBasicButtonStyle = new ButtonStyle()
116 Overlay = new ImageViewStyle()
118 ResourceUrl = new Selector<string>
120 Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
123 Border = new Rectangle(5, 5, 5, 5)
125 Text = new TextLabelStyle()
127 TextColor = new Selector<Color>
129 Normal = new Color(0, 0, 0, 1),
130 Pressed = new Color(0, 0, 0, 0.7f),
131 Selected = new Color(0.058f, 0.631f, 0.92f, 1),
132 Disabled = new Color(0, 0, 0, 0.4f)
134 Text = "UtilityBasicButton",
137 BackgroundImage = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png",
138 BackgroundImageBorder = new Rectangle(5, 5, 5, 5),
140 utilityBasicButton = new Button();
141 utilityBasicButton.ApplyStyle(utilityBasicButtonStyle);
142 utilityBasicButton.IsSelectable = true;
143 utilityBasicButton.ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5));
144 utilityBasicButton.Size = new Size(300, 80);
145 utilityBasicButton.IsEnabled = false;
146 parent1.Add(utilityBasicButton);
148 //Create utility service style of button.
149 var utilityServiceButtonStyle = new ButtonStyle()
151 Overlay = new ImageViewStyle()
153 ResourceUrl = new Selector<string>
155 Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
158 Border = new Rectangle(5, 5, 5, 5)
160 Text = new TextLabelStyle()
162 TextColor = new Selector<Color>
164 Normal = new Color(1, 1, 1, 1),
165 Pressed = new Color(1, 1, 1, 0.7f),
166 Disabled = new Color(1, 1, 1, 0.4f)
168 Text = "ServiceBasicButton",
171 BackgroundImage = CommonResource.GetFHResourcePath() + "3. Button/rectangle_point_btn_normal.png",
172 BackgroundImageBorder = new Rectangle(5, 5, 5, 5)
174 utilityServiceButton = new Button();
175 utilityServiceButton.ApplyStyle(utilityServiceButtonStyle);
176 utilityServiceButton.ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5));
178 utilityServiceButton.Size = new Size(300, 80);
179 parent1.Add(utilityServiceButton);
181 //Create utility toggle style of button.
182 var utilityToggleButtonStyle = new ButtonStyle()
184 BackgroundImage = new Selector<string>
186 Normal = CommonResource.GetFHResourcePath() + "3. Button/rectangle_toggle_btn_normal.png",
187 Selected = CommonResource.GetFHResourcePath() + "3. Button/rectangle_point_btn_normal.png",
189 Overlay = new ImageViewStyle()
191 ResourceUrl = new Selector<string>
193 Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
197 Text = new TextLabelStyle()
199 TextColor = new Selector<Color>
201 Normal = new Color(0.058f, 0.631f, 0.92f, 1),
202 Selected = new Color(1, 1, 1, 1),
204 Text = new Selector<string>
206 Normal = "Toggle Off",
207 Selected = "Toggle On"
211 BackgroundColor = new Selector<Color>()
213 utilityToggleButton = new Button();
214 utilityToggleButton.ApplyStyle(utilityToggleButtonStyle);
215 utilityToggleButton.IsSelectable = true;
216 utilityToggleButton.BackgroundImageBorder = new Rectangle(5, 5, 5, 5);
217 utilityToggleButton.ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5));
218 utilityToggleButton.OverlayImage.Border = new Rectangle(5, 5, 5, 5);
220 utilityToggleButton.Size = new Size(300, 80);
221 parent1.Add(utilityToggleButton);
223 //Create utility oval style of button.
224 var utilityOvalButtonStyle = new ButtonStyle()
226 BackgroundImage = new Selector<string>
228 Normal = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_normal.png",
229 Selected = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_select.png",
231 Overlay = new ImageViewStyle()
233 ResourceUrl = new Selector<string>
235 Pressed = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_press_overlay.png",
239 Text = new TextLabelStyle()
243 BackgroundColor = new Selector<Color>(),
245 utilityOvalButton = new Button();
246 utilityOvalButton.ApplyStyle(utilityOvalButtonStyle);
247 utilityOvalButton.IsSelectable = true;
248 utilityOvalButton.BackgroundImageBorder = new Rectangle(5, 5, 5, 5);
249 utilityOvalButton.ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_shadow.png", new Rectangle(5, 5, 5, 5));
250 utilityOvalButton.OverlayImage.Border = new Rectangle(5, 5, 5, 5);
252 utilityOvalButton.Size = new Size(104, 104);
253 utilityOvalButton.TextLabel.PointSize = 20;
254 parent1.Add(utilityOvalButton);
256 ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
257 //Create family basic style of Button.
258 ButtonStyle familyBasicButtonStyle = new ButtonStyle
261 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png" },
262 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
263 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
265 Overlay = new ImageViewStyle
267 ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
268 Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
271 Text = new TextLabelStyle
273 PointSize = new Selector<float?> { All = 20 },
274 HorizontalAlignment = HorizontalAlignment.Center,
275 VerticalAlignment = VerticalAlignment.Center,
276 WidthResizePolicy = ResizePolicyType.FillToParent,
277 HeightResizePolicy = ResizePolicyType.FillToParent,
279 TextColor = new Selector<Color>
281 Normal = new Color(0, 0, 0, 1),
282 Pressed = new Color(0, 0, 0, 0.7f),
283 Selected = new Color(0.141f, 0.769f, 0.278f, 1),
284 Disabled = new Color(0, 0, 0, 0.4f),
286 Text = "FamilyBasicButton",
289 familyBasicButton = new Button(familyBasicButtonStyle);
290 familyBasicButton.Size = new Size(300, 80);
291 parent2.Add(familyBasicButton);
293 //Create family service style of button.
294 ButtonStyle familyServiceButtonStyle = new ButtonStyle
296 IsSelectable = false,
297 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_point_btn_normal_24c447.png" },
298 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
300 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
302 Overlay = new ImageViewStyle
304 ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
305 Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
308 Text = new TextLabelStyle
310 PointSize = new Selector<float?> { All = 20 },
311 HorizontalAlignment = HorizontalAlignment.Center,
312 VerticalAlignment = VerticalAlignment.Center,
313 WidthResizePolicy = ResizePolicyType.FillToParent,
314 HeightResizePolicy = ResizePolicyType.FillToParent,
316 TextColor = new Selector<Color>
318 Normal = new Color(1, 1, 1, 1),
319 Pressed = new Color(1, 1, 1, 0.7f),
320 Disabled = new Color(1, 1, 1, 0.4f),
322 Text = "FamilySeviceButton"
325 familyServiceButton = new Button(familyServiceButtonStyle);
326 familyServiceButton.Size = new Size(300, 80);
327 parent2.Add(familyServiceButton);
329 //Create family toggle style of button.
330 ButtonStyle familyToggleButtonStyle = new ButtonStyle
333 BackgroundImage = new Selector<string>
335 Normal = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_toggle_btn_normal_24c447.png",
336 Selected = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_point_btn_normal_24c447.png",
338 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
340 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
342 Overlay = new ImageViewStyle
344 ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
345 Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
348 Text = new TextLabelStyle
350 PointSize = new Selector<float?> { All = 20 },
351 HorizontalAlignment = HorizontalAlignment.Center,
352 VerticalAlignment = VerticalAlignment.Center,
353 WidthResizePolicy = ResizePolicyType.FillToParent,
354 HeightResizePolicy = ResizePolicyType.FillToParent,
356 TextColor = new Selector<Color>
358 Normal = new Color(0.141f, 0.769f, 0.278f, 1),
359 Selected = new Color(1, 1, 1, 1),
361 Text = new Selector<string>
363 Normal = "Toggle Off",
364 Selected = "Toggle On"
368 familyToggleButton = new Button(familyToggleButtonStyle);
369 familyToggleButton.Size = new Size(300, 80);
370 parent2.Add(familyToggleButton);
372 //Create family oval style of button.
373 ButtonStyle familyOvalButtonStyle = new ButtonStyle
376 BackgroundImage = new Selector<string>
378 Normal = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_normal.png",
379 Selected = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/oval_toggle_btn_select_24c447.png",
381 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
383 ImageShadow = new ImageShadow(CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_shadow.png", new Rectangle(5, 5, 5, 5)),
385 Overlay = new ImageViewStyle
387 ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_press_overlay.png", Other = "" },
388 Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
391 familyOvalButton = new Button(familyOvalButtonStyle);
392 familyOvalButton.Size = new Size(104, 104);
393 parent2.Add(familyOvalButton);
395 // Add three layout into root
401 private void Window_KeyEvent(object sender, Window.KeyEventArgs e)
403 if(e.Key.State == Key.StateType.Up)
405 switch(e.Key.KeyPressedName)
408 iconTextButton.IconRelativeOrientation = Button.IconOrientation.Right;
411 iconTextButton.IconRelativeOrientation = Button.IconOrientation.Top;
414 iconTextButton.IconRelativeOrientation = Button.IconOrientation.Bottom;
417 iconTextButton.IconRelativeOrientation = Button.IconOrientation.Left;
420 iconTextButton.Icon.Padding.Start = 50;
423 iconTextButton.Icon.Padding.End = 50;
426 iconTextButton.LayoutDirection = ViewLayoutDirectionType.RTL;
429 iconTextButton.LayoutDirection = ViewLayoutDirectionType.LTR;
435 public void Deactivate()
439 parent1.Remove(textButton);
440 textButton.Dispose();
442 parent1.Remove(utilityBasicButton);
443 utilityBasicButton.Dispose();
444 utilityBasicButton = null;
445 parent1.Remove(utilityServiceButton);
446 utilityServiceButton.Dispose();
447 utilityServiceButton = null;
448 parent1.Remove(utilityToggleButton);
449 utilityToggleButton.Dispose();
450 utilityToggleButton = null;
451 parent1.Remove(utilityOvalButton);
452 utilityOvalButton.Dispose();
453 utilityOvalButton = null;
455 parent1.Remove(familyBasicButton);
456 familyBasicButton.Dispose();
457 familyBasicButton = null;
458 parent1.Remove(familyServiceButton);
459 familyServiceButton.Dispose();
460 familyServiceButton = null;
461 parent1.Remove(familyToggleButton);
462 familyToggleButton.Dispose();
463 familyToggleButton = null;
464 parent1.Remove(familyOvalButton);
465 familyOvalButton.Dispose();
466 familyOvalButton = null;
468 parent3.Remove(iconTextButton);
469 iconTextButton.Dispose();
470 iconTextButton = null;
472 root.Remove(parent1);
476 root.Remove(parent2);
480 root.Remove(parent3);
484 NUIApplication.GetDefaultWindow().Remove(root);