2 * Copyright(c) 2020 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;
20 using Tizen.NUI.Binding;
21 using Tizen.NUI.Components.Extension;
23 namespace Tizen.NUI.Components
26 /// Button is one kind of common component, a button clearly describes what action will occur when the user selects it.
27 /// Button may contain text or an icon.
29 /// <since_tizen> 6 </since_tizen>
30 public class Button : Control
32 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
33 [EditorBrowsable(EditorBrowsableState.Never)]
34 public static readonly BindableProperty IconRelativeOrientationProperty = BindableProperty.Create(nameof(IconRelativeOrientation), typeof(IconOrientation?), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
36 var instance = (Button)bindable;
39 instance.privateIconRelativeOrientation = (IconOrientation?)newValue;
42 defaultValueCreator: (bindable) =>
44 var instance = (Button)bindable;
45 return instance.privateIconRelativeOrientation;
47 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
48 [EditorBrowsable(EditorBrowsableState.Never)]
49 public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
51 var instance = (Button)bindable;
54 instance.privateIsEnabled = (bool)newValue;
57 defaultValueCreator: (bindable) =>
59 var instance = (Button)bindable;
60 return instance.privateIsEnabled;
62 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
63 [EditorBrowsable(EditorBrowsableState.Never)]
64 public static readonly BindableProperty IsSelectedProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
66 var instance = (Button)bindable;
69 instance.privateIsSelected = (bool)newValue;
72 defaultValueCreator: (bindable) =>
74 var instance = (Button)bindable;
75 return instance.privateIsSelected;
77 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
78 [EditorBrowsable(EditorBrowsableState.Never)]
79 public static readonly BindableProperty IsSelectableProperty = BindableProperty.Create(nameof(IsSelectable), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
81 var instance = (Button)bindable;
84 instance.privateIsSelectable = (bool)newValue;
87 defaultValueCreator: (bindable) =>
89 var instance = (Button)bindable;
90 return instance.privateIsSelectable;
92 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
93 [EditorBrowsable(EditorBrowsableState.Never)]
94 public static readonly BindableProperty IconPaddingProperty = BindableProperty.Create(nameof(IconPadding), typeof(Extents), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
96 var instance = (Button)bindable;
97 if (null != newValue && null != instance.Style?.IconPadding)
99 instance.Style.IconPadding.CopyFrom((Extents)newValue);
100 instance.UpdateUIContent();
103 defaultValueCreator: (bindable) =>
105 var instance = (Button)bindable;
106 return instance.Style?.IconPadding;
108 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
109 [EditorBrowsable(EditorBrowsableState.Never)]
110 public static readonly BindableProperty TextPaddingProperty = BindableProperty.Create(nameof(TextPadding), typeof(Extents), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
112 var instance = (Button)bindable;
113 if (null != newValue && null != instance.Style?.TextPadding)
115 instance.Style.TextPadding.CopyFrom((Extents)newValue);
116 instance.UpdateUIContent();
119 defaultValueCreator: (bindable) =>
121 var instance = (Button)bindable;
122 return instance.Style?.TextPadding;
125 private ImageView overlayImage;
126 private TextLabel buttonText;
127 private ImageView buttonIcon;
129 private EventHandler<StateChangedEventArgs> stateChangeHander;
131 private bool isSelected = false;
132 private bool isEnabled = true;
133 private bool isPressed = false;
136 /// The last touch information triggering selected state change.
138 [EditorBrowsable(EditorBrowsableState.Never)]
139 protected Touch SelectionChangedByTouch { get; set; }
142 /// The ButtonExtension instance that is injected by ButtonStyle.
144 [EditorBrowsable(EditorBrowsableState.Never)]
145 protected ButtonExtension Extension { get; set; }
148 /// Creates Button's text part.
150 /// <return>The created Button's text part.</return>
151 [EditorBrowsable(EditorBrowsableState.Never)]
152 protected virtual TextLabel CreateText()
154 return new TextLabel();
158 /// Creates Button's icon part.
160 /// <return>The created Button's icon part.</return>
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 protected virtual ImageView CreateIcon()
164 return new ImageView();
168 /// Creates Button's overlay image part.
170 /// <return>The created Button's overlay image part.</return>
171 [EditorBrowsable(EditorBrowsableState.Never)]
172 protected virtual ImageView CreateOverlayImage()
174 return new ImageView();
178 /// Called when the Button is Clicked by a user
180 /// <param name="eventArgs">The click information.</param>
181 [EditorBrowsable(EditorBrowsableState.Never)]
182 protected virtual void OnClick(ClickEventArgs eventArgs)
189 /// Creates a new instance of a Button.
191 /// <since_tizen> 6 </since_tizen>
192 public Button() : base()
198 /// Creates a new instance of a Button with style.
200 /// <param name="style">Create Button by special style defined in UX.</param>
201 /// <since_tizen> 8 </since_tizen>
202 public Button(string style) : base(style)
208 /// Creates a new instance of a Button with style.
210 /// <param name="buttonStyle">Create Button by style customized by user.</param>
211 /// <since_tizen> 8 </since_tizen>
212 public Button(ButtonStyle buttonStyle) : base(buttonStyle)
218 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
220 /// <since_tizen> 6 </since_tizen>
221 public event EventHandler<ClickEventArgs> ClickEvent;
223 /// An event for the button state changed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
225 /// <since_tizen> 6 </since_tizen>
226 public event EventHandler<StateChangedEventArgs> StateChangedEvent
230 stateChangeHander += value;
234 stateChangeHander -= value;
238 /// Icon orientation.
240 /// <since_tizen> 6 </since_tizen>
241 public enum IconOrientation
246 /// <since_tizen> 6 </since_tizen>
251 /// <since_tizen> 6 </since_tizen>
256 /// <since_tizen> 6 </since_tizen>
261 /// <since_tizen> 6 </since_tizen>
266 /// Button's icon part.
268 [EditorBrowsable(EditorBrowsableState.Never)]
269 public ImageView ButtonIcon
273 if (null == buttonIcon)
275 buttonIcon = CreateIcon();
276 if (null != Extension)
278 buttonIcon = Extension.OnCreateIcon(this, buttonIcon);
281 buttonIcon.Relayout += OnIconRelayout;
292 /// Button's overlay image part.
294 [EditorBrowsable(EditorBrowsableState.Never)]
295 public ImageView ButtonOverlay
299 if (null == overlayImage)
301 overlayImage = CreateOverlayImage();
302 if (null != Extension)
304 overlayImage = Extension.OnCreateOverlayImage(this, overlayImage);
306 overlayImage.WidthResizePolicy = ResizePolicyType.FillToParent;
307 overlayImage.HeightResizePolicy = ResizePolicyType.FillToParent;
314 overlayImage = value;
319 /// Button's text part.
321 [EditorBrowsable(EditorBrowsableState.Never)]
322 public TextLabel ButtonText
326 if (null == buttonText)
328 buttonText = CreateText();
329 if (null != Extension)
331 buttonText = Extension.OnCreateText(this, buttonText);
333 buttonText.HorizontalAlignment = HorizontalAlignment.Center;
334 buttonText.VerticalAlignment = VerticalAlignment.Center;
346 /// Return a copied Style instance of Button
349 /// It returns copied Style instance and changing it does not effect to the Button.
350 /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
352 /// <since_tizen> 8 </since_tizen>
353 public new ButtonStyle Style => ViewStyle as ButtonStyle;
356 /// The text of Button.
358 /// <since_tizen> 6 </since_tizen>
363 return Style?.Text?.Text?.GetValue(ControlState);
367 if (null != Style?.Text)
369 Style.Text.Text = value;
375 /// Flag to decide Button can be selected or not.
377 /// <since_tizen> 6 </since_tizen>
378 public bool IsSelectable
382 return (bool)GetValue(IsSelectableProperty);
386 SetValue(IsSelectableProperty, value);
390 private bool privateIsSelectable
394 return Style?.IsSelectable ?? false;
398 Style.IsSelectable = value;
403 /// Translate text string in Button.
405 /// <since_tizen> 6 </since_tizen>
406 public string TranslatableText
410 return Style?.Text?.TranslatableText?.All;
414 if (null != Style?.Text)
416 Style.Text.TranslatableText = value;
422 /// Text point size in Button.
424 /// <since_tizen> 6 </since_tizen>
425 public float PointSize
429 return Style?.Text?.PointSize?.All ?? 0;
433 if (null != Style?.Text)
435 Style.Text.PointSize = value;
441 /// Text font family in Button.
443 /// <since_tizen> 6 </since_tizen>
444 public string FontFamily
448 return Style?.Text?.FontFamily.All;
452 if (null != Style?.Text)
454 Style.Text.FontFamily = value;
459 /// Text color in Button.
461 /// <since_tizen> 6 </since_tizen>
462 public Color TextColor
466 return Style?.Text?.TextColor?.All;
470 if (null != Style?.Text)
472 Style.Text.TextColor = value;
477 /// Text horizontal alignment in Button.
479 /// <since_tizen> 6 </since_tizen>
480 public HorizontalAlignment TextAlignment
484 return Style?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center;
488 if (null != Style?.Text)
490 Style.Text.HorizontalAlignment = value;
495 /// Icon image's resource url in Button.
497 /// <since_tizen> 6 </since_tizen>
498 public string IconURL
502 return Style?.Icon?.ResourceUrl?.All;
506 if (null != Style?.Icon)
508 Style.Icon.ResourceUrl = value;
513 private StringSelector textSelector = new StringSelector();
515 /// Text string selector in Button.
517 /// <since_tizen> 6 </since_tizen>
518 public StringSelector TextSelector
526 if (value == null || textSelector == null)
528 Tizen.Log.Fatal("NUI", "[Exception] Button.TextSelector is null");
529 throw new NullReferenceException("Button.TextSelector is null");
533 textSelector.Clone(value);
538 private StringSelector translatableTextSelector = new StringSelector();
540 /// Translateable text string selector in Button.
542 /// <since_tizen> 6 </since_tizen>
543 public StringSelector TranslatableTextSelector
547 return translatableTextSelector;
551 if (value == null || translatableTextSelector == null)
553 Tizen.Log.Fatal("NUI", "[Exception] Button.TranslatableTextSelector is null");
554 throw new NullReferenceException("Button.TranslatableTextSelector is null");
558 translatableTextSelector.Clone(value);
563 private ColorSelector textColorSelector = new ColorSelector();
565 /// Text color selector in Button.
567 /// <since_tizen> 6 </since_tizen>
568 public ColorSelector TextColorSelector
572 return textColorSelector;
576 if (value == null || textColorSelector == null)
578 Tizen.Log.Fatal("NUI", "[Exception] Button.textColorSelector is null");
579 throw new NullReferenceException("Button.textColorSelector is null");
583 textColorSelector.Clone(value);
588 private FloatSelector pointSizeSelector = new FloatSelector();
590 /// Text font size selector in Button.
592 /// <since_tizen> 6 </since_tizen>
593 public FloatSelector PointSizeSelector
597 return pointSizeSelector;
601 if (value == null || pointSizeSelector == null)
603 Tizen.Log.Fatal("NUI", "[Exception] Button.pointSizeSelector is null");
604 throw new NullReferenceException("Button.pointSizeSelector is null");
608 pointSizeSelector.Clone(value);
613 private StringSelector iconURLSelector = new StringSelector();
615 /// Icon image's resource url selector in Button.
617 /// <since_tizen> 6 </since_tizen>
618 public StringSelector IconURLSelector
622 return iconURLSelector;
626 if (value == null || iconURLSelector == null)
628 Tizen.Log.Fatal("NUI", "[Exception] Button.iconURLSelector is null");
629 throw new NullReferenceException("Button.iconURLSelector is null");
633 iconURLSelector.Clone(value);
639 /// Flag to decide selected state in Button.
641 /// <since_tizen> 6 </since_tizen>
642 public bool IsSelected
646 return (bool)GetValue(IsSelectedProperty);
650 SetValue(IsSelectedProperty, value);
653 private bool privateIsSelected
668 /// Flag to decide enable or disable in Button.
670 /// <since_tizen> 6 </since_tizen>
671 public bool IsEnabled
675 return (bool)GetValue(IsEnabledProperty);
679 SetValue(IsEnabledProperty, value);
682 private bool privateIsEnabled
696 /// Icon relative orientation in Button, work only when show icon and text.
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 IconOrientation? IconRelativeOrientation
705 return (IconOrientation?)GetValue(IconRelativeOrientationProperty);
709 SetValue(IconRelativeOrientationProperty, value);
712 private IconOrientation? privateIconRelativeOrientation
716 return Style?.IconRelativeOrientation;
720 if (Style != null && Style.IconRelativeOrientation != value)
722 Style.IconRelativeOrientation = value;
729 /// Icon padding in Button, work only when show icon and text.
731 /// <since_tizen> 6 </since_tizen>
732 public Extents IconPadding
734 get => (Extents)GetValue(IconPaddingProperty);
735 set => SetValue(IconPaddingProperty, value);
739 /// Text padding in Button, work only when show icon and text.
741 /// <since_tizen> 6 </since_tizen>
742 public Extents TextPadding
744 get => (Extents)GetValue(TextPaddingProperty);
745 set => SetValue(TextPaddingProperty, value);
749 /// Dispose Button and all children on it.
751 /// <param name="type">Dispose type.</param>
752 /// <since_tizen> 6 </since_tizen>
753 protected override void Dispose(DisposeTypes type)
760 if (type == DisposeTypes.Explicit)
762 Extension?.OnDispose(this);
764 if (ButtonIcon != null)
766 Utility.Dispose(ButtonIcon);
768 if (ButtonText != null)
770 Utility.Dispose(ButtonText);
772 if (ButtonOverlay != null)
774 Utility.Dispose(ButtonOverlay);
781 /// Called after a key event is received by the view that has had its focus set.
783 /// <param name="key">The key event.</param>
784 /// <returns>True if the key event should be consumed.</returns>
785 /// <since_tizen> 6 </since_tizen>
786 public override bool OnKey(Key key)
788 if (null == key) return false;
789 if (key.State == Key.StateType.Down)
791 if (key.KeyPressedName == "Return")
797 else if (key.State == Key.StateType.Up)
799 if (key.KeyPressedName == "Return")
801 bool clicked = isPressed && isEnabled;
805 if (Style.IsSelectable != null && Style.IsSelectable == true)
807 IsSelected = !IsSelected;
816 ClickEventArgs eventArgs = new ClickEventArgs();
817 OnClickInternal(eventArgs);
821 return base.OnKey(key);
825 /// 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.
827 /// <since_tizen> 6 </since_tizen>
828 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
829 [EditorBrowsable(EditorBrowsableState.Never)]
830 public override void OnFocusGained()
832 base.OnFocusGained();
837 /// 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.
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 override void OnFocusLost()
849 /// Called after a touch event is received by the owning view.<br />
850 /// CustomViewBehaviour.REQUIRES_TOUCH_EVENTS must be enabled during construction. See CustomView(ViewWrapperImpl.CustomViewBehaviour behaviour).<br />
852 /// <param name="touch">The touch event.</param>
853 /// <returns>True if the event should be consumed.</returns>
854 /// <since_tizen> 6 </since_tizen>
855 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
856 [EditorBrowsable(EditorBrowsableState.Never)]
857 public override bool OnTouch(Touch touch)
859 if (null == touch) return false;
860 PointStateType state = touch.GetState(0);
864 case PointStateType.Down:
866 Extension?.SetTouchInfo(touch);
869 case PointStateType.Interrupted:
873 case PointStateType.Up:
875 bool clicked = isPressed && isEnabled;
879 if (Style.IsSelectable != null && Style.IsSelectable == true)
881 Extension?.SetTouchInfo(touch);
882 IsSelected = !IsSelected;
886 Extension?.SetTouchInfo(touch);
892 ClickEventArgs eventArgs = new ClickEventArgs();
893 OnClickInternal(eventArgs);
901 return base.OnTouch(touch);
905 /// Apply style to button.
907 /// <param name="viewStyle">The style to apply.</param>
908 /// <since_tizen> 8 </since_tizen>
909 public override void ApplyStyle(ViewStyle viewStyle)
911 base.ApplyStyle(viewStyle);
913 ButtonStyle buttonStyle = viewStyle as ButtonStyle;
914 if (null != buttonStyle)
916 Extension = buttonStyle.CreateExtension();
917 if (buttonStyle.Overlay != null)
919 ButtonOverlay?.ApplyStyle(buttonStyle.Overlay);
922 if (buttonStyle.Text != null)
924 ButtonText?.ApplyStyle(buttonStyle.Text);
927 if (buttonStyle.Icon != null)
929 ButtonIcon?.ApplyStyle(buttonStyle.Icon);
935 /// Get Button style.
937 /// <returns>The default button style.</returns>
938 /// <since_tizen> 8 </since_tizen>
939 protected override ViewStyle CreateViewStyle()
941 return new ButtonStyle();
944 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
945 [EditorBrowsable(EditorBrowsableState.Never)]
946 protected override void OnUpdate()
951 Extension?.OnRelayout(this);
955 /// Update Button State.
957 /// <param name="touchInfo">The touch information in case the state has changed by touching.</param>
958 /// <since_tizen> 6 </since_tizen>
959 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
960 [EditorBrowsable(EditorBrowsableState.Never)]
961 protected void UpdateState()
963 ControlStates sourceState = ControlState;
964 ControlStates targetState;
971 targetState = ControlStates.Pressed;
976 targetState = ControlStates.Normal;
979 targetState |= (IsSelected ? ControlStates.Selected : 0);
981 // Focused, SelectedFocused
982 targetState |= (IsFocused ? ControlStates.Focused : 0);
988 targetState = ControlStates.Disabled;
990 // DisabledSelected, DisabledFocused
991 targetState |= (IsSelected ? ControlStates.Selected : (IsFocused ? ControlStates.Focused : 0));
994 if (sourceState != targetState)
996 ControlState = targetState;
1000 StateChangedEventArgs e = new StateChangedEventArgs
1002 PreviousState = sourceState,
1003 CurrentState = targetState
1005 stateChangeHander?.Invoke(this, e);
1007 Extension?.OnControlStateChanged(this, new ControlStateChangedEventArgs(sourceState, targetState));
1012 /// It is hijack by using protected, style copy problem when class inherited from Button.
1014 /// <since_tizen> 6 </since_tizen>
1015 private void Initialize()
1017 var style = (ButtonStyle)Style;
1018 EnableControlStatePropagation = true;
1020 LayoutDirectionChanged += OnLayoutDirectionChanged;
1024 /// Measure text, it can be override.
1026 /// <since_tizen> 6 </since_tizen>
1027 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1028 [EditorBrowsable(EditorBrowsableState.Never)]
1029 protected virtual void MeasureText()
1031 if (Style.IconRelativeOrientation == null || ButtonIcon == null || ButtonText == null)
1035 ButtonText.WidthResizePolicy = ResizePolicyType.Fixed;
1036 ButtonText.HeightResizePolicy = ResizePolicyType.Fixed;
1037 int textPaddingStart = Style.TextPadding.Start;
1038 int textPaddingEnd = Style.TextPadding.End;
1039 int textPaddingTop = Style.TextPadding.Top;
1040 int textPaddingBottom = Style.TextPadding.Bottom;
1042 int iconPaddingStart = Style.IconPadding.Start;
1043 int iconPaddingEnd = Style.IconPadding.End;
1044 int iconPaddingTop = Style.IconPadding.Top;
1045 int iconPaddingBottom = Style.IconPadding.Bottom;
1047 if (IconRelativeOrientation == IconOrientation.Top || IconRelativeOrientation == IconOrientation.Bottom)
1049 ButtonText.SizeWidth = SizeWidth - textPaddingStart - textPaddingEnd;
1050 ButtonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom - iconPaddingTop - iconPaddingBottom - ButtonIcon.SizeHeight;
1054 ButtonText.SizeWidth = SizeWidth - textPaddingStart - textPaddingEnd - iconPaddingStart - iconPaddingEnd - ButtonIcon.SizeWidth;
1055 ButtonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom;
1059 /// Layout child, it can be override.
1061 /// <since_tizen> 6 </since_tizen>
1062 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1063 [EditorBrowsable(EditorBrowsableState.Never)]
1064 protected virtual void LayoutChild()
1066 if (Style.IconRelativeOrientation == null || ButtonIcon == null || ButtonText == null)
1071 var buttonIcon = ButtonIcon;
1072 var buttonText = ButtonText;
1074 int textPaddingStart = Style.TextPadding.Start;
1075 int textPaddingEnd = Style.TextPadding.End;
1076 int textPaddingTop = Style.TextPadding.Top;
1077 int textPaddingBottom = Style.TextPadding.Bottom;
1079 int iconPaddingStart = Style.IconPadding.Start;
1080 int iconPaddingEnd = Style.IconPadding.End;
1081 int iconPaddingTop = Style.IconPadding.Top;
1082 int iconPaddingBottom = Style.IconPadding.Bottom;
1084 switch (IconRelativeOrientation)
1086 case IconOrientation.Top:
1087 buttonIcon.PositionUsesPivotPoint = true;
1088 buttonIcon.ParentOrigin = NUI.ParentOrigin.TopCenter;
1089 buttonIcon.PivotPoint = NUI.PivotPoint.TopCenter;
1090 buttonIcon.Position2D = new Position2D(0, iconPaddingTop);
1092 buttonText.PositionUsesPivotPoint = true;
1093 buttonText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1094 buttonText.PivotPoint = NUI.PivotPoint.BottomCenter;
1095 buttonText.Position2D = new Position2D(0, -textPaddingBottom);
1097 case IconOrientation.Bottom:
1098 buttonIcon.PositionUsesPivotPoint = true;
1099 buttonIcon.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1100 buttonIcon.PivotPoint = NUI.PivotPoint.BottomCenter;
1101 buttonIcon.Position2D = new Position2D(0, -iconPaddingBottom);
1103 buttonText.PositionUsesPivotPoint = true;
1104 buttonText.ParentOrigin = NUI.ParentOrigin.TopCenter;
1105 buttonText.PivotPoint = NUI.PivotPoint.TopCenter;
1106 buttonText.Position2D = new Position2D(0, textPaddingTop);
1108 case IconOrientation.Left:
1109 if (LayoutDirection == ViewLayoutDirectionType.LTR)
1111 buttonIcon.PositionUsesPivotPoint = true;
1112 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1113 buttonIcon.PivotPoint = NUI.PivotPoint.CenterLeft;
1114 buttonIcon.Position2D = new Position2D(iconPaddingStart, 0);
1116 buttonText.PositionUsesPivotPoint = true;
1117 buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
1118 buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
1119 buttonText.Position2D = new Position2D(-textPaddingEnd, 0);
1123 buttonIcon.PositionUsesPivotPoint = true;
1124 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
1125 buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
1126 buttonIcon.Position2D = new Position2D(-iconPaddingStart, 0);
1128 buttonText.PositionUsesPivotPoint = true;
1129 buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1130 buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
1131 buttonText.Position2D = new Position2D(textPaddingEnd, 0);
1135 case IconOrientation.Right:
1136 if (LayoutDirection == ViewLayoutDirectionType.RTL)
1138 buttonIcon.PositionUsesPivotPoint = true;
1139 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1140 buttonIcon.PivotPoint = NUI.PivotPoint.CenterLeft;
1141 buttonIcon.Position2D = new Position2D(iconPaddingEnd, 0);
1143 buttonText.PositionUsesPivotPoint = true;
1144 buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
1145 buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
1146 buttonText.Position2D = new Position2D(-textPaddingStart, 0);
1150 buttonIcon.PositionUsesPivotPoint = true;
1151 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
1152 buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
1153 buttonIcon.Position2D = new Position2D(-iconPaddingEnd, 0);
1155 buttonText.PositionUsesPivotPoint = true;
1156 buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1157 buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
1158 buttonText.Position2D = new Position2D(textPaddingStart, 0);
1164 if (string.IsNullOrEmpty(buttonText.Text))
1166 buttonIcon.ParentOrigin = NUI.ParentOrigin.Center;
1167 buttonIcon.PivotPoint = NUI.PivotPoint.Center;
1171 /// Theme change callback when theme is changed, this callback will be trigger.
1173 /// <param name="sender">The sender</param>
1174 /// <param name="e">The event data</param>
1175 /// <since_tizen> 8 </since_tizen>
1176 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
1178 ButtonStyle buttonStyle = StyleManager.Instance.GetViewStyle(StyleName) as ButtonStyle;
1179 if (buttonStyle != null)
1181 Style.CopyFrom(buttonStyle);
1186 private void UpdateUIContent()
1191 Sensitive = isEnabled;
1194 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
1200 private void OnClickInternal(ClickEventArgs eventArgs)
1202 Command?.Execute(CommandParameter);
1204 Extension?.OnClick(this, eventArgs);
1205 ClickEvent?.Invoke(this, eventArgs);
1208 private void OnIconRelayout(object sender, EventArgs e)
1215 /// ClickEventArgs is a class to record button click event arguments which will sent to user.
1217 /// <since_tizen> 6 </since_tizen>
1218 public class ClickEventArgs : EventArgs
1222 /// StateChangeEventArgs is a class to record button state change event arguments which will sent to user.
1224 /// <since_tizen> 6 </since_tizen>
1225 public class StateChangedEventArgs : EventArgs
1227 /// <summary> previous state of Button </summary>
1228 /// <since_tizen> 6 </since_tizen>
1229 public ControlStates PreviousState;
1230 /// <summary> current state of Button </summary>
1231 /// <since_tizen> 6 </since_tizen>
1232 public ControlStates CurrentState;
1236 /// Get current text part to the attached ButtonExtension.
1239 /// It returns null if the passed extension is invaild.
1241 /// <param name="extension">The extension instance that is currently attached to this Button.</param>
1242 /// <return>The button's text part.</return>
1243 [EditorBrowsable(EditorBrowsableState.Never)]
1244 public TextLabel GetCurrentText(ButtonExtension extension)
1246 return (extension == Extension) ? ButtonText : null;
1250 /// Get current icon part to the attached ButtonExtension.
1253 /// It returns null if the passed extension is invaild.
1255 /// <param name="extension">The extension instance that is currently attached to this Button.</param>
1256 /// <return>The button's icon part.</return>
1257 [EditorBrowsable(EditorBrowsableState.Never)]
1258 public ImageView GetCurrentIcon(ButtonExtension extension)
1260 return (extension == Extension) ? ButtonIcon : null;
1264 /// Get current overlay image part to the attached ButtonExtension.
1267 /// It returns null if the passed extension is invaild.
1269 /// <param name="extension">The extension instance that is currently attached to this Button.</param>
1270 /// <return>The button's overlay image part.</return>
1271 [EditorBrowsable(EditorBrowsableState.Never)]
1272 public ImageView GetCurrentOverlayImage(ButtonExtension extension)
1274 return (extension == Extension) ? ButtonOverlay : null;