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 /// <summary> The bindable property of ItemAlignment. </summary>
102 [EditorBrowsable(EditorBrowsableState.Never)]
103 internal static readonly BindableProperty ItemAlignmentProperty = BindableProperty.Create(nameof(ItemAlignment), typeof(LinearLayout.Alignment?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
105 ((ButtonStyle)bindable).itemAlignment = (LinearLayout.Alignment?)newValue;
107 defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemAlignment);
109 /// <summary> The bindable property of ItemSpacing. </summary>
110 [EditorBrowsable(EditorBrowsableState.Never)]
111 internal static readonly BindableProperty ItemSpacingProperty = BindableProperty.Create(nameof(ItemSpacing), typeof(Size2D), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
113 ((ButtonStyle)bindable).itemSpacing = (Size2D)newValue;
115 defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemSpacing);
117 private bool? isSelectable;
118 private bool? isSelected;
119 private bool? isEnabled;
120 private Button.IconOrientation? iconRelativeOrientation;
121 private Extents iconPadding;
122 private Extents textPadding;
123 private Size2D itemSpacing;
124 private LinearLayout.Alignment? itemAlignment;
126 static ButtonStyle() { }
129 /// Creates a new instance of a ButtonStyle.
131 /// <since_tizen> 8 </since_tizen>
132 public ButtonStyle() : base()
137 /// Creates a new instance of a ButtonStyle with style.
139 /// <param name="style">Create ButtonStyle by style customized by user.</param>
140 /// <since_tizen> 8 </since_tizen>
141 public ButtonStyle(ButtonStyle style) : base(style)
146 /// Overlay image's Style.
148 /// <since_tizen> 8 </since_tizen>
149 public ImageViewStyle Overlay { get; set; } = new ImageViewStyle();
154 /// <since_tizen> 8 </since_tizen>
155 public TextLabelStyle Text { get; set; } = new TextLabelStyle();
160 /// <since_tizen> 8 </since_tizen>
161 public ImageViewStyle Icon { get; set; } = new ImageViewStyle();
164 /// Flag to decide Button can be selected or not.
166 /// <since_tizen> 8 </since_tizen>
167 public bool? IsSelectable
169 get => (bool?)GetValue(IsSelectableProperty);
170 set => SetValue(IsSelectableProperty, value);
174 /// Flag to decide selected state in Button.
176 /// <since_tizen> 8 </since_tizen>
177 public bool? IsSelected
179 get => (bool?)GetValue(IsSelectedProperty);
180 set => SetValue(IsSelectedProperty, value);
184 /// Flag to decide button can be selected or not.
186 /// <since_tizen> 8 </since_tizen>
187 public bool? IsEnabled
189 get => (bool?)GetValue(IsEnabledProperty);
190 set => SetValue(IsEnabledProperty, value);
194 /// Icon relative orientation.
196 /// <since_tizen> 8 </since_tizen>
197 public Button.IconOrientation? IconRelativeOrientation
199 get => (Button.IconOrientation?)GetValue(IconRelativeOrientationProperty);
200 set => SetValue(IconRelativeOrientationProperty, value);
204 /// Icon padding in Button. It is shortcut of Icon.Padding.
206 /// <since_tizen> 8 </since_tizen>
207 public Extents IconPadding
210 // When there are icon and text, the linear layout does not count padding.
211 get => ((Extents)GetValue(IconPaddingProperty)) ?? (iconPadding = new Extents());
212 set => SetValue(IconPaddingProperty, value);
216 /// Text padding in Button. It is shortcut of Text.Padding.
218 /// <since_tizen> 8 </since_tizen>
219 public Extents TextPadding
221 get => ((Extents)GetValue(TextPaddingProperty)) ?? (textPadding = new Extents());
222 set => SetValue(TextPaddingProperty, value);
226 /// The item (text or icon or both) alignment.
228 [EditorBrowsable(EditorBrowsableState.Never)]
229 public LinearLayout.Alignment? ItemAlignment
231 get => (LinearLayout.Alignment?)GetValue(ItemAlignmentProperty);
232 set => SetValue(ItemAlignmentProperty, value);
236 /// The space between icon and text.
237 /// The value is applied when there exist icon and text both.
238 /// The width value is used when the items are arranged horizontally. Otherwise, the height value is used.
240 [EditorBrowsable(EditorBrowsableState.Never)]
241 public Size2D ItemSpacing
243 get => (Size2D)GetValue(ItemSpacingProperty);
244 set => SetValue(ItemSpacingProperty, value);
248 /// <since_tizen> 8 </since_tizen>
249 public override void CopyFrom(BindableObject bindableObject)
251 base.CopyFrom(bindableObject);
253 if (bindableObject is ButtonStyle buttonStyle)
255 Overlay.CopyFrom(buttonStyle.Overlay);
256 Text.CopyFrom(buttonStyle.Text);
257 Icon.CopyFrom(buttonStyle.Icon);
262 /// Create corresponding ButtonExtension.
263 /// This is to be called by a Button.
264 /// You may override this function to customize button's behavior.
266 /// <return>The new ButtonExtension instance.</return>
267 [EditorBrowsable(EditorBrowsableState.Never)]
268 public virtual ButtonExtension CreateExtension()
274 /// Dispose ButtonStyle and all children on it.
276 /// <param name="disposing">true in order to free managed objects</param>
277 [EditorBrowsable(EditorBrowsableState.Never)]
278 protected override void Dispose(bool disposing)
282 iconPadding?.Dispose();
283 textPadding?.Dispose();
286 base.Dispose(disposing);