2 * Copyright(c) 2019 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;
19 using Tizen.NUI.BaseComponents;
21 namespace Tizen.NUI.Components
24 /// Button is one kind of common component, a button clearly describes what action will occur when the user selects it.
25 /// Button may contain text or an icon.
27 /// <since_tizen> 6 </since_tizen>
28 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public class Button : Control
32 private ImageView backgroundImage;
33 private ImageView shadowImage;
34 private ImageView overlayImage;
36 private TextLabel buttonText;
37 private ImageView buttonIcon;
39 private ButtonAttributes buttonAttributes;
40 private EventHandler<StateChangeEventArgs> stateChangeHander;
42 private bool isSelected = false;
43 private bool isEnabled = true;
44 private bool isPressed = false;
46 /// Creates a new instance of a Button.
48 /// <since_tizen> 6 </since_tizen>
49 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
50 [EditorBrowsable(EditorBrowsableState.Never)]
51 public Button() : base()
56 /// Creates a new instance of a Button with style.
58 /// <param name="style">Create Button by special style defined in UX.</param>
59 /// <since_tizen> 6 </since_tizen>
60 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
61 [EditorBrowsable(EditorBrowsableState.Never)]
62 public Button(string style) : base(style)
67 /// Creates a new instance of a Button with attributes.
69 /// <param name="attributes">Create Button by attributes customized by user.</param>
70 /// <since_tizen> 6 </since_tizen>
71 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 public Button(ButtonAttributes attributes) : base(attributes)
78 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
80 /// <since_tizen> 6 </since_tizen>
81 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
82 [EditorBrowsable(EditorBrowsableState.Never)]
83 public event EventHandler<ClickEventArgs> ClickEvent;
85 /// An event for the button state changed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
87 /// <since_tizen> 6 </since_tizen>
88 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
89 [EditorBrowsable(EditorBrowsableState.Never)]
90 public event EventHandler<StateChangeEventArgs> StateChangedEvent
94 stateChangeHander += value;
98 stateChangeHander -= value;
102 /// Icon orientation.
104 /// <since_tizen> 6 </since_tizen>
105 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
106 [EditorBrowsable(EditorBrowsableState.Never)]
107 public enum IconOrientation
112 /// <since_tizen> 6 </since_tizen>
113 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
114 [EditorBrowsable(EditorBrowsableState.Never)]
119 /// <since_tizen> 6 </since_tizen>
120 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
121 [EditorBrowsable(EditorBrowsableState.Never)]
126 /// <since_tizen> 6 </since_tizen>
127 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
128 [EditorBrowsable(EditorBrowsableState.Never)]
133 /// <since_tizen> 6 </since_tizen>
134 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
135 [EditorBrowsable(EditorBrowsableState.Never)]
139 /// Flag to decide Button can be selected or not.
141 /// <since_tizen> 6 </since_tizen>
142 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 public bool IsSelectable
148 return buttonAttributes?.IsSelectable ?? false;
152 buttonAttributes.IsSelectable = value;
156 /// Background image's resource url in Button.
158 /// <since_tizen> 6 </since_tizen>
159 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
160 [EditorBrowsable(EditorBrowsableState.Never)]
161 public string BackgroundImageURL
165 return buttonAttributes?.BackgroundImageAttributes?.ResourceURL?.All;
171 CreateBackgroundAttributes();
172 if (buttonAttributes.BackgroundImageAttributes.ResourceURL == null)
174 buttonAttributes.BackgroundImageAttributes.ResourceURL = new StringSelector();
176 buttonAttributes.BackgroundImageAttributes.ResourceURL.All = value;
182 /// Background image's border in Button.
184 /// <since_tizen> 6 </since_tizen>
185 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
186 [EditorBrowsable(EditorBrowsableState.Never)]
187 public Rectangle BackgroundImageBorder
191 return buttonAttributes?.BackgroundImageAttributes?.Border?.All;
197 CreateBackgroundAttributes();
198 if (buttonAttributes.BackgroundImageAttributes.Border == null)
200 buttonAttributes.BackgroundImageAttributes.Border = new RectangleSelector();
202 buttonAttributes.BackgroundImageAttributes.Border.All = value;
208 /// Shadow image's resource url in Button.
210 /// <since_tizen> 6 </since_tizen>
211 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
212 [EditorBrowsable(EditorBrowsableState.Never)]
213 public string ShadowImageURL
217 return buttonAttributes?.ShadowImageAttributes?.ResourceURL?.All;
223 CreateShadowAttributes();
224 if (buttonAttributes.ShadowImageAttributes.ResourceURL == null)
226 buttonAttributes.ShadowImageAttributes.ResourceURL = new StringSelector();
228 buttonAttributes.ShadowImageAttributes.ResourceURL.All = value;
234 /// Shadow image's border in Button.
236 /// <since_tizen> 6 </since_tizen>
237 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
238 [EditorBrowsable(EditorBrowsableState.Never)]
239 public Rectangle ShadowImageBorder
243 return buttonAttributes?.ShadowImageAttributes?.Border?.All;
249 CreateShadowAttributes();
250 if (buttonAttributes.ShadowImageAttributes.Border == null)
252 buttonAttributes.ShadowImageAttributes.Border = new RectangleSelector();
254 buttonAttributes.ShadowImageAttributes.Border.All = value;
260 /// Overlay image's resource url in Button.
262 /// <since_tizen> 6 </since_tizen>
263 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
264 [EditorBrowsable(EditorBrowsableState.Never)]
265 public string OverlayImageURL
269 return buttonAttributes?.OverlayImageAttributes?.ResourceURL?.All;
275 CreateOverlayAttributes();
276 if (buttonAttributes.OverlayImageAttributes.ResourceURL == null)
278 buttonAttributes.OverlayImageAttributes.ResourceURL = new StringSelector();
280 buttonAttributes.OverlayImageAttributes.ResourceURL.All = value;
286 /// Overlay image's border in Button.
288 /// <since_tizen> 6 </since_tizen>
289 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
290 [EditorBrowsable(EditorBrowsableState.Never)]
291 public Rectangle OverlayImageBorder
295 return buttonAttributes?.OverlayImageAttributes?.Border?.All;
301 CreateOverlayAttributes();
302 if (buttonAttributes.OverlayImageAttributes.Border == null)
304 buttonAttributes.OverlayImageAttributes.Border = new RectangleSelector();
306 buttonAttributes.OverlayImageAttributes.Border.All = value;
312 /// Text string in Button.
314 /// <since_tizen> 6 </since_tizen>
315 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
316 [EditorBrowsable(EditorBrowsableState.Never)]
321 return buttonAttributes?.TextAttributes?.Text?.All;
327 CreateTextAttributes();
328 if(buttonAttributes.TextAttributes.Text == null)
330 buttonAttributes.TextAttributes.Text = new StringSelector();
332 buttonAttributes.TextAttributes.Text.All = value;
339 /// Translate text string in Button.
341 /// <since_tizen> 6 </since_tizen>
342 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
343 [EditorBrowsable(EditorBrowsableState.Never)]
344 public string TranslatableText
348 return buttonAttributes?.TextAttributes?.TranslatableText?.All;
354 CreateTextAttributes();
355 if (buttonAttributes.TextAttributes.TranslatableText == null)
357 buttonAttributes.TextAttributes.TranslatableText = new StringSelector();
359 buttonAttributes.TextAttributes.TranslatableText.All = value;
366 /// Text point size in Button.
368 /// <since_tizen> 6 </since_tizen>
369 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
370 [EditorBrowsable(EditorBrowsableState.Never)]
371 public float PointSize
375 return buttonAttributes?.TextAttributes?.PointSize?.All ?? 0;
379 CreateTextAttributes();
380 if (buttonAttributes.TextAttributes.PointSize == null)
382 buttonAttributes.TextAttributes.PointSize = new FloatSelector();
384 buttonAttributes.TextAttributes.PointSize.All = value;
389 /// Text font family in Button.
391 /// <since_tizen> 6 </since_tizen>
392 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
393 [EditorBrowsable(EditorBrowsableState.Never)]
394 public string FontFamily
398 return buttonAttributes?.TextAttributes?.FontFamily;
402 CreateTextAttributes();
403 buttonAttributes.TextAttributes.FontFamily = value;
408 /// Text color in Button.
410 /// <since_tizen> 6 </since_tizen>
411 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
412 [EditorBrowsable(EditorBrowsableState.Never)]
413 public Color TextColor
417 return buttonAttributes?.TextAttributes?.TextColor?.All;
421 CreateTextAttributes();
422 if (buttonAttributes.TextAttributes.TextColor == null)
424 buttonAttributes.TextAttributes.TextColor = new ColorSelector();
426 buttonAttributes.TextAttributes.TextColor.All = value;
431 /// Text horizontal alignment in Button.
433 /// <since_tizen> 6 </since_tizen>
434 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
435 [EditorBrowsable(EditorBrowsableState.Never)]
436 public HorizontalAlignment TextAlignment
440 return buttonAttributes?.TextAttributes?.HorizontalAlignment ?? HorizontalAlignment.Center;
444 CreateTextAttributes();
445 buttonAttributes.TextAttributes.HorizontalAlignment = value;
450 /// Icon image's resource url in Button.
452 /// <since_tizen> 6 </since_tizen>
453 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
454 [EditorBrowsable(EditorBrowsableState.Never)]
455 public string IconURL
459 return buttonAttributes?.IconAttributes?.ResourceURL?.All;
465 CreateIconAttributes();
466 if (buttonAttributes.IconAttributes.ResourceURL == null)
468 buttonAttributes.IconAttributes.ResourceURL = new StringSelector();
470 buttonAttributes.IconAttributes.ResourceURL.All = value;
476 /// Text string selector in Button.
478 /// <since_tizen> 6 </since_tizen>
479 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
480 [EditorBrowsable(EditorBrowsableState.Never)]
481 public StringSelector TextSelector
485 return buttonAttributes?.TextAttributes?.Text;
491 CreateTextAttributes();
492 buttonAttributes.TextAttributes.Text = value.Clone() as StringSelector;
498 /// Translateable text string selector in Button.
500 /// <since_tizen> 6 </since_tizen>
501 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
502 [EditorBrowsable(EditorBrowsableState.Never)]
503 public StringSelector TranslatableTextSelector
507 return buttonAttributes?.TextAttributes?.TranslatableText;
513 CreateTextAttributes();
514 buttonAttributes.TextAttributes.TranslatableText = value.Clone() as StringSelector;
520 /// Text color selector in Button.
522 /// <since_tizen> 6 </since_tizen>
523 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
524 [EditorBrowsable(EditorBrowsableState.Never)]
525 public ColorSelector TextColorSelector
529 return buttonAttributes?.TextAttributes?.TextColor;
535 CreateTextAttributes();
536 buttonAttributes.TextAttributes.TextColor = value.Clone() as ColorSelector;
542 /// Text font size selector in Button.
544 /// <since_tizen> 6 </since_tizen>
545 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
546 [EditorBrowsable(EditorBrowsableState.Never)]
547 public FloatSelector PointSizeSelector
551 return buttonAttributes?.TextAttributes?.PointSize;
557 CreateTextAttributes();
558 buttonAttributes.TextAttributes.PointSize = value.Clone() as FloatSelector;
564 /// Icon image's resource url selector in Button.
566 /// <since_tizen> 6 </since_tizen>
567 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
568 [EditorBrowsable(EditorBrowsableState.Never)]
569 public StringSelector IconURLSelector
573 return buttonAttributes?.IconAttributes?.ResourceURL;
579 CreateIconAttributes();
580 buttonAttributes.IconAttributes.ResourceURL = value.Clone() as StringSelector;
586 /// Background image's resource url selector in Button.
588 /// <since_tizen> 6 </since_tizen>
589 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
590 [EditorBrowsable(EditorBrowsableState.Never)]
591 public StringSelector BackgroundImageURLSelector
595 return buttonAttributes?.BackgroundImageAttributes?.ResourceURL;
601 CreateBackgroundAttributes();
602 buttonAttributes.BackgroundImageAttributes.ResourceURL = value.Clone() as StringSelector;
608 /// Background image's border selector in Button.
610 /// <since_tizen> 6 </since_tizen>
611 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
612 [EditorBrowsable(EditorBrowsableState.Never)]
613 public RectangleSelector BackgroundImageBorderSelector
617 return buttonAttributes?.BackgroundImageAttributes?.Border;
623 CreateBackgroundAttributes();
624 buttonAttributes.BackgroundImageAttributes.Border = value.Clone() as RectangleSelector;
630 /// Shadow image's resource url selector in Button.
632 /// <since_tizen> 6 </since_tizen>
633 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
634 [EditorBrowsable(EditorBrowsableState.Never)]
635 public StringSelector ShadowImageURLSelector
639 return buttonAttributes?.ShadowImageAttributes?.ResourceURL;
645 CreateShadowAttributes();
646 buttonAttributes.ShadowImageAttributes.ResourceURL = value.Clone() as StringSelector;
652 /// Shadow image's border selector in Button.
654 /// <since_tizen> 6 </since_tizen>
655 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
656 [EditorBrowsable(EditorBrowsableState.Never)]
657 public RectangleSelector ShadowImageBorderSelector
661 return buttonAttributes?.ShadowImageAttributes?.Border;
667 CreateShadowAttributes();
668 buttonAttributes.ShadowImageAttributes.Border = value.Clone() as RectangleSelector;
674 /// Overlay image's resource url selector in Button.
676 /// <since_tizen> 6 </since_tizen>
677 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
678 [EditorBrowsable(EditorBrowsableState.Never)]
679 public StringSelector OverlayImageURLSelector
683 return buttonAttributes?.OverlayImageAttributes?.ResourceURL;
689 CreateOverlayAttributes();
690 buttonAttributes.OverlayImageAttributes.ResourceURL = value.Clone() as StringSelector;
696 /// Overlay image's border selector in Button.
698 /// <since_tizen> 6 </since_tizen>
699 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
700 [EditorBrowsable(EditorBrowsableState.Never)]
701 public RectangleSelector OverlayImageBorderSelector
705 return buttonAttributes?.OverlayImageAttributes?.Border;
711 CreateOverlayAttributes();
712 buttonAttributes.OverlayImageAttributes.Border = value.Clone() as RectangleSelector;
718 /// Flag to decide selected state in Button.
720 /// <since_tizen> 6 </since_tizen>
721 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
722 [EditorBrowsable(EditorBrowsableState.Never)]
723 public bool IsSelected
736 /// Flag to decide enable or disable in Button.
738 /// <since_tizen> 6 </since_tizen>
739 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
740 [EditorBrowsable(EditorBrowsableState.Never)]
741 public bool IsEnabled
755 /// Icon relative orientation in Button, work only when show icon and text.
757 /// <since_tizen> 6 </since_tizen>
758 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
759 [EditorBrowsable(EditorBrowsableState.Never)]
760 public IconOrientation? IconRelativeOrientation
764 return buttonAttributes?.IconRelativeOrientation;
768 if(buttonAttributes != null && buttonAttributes.IconRelativeOrientation != value)
770 buttonAttributes.IconRelativeOrientation = value;
777 /// Icon left padding in Button, work only when show icon and text.
779 /// <since_tizen> 6 </since_tizen>
780 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
781 [EditorBrowsable(EditorBrowsableState.Never)]
782 public int IconPaddingLeft
786 return buttonAttributes?.IconAttributes?.PaddingLeft ?? 0;
790 CreateIconAttributes();
791 buttonAttributes.IconAttributes.PaddingLeft = value;
797 /// Icon right padding in Button, work only when show icon and text.
799 /// <since_tizen> 6 </since_tizen>
800 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
801 [EditorBrowsable(EditorBrowsableState.Never)]
802 public int IconPaddingRight
806 return buttonAttributes?.IconAttributes?.PaddingRight ?? 0;
810 CreateIconAttributes();
811 buttonAttributes.IconAttributes.PaddingRight = value;
817 /// Icon top padding in Button, work only when show icon and text.
819 /// <since_tizen> 6 </since_tizen>
820 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
821 [EditorBrowsable(EditorBrowsableState.Never)]
822 public int IconPaddingTop
826 return buttonAttributes?.IconAttributes?.PaddingTop ?? 0;
830 CreateIconAttributes();
831 buttonAttributes.IconAttributes.PaddingTop = value;
837 /// Icon bottom padding in Button, work only when show icon and text.
839 /// <since_tizen> 6 </since_tizen>
840 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
841 [EditorBrowsable(EditorBrowsableState.Never)]
842 public int IconPaddingBottom
846 return buttonAttributes?.IconAttributes?.PaddingBottom ?? 0;
850 CreateIconAttributes();
851 buttonAttributes.IconAttributes.PaddingBottom = value;
857 /// Text left padding in Button, work only when show icon and text.
859 /// <since_tizen> 6 </since_tizen>
860 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
861 [EditorBrowsable(EditorBrowsableState.Never)]
862 public int TextPaddingLeft
866 return buttonAttributes?.TextAttributes?.PaddingLeft ?? 0;
870 CreateTextAttributes();
871 buttonAttributes.TextAttributes.PaddingLeft = value;
877 /// Text right padding in Button, work only when show icon and text.
879 /// <since_tizen> 6 </since_tizen>
880 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
881 [EditorBrowsable(EditorBrowsableState.Never)]
882 public int TextPaddingRight
886 return buttonAttributes?.TextAttributes?.PaddingRight ?? 0;
890 CreateTextAttributes();
891 buttonAttributes.TextAttributes.PaddingRight = value;
897 /// Text top padding in Button, work only when show icon and text.
899 /// <since_tizen> 6 </since_tizen>
900 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
901 [EditorBrowsable(EditorBrowsableState.Never)]
902 public int TextPaddingTop
906 return buttonAttributes?.TextAttributes?.PaddingTop ?? 0;
910 CreateTextAttributes();
911 buttonAttributes.TextAttributes.PaddingTop = value;
917 /// Text bottom padding in Button, work only when show icon and text.
919 /// <since_tizen> 6 </since_tizen>
920 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
921 [EditorBrowsable(EditorBrowsableState.Never)]
922 public int TextPaddingBottom
926 return buttonAttributes?.TextAttributes?.PaddingBottom ?? 0;
930 CreateTextAttributes();
931 buttonAttributes.TextAttributes.PaddingBottom = value;
936 /// Dispose Button and all children on it.
938 /// <param name="type">Dispose type.</param>
939 /// <since_tizen> 6 </since_tizen>
940 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
941 [EditorBrowsable(EditorBrowsableState.Never)]
942 protected override void Dispose(DisposeTypes type)
949 if (type == DisposeTypes.Explicit)
951 if (buttonIcon != null)
953 buttonIcon.Relayout -= OnIconRelayout;
954 Utility.Dispose(buttonIcon);
956 if (buttonText != null)
958 Utility.Dispose(buttonText);
960 if (overlayImage != null)
962 Utility.Dispose(overlayImage);
964 if (backgroundImage != null)
966 Utility.Dispose(backgroundImage);
968 if (shadowImage != null)
970 Utility.Dispose(shadowImage);
977 /// Called after a key event is received by the view that has had its focus set.
979 /// <param name="key">The key event.</param>
980 /// <returns>True if the key event should be consumed.</returns>
981 /// <since_tizen> 6 </since_tizen>
982 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
983 [EditorBrowsable(EditorBrowsableState.Never)]
984 public override bool OnKey(Key key)
986 if (key.State == Key.StateType.Down)
988 if (key.KeyPressedName == "Return")
994 ClickEventArgs eventArgs = new ClickEventArgs();
999 else if (key.State == Key.StateType.Up)
1001 if (key.KeyPressedName == "Return")
1004 if (buttonAttributes.IsSelectable != null && buttonAttributes.IsSelectable == true)
1006 isSelected = !isSelected;
1011 return base.OnKey(key);
1014 /// Called when the control gain key input focus. Should be overridden by derived classes if they need to customize what happens when the focus is gained.
1016 /// <since_tizen> 6 </since_tizen>
1017 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1018 [EditorBrowsable(EditorBrowsableState.Never)]
1019 public override void OnFocusGained()
1021 base.OnFocusGained();
1025 /// Called when the control loses key input focus. Should be overridden by derived classes if they need to customize what happens when the focus is lost.
1027 /// <since_tizen> 6 </since_tizen>
1028 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1029 [EditorBrowsable(EditorBrowsableState.Never)]
1030 public override void OnFocusLost()
1036 /// Tap gesture event callback.
1038 /// <param name="source">Source which recieved touch event.</param>
1039 /// <param name="e">Tap gesture event argument.</param>
1040 /// <since_tizen> 6 </since_tizen>
1041 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1042 [EditorBrowsable(EditorBrowsableState.Never)]
1043 protected override void OnTapGestureDetected(object source, TapGestureDetector.DetectedEventArgs e)
1047 ClickEventArgs eventArgs = new ClickEventArgs();
1049 base.OnTapGestureDetected(source, e);
1054 /// Called after a touch event is received by the owning view.<br />
1055 /// CustomViewBehaviour.REQUIRES_TOUCH_EVENTS must be enabled during construction. See CustomView(ViewWrapperImpl.CustomViewBehaviour behaviour).<br />
1057 /// <param name="touch">The touch event.</param>
1058 /// <returns>True if the event should be consumed.</returns>
1059 /// <since_tizen> 6 </since_tizen>
1060 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1061 [EditorBrowsable(EditorBrowsableState.Never)]
1062 public override bool OnTouch(Touch touch)
1064 PointStateType state = touch.GetState(0);
1068 case PointStateType.Down:
1072 case PointStateType.Interrupted:
1076 case PointStateType.Up:
1078 if (buttonAttributes.IsSelectable != null && buttonAttributes.IsSelectable == true)
1080 isSelected = !isSelected;
1087 return base.OnTouch(touch);
1090 /// Get Button attribues.
1092 /// <since_tizen> 6 </since_tizen>
1093 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1094 [EditorBrowsable(EditorBrowsableState.Never)]
1095 protected override Attributes GetAttributes()
1097 return new ButtonAttributes();
1100 /// Update Button by attributes.
1102 /// <since_tizen> 6 </since_tizen>
1103 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1104 [EditorBrowsable(EditorBrowsableState.Never)]
1105 protected override void OnUpdate()
1107 if (buttonAttributes.ShadowImageAttributes != null)
1109 if(shadowImage == null)
1111 shadowImage = new ImageView()
1113 WidthResizePolicy = ResizePolicyType.FillToParent,
1114 HeightResizePolicy = ResizePolicyType.FillToParent
1116 this.Add(shadowImage);
1118 ApplyAttributes(shadowImage, buttonAttributes.ShadowImageAttributes);
1121 if (buttonAttributes.BackgroundImageAttributes != null)
1123 if(backgroundImage == null)
1125 backgroundImage = new ImageView()
1127 WidthResizePolicy = ResizePolicyType.FillToParent,
1128 HeightResizePolicy = ResizePolicyType.FillToParent
1130 this.Add(backgroundImage);
1132 ApplyAttributes(backgroundImage, buttonAttributes.BackgroundImageAttributes);
1135 if (buttonAttributes.OverlayImageAttributes != null)
1137 if(overlayImage == null)
1139 overlayImage = new ImageView()
1141 WidthResizePolicy = ResizePolicyType.FillToParent,
1142 HeightResizePolicy = ResizePolicyType.FillToParent
1144 this.Add(overlayImage);
1146 ApplyAttributes(overlayImage, buttonAttributes.OverlayImageAttributes);
1149 if (buttonAttributes.TextAttributes != null)
1151 if(buttonText == null)
1153 buttonText = new TextLabel();
1154 this.Add(buttonText);
1156 ApplyAttributes(buttonText, buttonAttributes.TextAttributes);
1159 if (buttonAttributes.IconAttributes != null)
1161 if(buttonIcon == null)
1163 buttonIcon = new ImageView();
1164 buttonIcon.Relayout += OnIconRelayout;
1165 this.Add(buttonIcon);
1167 ApplyAttributes(buttonIcon, buttonAttributes.IconAttributes);
1173 Sensitive = isEnabled ? true : false;
1177 /// Update Button State.
1179 /// <since_tizen> 6 </since_tizen>
1180 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1181 [EditorBrowsable(EditorBrowsableState.Never)]
1182 protected void UpdateState()
1184 ControlStates sourceState = State;
1185 ControlStates targetState;
1189 targetState = isPressed ? ControlStates.Pressed : (IsFocused ? (IsSelected ? ControlStates.SelectedFocused : ControlStates.Focused) : (IsSelected ? ControlStates.Selected : ControlStates.Normal));
1193 targetState = IsSelected ? ControlStates.DisabledSelected : (IsFocused ? ControlStates.DisabledFocused : ControlStates.Disabled);
1195 if(sourceState != targetState)
1197 State = targetState;
1201 StateChangeEventArgs e = new StateChangeEventArgs
1203 PreviousState = sourceState,
1204 CurrentState = targetState
1206 stateChangeHander?.Invoke(this, e);
1210 /// It is hijack by using protected, attributes copy problem when class inherited from Button.
1212 /// <since_tizen> 6 </since_tizen>
1213 private void Initialize()
1215 buttonAttributes = attributes as ButtonAttributes;
1216 if (buttonAttributes == null)
1218 throw new Exception("Button attribute parse error.");
1221 ApplyAttributes(this, buttonAttributes);
1222 LayoutDirectionChanged += OnLayoutDirectionChanged;
1226 /// Measure text, it can be override.
1228 /// <since_tizen> 6 </since_tizen>
1229 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1230 [EditorBrowsable(EditorBrowsableState.Never)]
1231 protected virtual void MeasureText()
1233 if (buttonAttributes.IconRelativeOrientation == null || buttonIcon == null || buttonText == null)
1237 buttonText.WidthResizePolicy = ResizePolicyType.Fixed;
1238 buttonText.HeightResizePolicy = ResizePolicyType.Fixed;
1239 int textPaddingLeft = buttonAttributes.TextAttributes.PaddingLeft;
1240 int textPaddingRight = buttonAttributes.TextAttributes.PaddingRight;
1241 int textPaddingTop = buttonAttributes.TextAttributes.PaddingTop;
1242 int textPaddingBottom = buttonAttributes.TextAttributes.PaddingBottom;
1244 int iconPaddingLeft = buttonAttributes.IconAttributes.PaddingLeft;
1245 int iconPaddingRight = buttonAttributes.IconAttributes.PaddingRight;
1246 int iconPaddingTop = buttonAttributes.IconAttributes.PaddingTop;
1247 int iconPaddingBottom = buttonAttributes.IconAttributes.PaddingBottom;
1249 if (IconRelativeOrientation == IconOrientation.Top || IconRelativeOrientation == IconOrientation.Bottom)
1251 buttonText.SizeWidth = SizeWidth - textPaddingLeft - textPaddingRight;
1252 buttonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom - iconPaddingTop - iconPaddingBottom - buttonIcon.SizeHeight;
1256 buttonText.SizeWidth = SizeWidth - textPaddingLeft - textPaddingRight - iconPaddingLeft - iconPaddingRight - buttonIcon.SizeWidth;
1257 buttonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom;
1261 /// Layout child, it can be override.
1263 /// <since_tizen> 6 </since_tizen>
1264 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1265 [EditorBrowsable(EditorBrowsableState.Never)]
1266 protected virtual void LayoutChild()
1268 if (buttonAttributes.IconRelativeOrientation == null || buttonIcon == null || buttonText == null)
1273 int textPaddingLeft = buttonAttributes.TextAttributes.PaddingLeft;
1274 int textPaddingRight = buttonAttributes.TextAttributes.PaddingRight;
1275 int textPaddingTop = buttonAttributes.TextAttributes.PaddingTop;
1276 int textPaddingBottom = buttonAttributes.TextAttributes.PaddingBottom;
1278 int iconPaddingLeft = buttonAttributes.IconAttributes.PaddingLeft;
1279 int iconPaddingRight = buttonAttributes.IconAttributes.PaddingRight;
1280 int iconPaddingTop = buttonAttributes.IconAttributes.PaddingTop;
1281 int iconPaddingBottom = buttonAttributes.IconAttributes.PaddingBottom;
1283 switch (IconRelativeOrientation)
1285 case IconOrientation.Top:
1286 buttonIcon.PositionUsesPivotPoint = true;
1287 buttonIcon.ParentOrigin = NUI.ParentOrigin.TopCenter;
1288 buttonIcon.PivotPoint = NUI.PivotPoint.TopCenter;
1289 buttonIcon.Position2D = new Position2D(0, iconPaddingTop);
1291 buttonText.PositionUsesPivotPoint = true;
1292 buttonText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1293 buttonText.PivotPoint = NUI.PivotPoint.BottomCenter;
1294 buttonText.Position2D = new Position2D(0, -textPaddingBottom);
1296 case IconOrientation.Bottom:
1297 buttonIcon.PositionUsesPivotPoint = true;
1298 buttonIcon.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1299 buttonIcon.PivotPoint = NUI.PivotPoint.BottomCenter;
1300 buttonIcon.Position2D = new Position2D(0, -iconPaddingBottom);
1302 buttonText.PositionUsesPivotPoint = true;
1303 buttonText.ParentOrigin = NUI.ParentOrigin.TopCenter;
1304 buttonText.PivotPoint = NUI.PivotPoint.TopCenter;
1305 buttonText.Position2D = new Position2D(0, textPaddingTop);
1307 case IconOrientation.Left:
1308 if (LayoutDirection == ViewLayoutDirectionType.LTR)
1310 buttonIcon.PositionUsesPivotPoint = true;
1311 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1312 buttonIcon.PivotPoint = NUI.PivotPoint.CenterLeft;
1313 buttonIcon.Position2D = new Position2D(iconPaddingLeft, 0);
1315 buttonText.PositionUsesPivotPoint = true;
1316 buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
1317 buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
1318 buttonText.Position2D = new Position2D(-textPaddingRight, 0);
1322 buttonIcon.PositionUsesPivotPoint = true;
1323 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
1324 buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
1325 buttonIcon.Position2D = new Position2D(-iconPaddingLeft, 0);
1327 buttonText.PositionUsesPivotPoint = true;
1328 buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1329 buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
1330 buttonText.Position2D = new Position2D(textPaddingRight, 0);
1334 case IconOrientation.Right:
1335 if (LayoutDirection == ViewLayoutDirectionType.RTL)
1337 buttonIcon.PositionUsesPivotPoint = true;
1338 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1339 buttonIcon.PivotPoint = NUI.PivotPoint.CenterLeft;
1340 buttonIcon.Position2D = new Position2D(iconPaddingRight, 0);
1342 buttonText.PositionUsesPivotPoint = true;
1343 buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
1344 buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
1345 buttonText.Position2D = new Position2D(-textPaddingLeft, 0);
1349 buttonIcon.PositionUsesPivotPoint = true;
1350 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
1351 buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
1352 buttonIcon.Position2D = new Position2D(-iconPaddingRight, 0);
1354 buttonText.PositionUsesPivotPoint = true;
1355 buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1356 buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
1357 buttonText.Position2D = new Position2D(textPaddingLeft, 0);
1365 /// Theme change callback when theme is changed, this callback will be trigger.
1367 /// <since_tizen> 6 </since_tizen>
1368 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1369 [EditorBrowsable(EditorBrowsableState.Never)]
1370 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
1372 ButtonAttributes tempAttributes = StyleManager.Instance.GetAttributes(style) as ButtonAttributes;
1373 if(tempAttributes != null)
1375 attributes = buttonAttributes = tempAttributes;
1380 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
1386 private void OnClick(ClickEventArgs eventArgs)
1388 ClickEvent?.Invoke(this, eventArgs);
1391 private void OnIconRelayout(object sender, EventArgs e)
1397 private void CreateBackgroundAttributes()
1399 if (buttonAttributes.BackgroundImageAttributes == null)
1401 buttonAttributes.BackgroundImageAttributes = new ImageAttributes()
1403 PositionUsesPivotPoint = true,
1404 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
1405 PivotPoint = Tizen.NUI.PivotPoint.Center,
1406 WidthResizePolicy = ResizePolicyType.FillToParent,
1407 HeightResizePolicy = ResizePolicyType.FillToParent
1412 private void CreateShadowAttributes()
1414 if (buttonAttributes.ShadowImageAttributes == null)
1416 buttonAttributes.ShadowImageAttributes = new ImageAttributes()
1418 PositionUsesPivotPoint = true,
1419 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
1420 PivotPoint = Tizen.NUI.PivotPoint.Center,
1421 WidthResizePolicy = ResizePolicyType.FillToParent,
1422 HeightResizePolicy = ResizePolicyType.FillToParent
1427 private void CreateOverlayAttributes()
1429 if (buttonAttributes.OverlayImageAttributes == null)
1431 buttonAttributes.OverlayImageAttributes = new ImageAttributes()
1433 PositionUsesPivotPoint = true,
1434 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
1435 PivotPoint = Tizen.NUI.PivotPoint.Center,
1436 WidthResizePolicy = ResizePolicyType.FillToParent,
1437 HeightResizePolicy = ResizePolicyType.FillToParent
1442 private void CreateTextAttributes()
1444 if (buttonAttributes.TextAttributes == null)
1446 buttonAttributes.TextAttributes = new TextAttributes()
1448 PositionUsesPivotPoint = true,
1449 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
1450 PivotPoint = Tizen.NUI.PivotPoint.Center,
1451 WidthResizePolicy = ResizePolicyType.FillToParent,
1452 HeightResizePolicy = ResizePolicyType.FillToParent,
1453 HorizontalAlignment = HorizontalAlignment.Center,
1454 VerticalAlignment = VerticalAlignment.Center
1459 private void CreateIconAttributes()
1461 if (buttonAttributes.IconAttributes == null)
1463 buttonAttributes.IconAttributes = new ImageAttributes()
1465 PositionUsesPivotPoint = true,
1466 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
1467 PivotPoint = Tizen.NUI.PivotPoint.Center,
1468 WidthResizePolicy = ResizePolicyType.UseNaturalSize,
1469 HeightResizePolicy = ResizePolicyType.UseNaturalSize,
1474 /// ClickEventArgs is a class to record button click event arguments which will sent to user.
1476 /// <since_tizen> 6 </since_tizen>
1477 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1478 [EditorBrowsable(EditorBrowsableState.Never)]
1479 public class ClickEventArgs : EventArgs
1483 /// StateChangeEventArgs is a class to record button state change event arguments which will sent to user.
1485 /// <since_tizen> 6 </since_tizen>
1486 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1487 [EditorBrowsable(EditorBrowsableState.Never)]
1488 public class StateChangeEventArgs : EventArgs
1490 /// <summary> previous state of Button </summary>
1491 /// <since_tizen> 6 </since_tizen>
1492 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1493 [EditorBrowsable(EditorBrowsableState.Never)]
1494 public ControlStates PreviousState;
1495 /// <summary> current state of Button </summary>
1496 /// <since_tizen> 6 </since_tizen>
1497 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1498 [EditorBrowsable(EditorBrowsableState.Never)]
1499 public ControlStates CurrentState;