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.
17 using System.ComponentModel;
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Binding;
20 using Tizen.NUI.Components.Extension;
22 namespace Tizen.NUI.Components
25 /// ButtonStyle is a class which saves Button's ux data.
27 /// <since_tizen> 8 </since_tizen>
28 public class ButtonStyle : ControlStyle
30 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
31 [EditorBrowsable(EditorBrowsableState.Never)]
32 public static readonly BindableProperty IsSelectableProperty = BindableProperty.Create(nameof(IsSelectable), typeof(bool?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
34 var buttonStyle = (ButtonStyle)bindable;
35 buttonStyle.isSelectable = (bool?)newValue;
37 defaultValueCreator: (bindable) =>
39 var buttonStyle = (ButtonStyle)bindable;
40 return buttonStyle.isSelectable;
42 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
43 [EditorBrowsable(EditorBrowsableState.Never)]
44 public static readonly BindableProperty IsSelectedProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
46 var buttonStyle = (ButtonStyle)bindable;
47 buttonStyle.isSelected = (bool?)newValue;
49 defaultValueCreator: (bindable) =>
51 var buttonStyle = (ButtonStyle)bindable;
52 return buttonStyle.isSelected;
54 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
55 [EditorBrowsable(EditorBrowsableState.Never)]
56 public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
58 var buttonStyle = (ButtonStyle)bindable;
59 buttonStyle.isEnabled = (bool?)newValue;
61 defaultValueCreator: (bindable) =>
63 var buttonStyle = (ButtonStyle)bindable;
64 return buttonStyle.isEnabled;
66 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
67 [EditorBrowsable(EditorBrowsableState.Never)]
68 public static readonly BindableProperty IconRelativeOrientationProperty = BindableProperty.Create(nameof(IconRelativeOrientation), typeof(Button.IconOrientation?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
70 var buttonStyle = (ButtonStyle)bindable;
71 buttonStyle.iconRelativeOrientation = (Button.IconOrientation?)newValue;
73 defaultValueCreator: (bindable) =>
75 var buttonStyle = (ButtonStyle)bindable;
76 return buttonStyle.iconRelativeOrientation;
78 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
79 [EditorBrowsable(EditorBrowsableState.Never)]
80 public static readonly BindableProperty IconPaddingProperty = BindableProperty.Create(nameof(IconPadding), typeof(Extents), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
82 ((ButtonStyle)bindable).iconPadding = null == newValue ? null : new Extents((Extents)newValue);
84 defaultValueCreator: (bindable) =>
86 var buttonStyle = (ButtonStyle)bindable;
87 return buttonStyle.iconPadding;
89 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
90 [EditorBrowsable(EditorBrowsableState.Never)]
91 public static readonly BindableProperty TextPaddingProperty = BindableProperty.Create(nameof(TextPadding), typeof(Extents), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
93 ((ButtonStyle)bindable).textPadding = null == newValue ? null : new Extents((Extents)newValue);
95 defaultValueCreator: (bindable) =>
97 var buttonStyle = (ButtonStyle)bindable;
98 return buttonStyle.textPadding;
101 private bool? isSelectable;
102 private bool? isSelected;
103 private bool? isEnabled;
104 private Button.IconOrientation? iconRelativeOrientation;
105 private Extents iconPadding;
106 private Extents textPadding;
108 static ButtonStyle() { }
111 /// Creates a new instance of a ButtonStyle.
113 /// <since_tizen> 8 </since_tizen>
114 public ButtonStyle() : base()
119 /// Creates a new instance of a ButtonStyle with style.
121 /// <param name="style">Create ButtonStyle by style customized by user.</param>
122 /// <since_tizen> 8 </since_tizen>
123 public ButtonStyle(ButtonStyle style) : base(style)
128 /// Overlay image's Style.
130 /// <since_tizen> 8 </since_tizen>
131 public ImageViewStyle Overlay { get; set; } = new ImageViewStyle();
136 /// <since_tizen> 8 </since_tizen>
137 public TextLabelStyle Text { get; set; } = new TextLabelStyle();
142 /// <since_tizen> 8 </since_tizen>
143 public ImageViewStyle Icon { get; set; } = new ImageViewStyle();
146 /// Flag to decide Button can be selected or not.
148 /// <since_tizen> 8 </since_tizen>
149 public bool? IsSelectable
151 get => (bool?)GetValue(IsSelectableProperty);
152 set => SetValue(IsSelectableProperty, value);
156 /// Flag to decide selected state in Button.
158 /// <since_tizen> 8 </since_tizen>
159 public bool? IsSelected
161 get => (bool?)GetValue(IsSelectedProperty);
162 set => SetValue(IsSelectedProperty, value);
166 /// Flag to decide button can be selected or not.
168 /// <since_tizen> 8 </since_tizen>
169 public bool? IsEnabled
171 get => (bool?)GetValue(IsEnabledProperty);
172 set => SetValue(IsEnabledProperty, value);
176 /// Icon relative orientation.
178 /// <since_tizen> 8 </since_tizen>
179 public Button.IconOrientation? IconRelativeOrientation
181 get => (Button.IconOrientation?)GetValue(IconRelativeOrientationProperty);
182 set => SetValue(IconRelativeOrientationProperty, value);
186 /// Icon padding in Button, work only when show icon and text.
188 /// <since_tizen> 8 </since_tizen>
189 public Extents IconPadding
191 get => ((Extents)GetValue(IconPaddingProperty)) ?? (iconPadding = new Extents());
192 set => SetValue(IconPaddingProperty, value);
196 /// Text padding in Button, work only when show icon and text.
198 /// <since_tizen> 8 </since_tizen>
199 public Extents TextPadding
201 get => ((Extents)GetValue(TextPaddingProperty)) ?? (textPadding = new Extents());
202 set => SetValue(TextPaddingProperty, value);
206 /// Style's clone function.
208 /// <param name="bindableObject">The style that need to copy.</param>
209 /// <since_tizen> 8 </since_tizen>
210 public override void CopyFrom(BindableObject bindableObject)
212 base.CopyFrom(bindableObject);
214 if (bindableObject is ButtonStyle buttonStyle)
216 Overlay.CopyFrom(buttonStyle.Overlay);
217 Text.CopyFrom(buttonStyle.Text);
218 Icon.CopyFrom(buttonStyle.Icon);
223 /// Create corresponding ButtonExtension.
224 /// This is to be called by a Button.
225 /// You may override this function to customize button's behavior.
227 /// <return>The new ButtonExtension instance.</return>
228 [EditorBrowsable(EditorBrowsableState.Never)]
229 public virtual ButtonExtension CreateExtension()
235 /// Dispose ButtonStyle and all children on it.
237 /// <param name="type">Dispose type.</param>
238 [EditorBrowsable(EditorBrowsableState.Never)]
239 protected override void Dispose(DisposeTypes type)
246 if (type == DisposeTypes.Explicit)
248 iconPadding?.Dispose();
249 textPadding?.Dispose();