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 EventHandler<StateChangedEventArgs> stateChangeHander;
127 private bool isSelected = false;
128 private bool isEnabled = true;
129 private bool isPressed = false;
132 /// Button's overlay image part.
134 [EditorBrowsable(EditorBrowsableState.Never)]
135 protected ImageView ButtonOverlayImage { get; set; }
138 /// Button's text part.
140 [EditorBrowsable(EditorBrowsableState.Never)]
141 protected TextLabel ButtonText { get; set; }
144 /// Button's icon part.
146 [EditorBrowsable(EditorBrowsableState.Never)]
147 protected ImageView ButtonIcon { get; set; }
150 /// The last touch information triggering selected state change.
152 [EditorBrowsable(EditorBrowsableState.Never)]
153 protected Touch SelectionChangedByTouch { get; set; }
156 /// The ButtonExtension instance that is injected by ButtonStyle.
158 [EditorBrowsable(EditorBrowsableState.Never)]
159 protected ButtonExtension Extension { get; set; }
162 /// Creates Button's text part.
164 /// <return>The created Button's text part.</return>
165 [EditorBrowsable(EditorBrowsableState.Never)]
166 protected virtual TextLabel CreateText()
168 return new TextLabel();
172 /// Creates Button's icon part.
174 /// <return>The created Button's icon part.</return>
175 [EditorBrowsable(EditorBrowsableState.Never)]
176 protected virtual ImageView CreateIcon()
178 return new ImageView();
182 /// Creates Button's overlay image part.
184 /// <return>The created Button's overlay image part.</return>
185 [EditorBrowsable(EditorBrowsableState.Never)]
186 protected virtual ImageView CreateOverlayImage()
188 return new ImageView();
192 /// Called when the Button is Clicked by a user
194 /// <param name="eventArgs">The click information.</param>
195 [EditorBrowsable(EditorBrowsableState.Never)]
196 protected virtual void OnClick(ClickEventArgs eventArgs)
203 /// Creates a new instance of a Button.
205 /// <since_tizen> 6 </since_tizen>
206 public Button() : base()
212 /// Creates a new instance of a Button with style.
214 /// <param name="style">Create Button by special style defined in UX.</param>
215 /// <since_tizen> 8 </since_tizen>
216 public Button(string style) : base(style)
222 /// Creates a new instance of a Button with style.
224 /// <param name="buttonStyle">Create Button by style customized by user.</param>
225 /// <since_tizen> 8 </since_tizen>
226 public Button(ButtonStyle buttonStyle) : base(buttonStyle)
232 /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
234 /// <since_tizen> 6 </since_tizen>
235 public event EventHandler<ClickEventArgs> ClickEvent;
237 /// An event for the button state changed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
239 /// <since_tizen> 6 </since_tizen>
240 public event EventHandler<StateChangedEventArgs> StateChangedEvent
244 stateChangeHander += value;
248 stateChangeHander -= value;
252 /// Icon orientation.
254 /// <since_tizen> 6 </since_tizen>
255 public enum IconOrientation
260 /// <since_tizen> 6 </since_tizen>
265 /// <since_tizen> 6 </since_tizen>
270 /// <since_tizen> 6 </since_tizen>
275 /// <since_tizen> 6 </since_tizen>
280 /// Style of the button.
282 /// <since_tizen> 8 </since_tizen>
283 public new ButtonStyle Style => ViewStyle as ButtonStyle;
286 /// The text of Button.
288 /// <since_tizen> 6 </since_tizen>
293 return Style?.Text?.Text?.GetValue(ControlState);
297 if (null != Style?.Text)
299 Style.Text.Text = value;
305 /// Flag to decide Button can be selected or not.
307 /// <since_tizen> 6 </since_tizen>
308 public bool IsSelectable
312 return (bool)GetValue(IsSelectableProperty);
316 SetValue(IsSelectableProperty, value);
320 private bool privateIsSelectable
324 return Style?.IsSelectable ?? false;
328 Style.IsSelectable = value;
333 /// Translate text string in Button.
335 /// <since_tizen> 6 </since_tizen>
336 public string TranslatableText
340 return Style?.Text?.TranslatableText?.All;
344 if (null != Style?.Text)
346 Style.Text.TranslatableText = value;
352 /// Text point size in Button.
354 /// <since_tizen> 6 </since_tizen>
355 public float PointSize
359 return Style?.Text?.PointSize?.All ?? 0;
363 if (null != Style?.Text)
365 Style.Text.PointSize = value;
371 /// Text font family in Button.
373 /// <since_tizen> 6 </since_tizen>
374 public string FontFamily
378 return Style?.Text?.FontFamily.All;
382 if (null != Style?.Text)
384 Style.Text.FontFamily = value;
389 /// Text color in Button.
391 /// <since_tizen> 6 </since_tizen>
392 public Color TextColor
396 return Style?.Text?.TextColor?.All;
400 if (null != Style?.Text)
402 Style.Text.TextColor = value;
407 /// Text horizontal alignment in Button.
409 /// <since_tizen> 6 </since_tizen>
410 public HorizontalAlignment TextAlignment
414 return Style?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center;
418 if (null != Style?.Text)
420 Style.Text.HorizontalAlignment = value;
425 /// Icon image's resource url in Button.
427 /// <since_tizen> 6 </since_tizen>
428 public string IconURL
432 return Style?.Icon?.ResourceUrl?.All;
436 if (null != Style?.Icon)
438 Style.Icon.ResourceUrl = value;
443 private StringSelector textSelector = new StringSelector();
445 /// Text string selector in Button.
447 /// <since_tizen> 6 </since_tizen>
448 public StringSelector TextSelector
456 if (value == null || textSelector == null)
458 Tizen.Log.Fatal("NUI", "[Exception] Button.TextSelector is null");
459 throw new NullReferenceException("Button.TextSelector is null");
463 textSelector.Clone(value);
468 private StringSelector translatableTextSelector = new StringSelector();
470 /// Translateable text string selector in Button.
472 /// <since_tizen> 6 </since_tizen>
473 public StringSelector TranslatableTextSelector
477 return translatableTextSelector;
481 if (value == null || translatableTextSelector == null)
483 Tizen.Log.Fatal("NUI", "[Exception] Button.TranslatableTextSelector is null");
484 throw new NullReferenceException("Button.TranslatableTextSelector is null");
488 translatableTextSelector.Clone(value);
493 private ColorSelector textColorSelector = new ColorSelector();
495 /// Text color selector in Button.
497 /// <since_tizen> 6 </since_tizen>
498 public ColorSelector TextColorSelector
502 return textColorSelector;
506 if (value == null || textColorSelector == null)
508 Tizen.Log.Fatal("NUI", "[Exception] Button.textColorSelector is null");
509 throw new NullReferenceException("Button.textColorSelector is null");
513 textColorSelector.Clone(value);
518 private FloatSelector pointSizeSelector = new FloatSelector();
520 /// Text font size selector in Button.
522 /// <since_tizen> 6 </since_tizen>
523 public FloatSelector PointSizeSelector
527 return pointSizeSelector;
531 if (value == null || pointSizeSelector == null)
533 Tizen.Log.Fatal("NUI", "[Exception] Button.pointSizeSelector is null");
534 throw new NullReferenceException("Button.pointSizeSelector is null");
538 pointSizeSelector.Clone(value);
543 private StringSelector iconURLSelector = new StringSelector();
545 /// Icon image's resource url selector in Button.
547 /// <since_tizen> 6 </since_tizen>
548 public StringSelector IconURLSelector
552 return iconURLSelector;
556 if (value == null || iconURLSelector == null)
558 Tizen.Log.Fatal("NUI", "[Exception] Button.iconURLSelector is null");
559 throw new NullReferenceException("Button.iconURLSelector is null");
563 iconURLSelector.Clone(value);
569 /// Flag to decide selected state in Button.
571 /// <since_tizen> 6 </since_tizen>
572 public bool IsSelected
576 return (bool)GetValue(IsSelectedProperty);
580 SetValue(IsSelectedProperty, value);
583 private bool privateIsSelected
593 UpdateState(SelectionChangedByTouch);
595 SelectionChangedByTouch = null;
600 /// Flag to decide enable or disable in Button.
602 /// <since_tizen> 6 </since_tizen>
603 public bool IsEnabled
607 return (bool)GetValue(IsEnabledProperty);
611 SetValue(IsEnabledProperty, value);
614 private bool privateIsEnabled
628 /// Icon relative orientation in Button, work only when show icon and text.
630 /// <since_tizen> 6 </since_tizen>
631 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
632 [EditorBrowsable(EditorBrowsableState.Never)]
633 public IconOrientation? IconRelativeOrientation
637 return (IconOrientation?)GetValue(IconRelativeOrientationProperty);
641 SetValue(IconRelativeOrientationProperty, value);
644 private IconOrientation? privateIconRelativeOrientation
648 return Style?.IconRelativeOrientation;
652 if (Style != null && Style.IconRelativeOrientation != value)
654 Style.IconRelativeOrientation = value;
661 /// Icon padding in Button, work only when show icon and text.
663 /// <since_tizen> 6 </since_tizen>
664 public Extents IconPadding
666 get => (Extents)GetValue(IconPaddingProperty);
667 set => SetValue(IconPaddingProperty, value);
671 /// Text padding in Button, work only when show icon and text.
673 /// <since_tizen> 6 </since_tizen>
674 public Extents TextPadding
676 get => (Extents)GetValue(TextPaddingProperty);
677 set => SetValue(TextPaddingProperty, value);
681 /// Dispose Button and all children on it.
683 /// <param name="type">Dispose type.</param>
684 /// <since_tizen> 6 </since_tizen>
685 protected override void Dispose(DisposeTypes type)
692 if (type == DisposeTypes.Explicit)
694 Extension?.OnDispose(this);
696 if (ButtonIcon != null)
698 Utility.Dispose(ButtonIcon);
700 if (ButtonText != null)
702 Utility.Dispose(ButtonText);
704 if (ButtonOverlayImage != null)
706 Utility.Dispose(ButtonOverlayImage);
713 /// Called after a key event is received by the view that has had its focus set.
715 /// <param name="key">The key event.</param>
716 /// <returns>True if the key event should be consumed.</returns>
717 /// <since_tizen> 6 </since_tizen>
718 public override bool OnKey(Key key)
720 if (null == key) return false;
721 if (key.State == Key.StateType.Down)
723 if (key.KeyPressedName == "Return")
729 else if (key.State == Key.StateType.Up)
731 if (key.KeyPressedName == "Return")
733 bool clicked = isPressed && isEnabled;
737 if (Style.IsSelectable != null && Style.IsSelectable == true)
739 IsSelected = !IsSelected;
748 ClickEventArgs eventArgs = new ClickEventArgs();
749 OnClickInternal(eventArgs);
753 return base.OnKey(key);
757 /// 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.
759 /// <since_tizen> 6 </since_tizen>
760 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
761 [EditorBrowsable(EditorBrowsableState.Never)]
762 public override void OnFocusGained()
764 base.OnFocusGained();
769 /// 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.
771 /// <since_tizen> 6 </since_tizen>
772 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
773 [EditorBrowsable(EditorBrowsableState.Never)]
774 public override void OnFocusLost()
781 /// Called after a touch event is received by the owning view.<br />
782 /// CustomViewBehaviour.REQUIRES_TOUCH_EVENTS must be enabled during construction. See CustomView(ViewWrapperImpl.CustomViewBehaviour behaviour).<br />
784 /// <param name="touch">The touch event.</param>
785 /// <returns>True if the event should be consumed.</returns>
786 /// <since_tizen> 6 </since_tizen>
787 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
788 [EditorBrowsable(EditorBrowsableState.Never)]
789 public override bool OnTouch(Touch touch)
791 if (null == touch) return false;
792 PointStateType state = touch.GetState(0);
796 case PointStateType.Down:
800 case PointStateType.Interrupted:
804 case PointStateType.Up:
806 bool clicked = isPressed && isEnabled;
810 if (Style.IsSelectable != null && Style.IsSelectable == true)
812 SelectionChangedByTouch = touch;
813 IsSelected = !IsSelected;
822 ClickEventArgs eventArgs = new ClickEventArgs();
823 OnClickInternal(eventArgs);
831 return base.OnTouch(touch);
835 /// Apply style to button.
837 /// <param name="viewStyle">The style to apply.</param>
838 /// <since_tizen> 8 </since_tizen>
839 public override void ApplyStyle(ViewStyle viewStyle)
841 base.ApplyStyle(viewStyle);
843 ButtonStyle buttonStyle = viewStyle as ButtonStyle;
845 if (null != buttonStyle)
847 ButtonOverlayImage?.ApplyStyle(buttonStyle.Overlay);
848 ButtonText?.ApplyStyle(buttonStyle.Text);
849 ButtonIcon?.ApplyStyle(buttonStyle.Icon);
854 /// Get Button style.
856 /// <returns>The default button style.</returns>
857 /// <since_tizen> 8 </since_tizen>
858 protected override ViewStyle GetViewStyle()
860 return new ButtonStyle();
863 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
864 [EditorBrowsable(EditorBrowsableState.Never)]
865 protected override void OnUpdate()
870 Extension?.OnRelayout(this);
874 /// Update Button State.
876 /// <param name="touchInfo">The touch information in case the state has changed by touching.</param>
877 /// <since_tizen> 6 </since_tizen>
878 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
879 [EditorBrowsable(EditorBrowsableState.Never)]
880 protected void UpdateState(Touch touchInfo = null)
882 ControlStates sourceState = ControlState;
883 ControlStates targetState;
890 targetState = ControlStates.Pressed;
895 targetState = ControlStates.Normal;
898 targetState |= (IsSelected ? ControlStates.Selected : 0);
900 // Focused, SelectedFocused
901 targetState |= (IsFocused ? ControlStates.Focused : 0);
907 targetState = ControlStates.Disabled;
909 // DisabledSelected, DisabledFocused
910 targetState |= (IsSelected ? ControlStates.Selected : (IsFocused ? ControlStates.Focused : 0));
913 if (SetControlState(targetState, touchInfo))
917 StateChangedEventArgs e = new StateChangedEventArgs
919 PreviousState = sourceState,
920 CurrentState = targetState
922 stateChangeHander?.Invoke(this, e);
924 Extension?.OnControlStateChanged(this, sourceState, touchInfo);
929 /// It is hijack by using protected, style copy problem when class inherited from Button.
931 /// <since_tizen> 6 </since_tizen>
932 private void Initialize()
934 var style = (ButtonStyle)Style;
936 Extension = style.CreateExtension();
940 EnableControlStatePropagation = true;
942 if (ButtonOverlayImage != null)
944 Add(ButtonOverlayImage);
945 ButtonOverlayImage.ApplyStyle(style.Overlay);
948 if (ButtonIcon != null)
951 ButtonIcon.ApplyStyle(style.Icon);
952 ButtonIcon.Relayout += OnIconRelayout;
955 if (null != ButtonText)
958 ButtonText.ApplyStyle(style.Text);
963 LayoutDirectionChanged += OnLayoutDirectionChanged;
966 private void CreateComponents()
968 ButtonOverlayImage = CreateOverlayImage();
969 ButtonIcon = CreateIcon();
970 ButtonText = CreateText();
972 if (Extension == null)
977 // Update component with extension
978 ButtonOverlayImage = Extension.OnCreateOverlayImage(this, ButtonOverlayImage);
979 ButtonIcon = Extension.OnCreateIcon(this, ButtonIcon);
980 ButtonText = Extension.OnCreateText(this, ButtonText);
984 /// Measure text, it can be override.
986 /// <since_tizen> 6 </since_tizen>
987 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
988 [EditorBrowsable(EditorBrowsableState.Never)]
989 protected virtual void MeasureText()
991 if (Style.IconRelativeOrientation == null || ButtonIcon == null || ButtonText == null)
995 ButtonText.WidthResizePolicy = ResizePolicyType.Fixed;
996 ButtonText.HeightResizePolicy = ResizePolicyType.Fixed;
997 int textPaddingStart = Style.TextPadding.Start;
998 int textPaddingEnd = Style.TextPadding.End;
999 int textPaddingTop = Style.TextPadding.Top;
1000 int textPaddingBottom = Style.TextPadding.Bottom;
1002 int iconPaddingStart = Style.IconPadding.Start;
1003 int iconPaddingEnd = Style.IconPadding.End;
1004 int iconPaddingTop = Style.IconPadding.Top;
1005 int iconPaddingBottom = Style.IconPadding.Bottom;
1007 if (IconRelativeOrientation == IconOrientation.Top || IconRelativeOrientation == IconOrientation.Bottom)
1009 ButtonText.SizeWidth = SizeWidth - textPaddingStart - textPaddingEnd;
1010 ButtonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom - iconPaddingTop - iconPaddingBottom - ButtonIcon.SizeHeight;
1014 ButtonText.SizeWidth = SizeWidth - textPaddingStart - textPaddingEnd - iconPaddingStart - iconPaddingEnd - ButtonIcon.SizeWidth;
1015 ButtonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom;
1019 /// Layout child, it can be override.
1021 /// <since_tizen> 6 </since_tizen>
1022 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
1023 [EditorBrowsable(EditorBrowsableState.Never)]
1024 protected virtual void LayoutChild()
1026 if (Style.IconRelativeOrientation == null || ButtonIcon == null || ButtonText == null)
1031 var buttonIcon = ButtonIcon;
1032 var buttonText = ButtonText;
1034 int textPaddingStart = Style.TextPadding.Start;
1035 int textPaddingEnd = Style.TextPadding.End;
1036 int textPaddingTop = Style.TextPadding.Top;
1037 int textPaddingBottom = Style.TextPadding.Bottom;
1039 int iconPaddingStart = Style.IconPadding.Start;
1040 int iconPaddingEnd = Style.IconPadding.End;
1041 int iconPaddingTop = Style.IconPadding.Top;
1042 int iconPaddingBottom = Style.IconPadding.Bottom;
1044 switch (IconRelativeOrientation)
1046 case IconOrientation.Top:
1047 buttonIcon.PositionUsesPivotPoint = true;
1048 buttonIcon.ParentOrigin = NUI.ParentOrigin.TopCenter;
1049 buttonIcon.PivotPoint = NUI.PivotPoint.TopCenter;
1050 buttonIcon.Position2D = new Position2D(0, iconPaddingTop);
1052 buttonText.PositionUsesPivotPoint = true;
1053 buttonText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1054 buttonText.PivotPoint = NUI.PivotPoint.BottomCenter;
1055 buttonText.Position2D = new Position2D(0, -textPaddingBottom);
1057 case IconOrientation.Bottom:
1058 buttonIcon.PositionUsesPivotPoint = true;
1059 buttonIcon.ParentOrigin = NUI.ParentOrigin.BottomCenter;
1060 buttonIcon.PivotPoint = NUI.PivotPoint.BottomCenter;
1061 buttonIcon.Position2D = new Position2D(0, -iconPaddingBottom);
1063 buttonText.PositionUsesPivotPoint = true;
1064 buttonText.ParentOrigin = NUI.ParentOrigin.TopCenter;
1065 buttonText.PivotPoint = NUI.PivotPoint.TopCenter;
1066 buttonText.Position2D = new Position2D(0, textPaddingTop);
1068 case IconOrientation.Left:
1069 if (LayoutDirection == ViewLayoutDirectionType.LTR)
1071 buttonIcon.PositionUsesPivotPoint = true;
1072 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1073 buttonIcon.PivotPoint = NUI.PivotPoint.CenterLeft;
1074 buttonIcon.Position2D = new Position2D(iconPaddingStart, 0);
1076 buttonText.PositionUsesPivotPoint = true;
1077 buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
1078 buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
1079 buttonText.Position2D = new Position2D(-textPaddingEnd, 0);
1083 buttonIcon.PositionUsesPivotPoint = true;
1084 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
1085 buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
1086 buttonIcon.Position2D = new Position2D(-iconPaddingStart, 0);
1088 buttonText.PositionUsesPivotPoint = true;
1089 buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1090 buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
1091 buttonText.Position2D = new Position2D(textPaddingEnd, 0);
1095 case IconOrientation.Right:
1096 if (LayoutDirection == ViewLayoutDirectionType.RTL)
1098 buttonIcon.PositionUsesPivotPoint = true;
1099 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1100 buttonIcon.PivotPoint = NUI.PivotPoint.CenterLeft;
1101 buttonIcon.Position2D = new Position2D(iconPaddingEnd, 0);
1103 buttonText.PositionUsesPivotPoint = true;
1104 buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
1105 buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
1106 buttonText.Position2D = new Position2D(-textPaddingStart, 0);
1110 buttonIcon.PositionUsesPivotPoint = true;
1111 buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
1112 buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
1113 buttonIcon.Position2D = new Position2D(-iconPaddingEnd, 0);
1115 buttonText.PositionUsesPivotPoint = true;
1116 buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
1117 buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
1118 buttonText.Position2D = new Position2D(textPaddingStart, 0);
1124 if (string.IsNullOrEmpty(buttonText.Text))
1126 buttonIcon.ParentOrigin = NUI.ParentOrigin.Center;
1127 buttonIcon.PivotPoint = NUI.PivotPoint.Center;
1131 /// Theme change callback when theme is changed, this callback will be trigger.
1133 /// <param name="sender">The sender</param>
1134 /// <param name="e">The event data</param>
1135 /// <since_tizen> 8 </since_tizen>
1136 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
1138 ButtonStyle buttonStyle = StyleManager.Instance.GetViewStyle(style) as ButtonStyle;
1139 if (buttonStyle != null)
1141 Style.CopyFrom(buttonStyle);
1146 private void UpdateUIContent()
1151 Sensitive = isEnabled;
1154 private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
1160 private void OnClickInternal(ClickEventArgs eventArgs)
1163 Extension?.OnClick(this, eventArgs);
1164 ClickEvent?.Invoke(this, eventArgs);
1167 private void OnIconRelayout(object sender, EventArgs e)
1174 /// ClickEventArgs is a class to record button click event arguments which will sent to user.
1176 /// <since_tizen> 6 </since_tizen>
1177 public class ClickEventArgs : EventArgs
1181 /// StateChangeEventArgs is a class to record button state change event arguments which will sent to user.
1183 /// <since_tizen> 6 </since_tizen>
1184 public class StateChangedEventArgs : EventArgs
1186 /// <summary> previous state of Button </summary>
1187 /// <since_tizen> 6 </since_tizen>
1188 public ControlStates PreviousState;
1189 /// <summary> current state of Button </summary>
1190 /// <since_tizen> 6 </since_tizen>
1191 public ControlStates CurrentState;
1195 /// Get current text part to the attached ButtonExtension.
1198 /// It returns null if the passed extension is invaild.
1200 /// <param name="extension">The extension instance that is currently attached to this Button.</param>
1201 /// <return>The button's text part.</return>
1202 [EditorBrowsable(EditorBrowsableState.Never)]
1203 public TextLabel GetCurrentText(ButtonExtension extension)
1205 return (extension == Extension) ? ButtonText : null;
1209 /// Get current icon part to the attached ButtonExtension.
1212 /// It returns null if the passed extension is invaild.
1214 /// <param name="extension">The extension instance that is currently attached to this Button.</param>
1215 /// <return>The button's icon part.</return>
1216 [EditorBrowsable(EditorBrowsableState.Never)]
1217 public ImageView GetCurrentIcon(ButtonExtension extension)
1219 return (extension == Extension) ? ButtonIcon : null;
1223 /// Get current overlay image part to the attached ButtonExtension.
1226 /// It returns null if the passed extension is invaild.
1228 /// <param name="extension">The extension instance that is currently attached to this Button.</param>
1229 /// <return>The button's overlay image part.</return>
1230 [EditorBrowsable(EditorBrowsableState.Never)]
1231 public ImageView GetCurrentOverlayImage(ButtonExtension extension)
1233 return (extension == Extension) ? ButtonOverlayImage : null;