2 * Copyright(c) 2022 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 IconRelativeOrientationProperty = BindableProperty.Create(nameof(IconRelativeOrientation), typeof(Button.IconOrientation?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
58 var buttonStyle = (ButtonStyle)bindable;
59 buttonStyle.iconRelativeOrientation = (Button.IconOrientation?)newValue;
61 defaultValueCreator: (bindable) =>
63 var buttonStyle = (ButtonStyle)bindable;
64 return buttonStyle.iconRelativeOrientation;
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 IconPaddingProperty = BindableProperty.Create(nameof(IconPadding), typeof(Extents), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
70 ((ButtonStyle)bindable).iconPadding = null == newValue ? null : new Extents((Extents)newValue);
72 defaultValueCreator: (bindable) =>
74 var buttonStyle = (ButtonStyle)bindable;
75 return buttonStyle.iconPadding;
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 TextPaddingProperty = BindableProperty.Create(nameof(TextPadding), typeof(Extents), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
81 ((ButtonStyle)bindable).textPadding = null == newValue ? null : new Extents((Extents)newValue);
83 defaultValueCreator: (bindable) =>
85 var buttonStyle = (ButtonStyle)bindable;
86 return buttonStyle.textPadding;
89 /// <summary> The bindable property of ItemAlignment. </summary>
90 [EditorBrowsable(EditorBrowsableState.Never)]
91 internal static readonly BindableProperty ItemAlignmentProperty = BindableProperty.Create(nameof(ItemAlignment), typeof(LinearLayout.Alignment?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
93 ((ButtonStyle)bindable).itemAlignment = (LinearLayout.Alignment?)newValue;
97 case LinearLayout.Alignment.Begin:
98 ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.Begin;
100 case LinearLayout.Alignment.End:
101 ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.End;
103 case LinearLayout.Alignment.CenterHorizontal:
104 ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.Center;
106 case LinearLayout.Alignment.Top:
107 ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Top;
109 case LinearLayout.Alignment.Bottom:
110 ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Bottom;
112 case LinearLayout.Alignment.CenterVertical:
113 ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Center;
115 case LinearLayout.Alignment.Center:
116 ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.Center;
117 ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Center;
123 defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemAlignment);
125 /// <summary> The bindable property of ItemHorizontalAlignment. </summary>
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 internal static readonly BindableProperty ItemHorizontalAlignmentProperty = BindableProperty.Create(nameof(ItemHorizontalAlignment), typeof(HorizontalAlignment?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
129 ((ButtonStyle)bindable).itemHorizontalAlignment = (HorizontalAlignment?)newValue;
131 defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemHorizontalAlignment);
133 /// <summary> The bindable property of ItemVerticalAlignment. </summary>
134 [EditorBrowsable(EditorBrowsableState.Never)]
135 internal static readonly BindableProperty ItemVerticalAlignmentProperty = BindableProperty.Create(nameof(ItemVerticalAlignment), typeof(VerticalAlignment?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
137 ((ButtonStyle)bindable).itemVerticalAlignment = (VerticalAlignment?)newValue;
139 defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemVerticalAlignment);
141 /// <summary> The bindable property of ItemSpacing. </summary>
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 internal static readonly BindableProperty ItemSpacingProperty = BindableProperty.Create(nameof(ItemSpacing), typeof(Size2D), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
145 ((ButtonStyle)bindable).itemSpacing = (Size2D)newValue;
147 defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemSpacing);
149 private bool? isSelectable;
150 private bool? isSelected;
151 private Button.IconOrientation? iconRelativeOrientation;
152 private Extents iconPadding;
153 private Extents textPadding;
154 private Size2D itemSpacing;
155 private LinearLayout.Alignment? itemAlignment;
156 private HorizontalAlignment? itemHorizontalAlignment;
157 private VerticalAlignment? itemVerticalAlignment;
159 static ButtonStyle() { }
162 /// Creates a new instance of a ButtonStyle.
164 /// <since_tizen> 8 </since_tizen>
165 public ButtonStyle() : base()
170 /// Creates a new instance of a ButtonStyle with style.
172 /// <param name="style">Create ButtonStyle by style customized by user.</param>
173 /// <since_tizen> 8 </since_tizen>
174 public ButtonStyle(ButtonStyle style) : base(style)
179 /// Overlay image's Style.
181 /// <since_tizen> 8 </since_tizen>
182 public ImageViewStyle Overlay { get; set; } = new ImageViewStyle();
187 /// <since_tizen> 8 </since_tizen>
188 public TextLabelStyle Text { get; set; } = new TextLabelStyle();
193 /// <since_tizen> 8 </since_tizen>
194 public ImageViewStyle Icon { get; set; } = new ImageViewStyle();
197 /// Flag to decide Button can be selected or not.
199 /// <since_tizen> 8 </since_tizen>
200 public bool? IsSelectable
202 get => (bool?)GetValue(IsSelectableProperty);
203 set => SetValue(IsSelectableProperty, value);
207 /// Flag to decide selected state in Button.
209 /// <since_tizen> 8 </since_tizen>
210 public bool? IsSelected
212 get => (bool?)GetValue(IsSelectedProperty);
213 set => SetValue(IsSelectedProperty, value);
217 /// Flag to decide button can be selected or not.
219 /// <since_tizen> 8 </since_tizen>
220 public new bool? IsEnabled
222 get => (bool?)base.IsEnabled;
225 base.IsEnabled = value;
230 /// Icon relative orientation.
232 /// <since_tizen> 8 </since_tizen>
233 public Button.IconOrientation? IconRelativeOrientation
235 get => (Button.IconOrientation?)GetValue(IconRelativeOrientationProperty);
236 set => SetValue(IconRelativeOrientationProperty, value);
240 /// Icon padding in Button. It is shortcut of Icon.Padding.
242 /// <since_tizen> 8 </since_tizen>
243 public Extents IconPadding
246 // When there are icon and text, the linear layout does not count padding.
247 get => ((Extents)GetValue(IconPaddingProperty)) ?? (iconPadding = new Extents());
248 set => SetValue(IconPaddingProperty, value);
252 /// Text padding in Button. It is shortcut of Text.Padding.
254 /// <since_tizen> 8 </since_tizen>
255 public Extents TextPadding
257 get => ((Extents)GetValue(TextPaddingProperty)) ?? (textPadding = new Extents());
258 set => SetValue(TextPaddingProperty, value);
262 /// The item (text or icon or both) alignment.
264 [EditorBrowsable(EditorBrowsableState.Never)]
265 public LinearLayout.Alignment? ItemAlignment
267 get => (LinearLayout.Alignment?)GetValue(ItemAlignmentProperty);
268 set => SetValue(ItemAlignmentProperty, value);
272 /// The item (text or icon or both) horizontal alignment.
274 [EditorBrowsable(EditorBrowsableState.Never)]
275 public HorizontalAlignment? ItemHorizontalAlignment
277 get => (HorizontalAlignment?)GetValue(ItemHorizontalAlignmentProperty);
278 set => SetValue(ItemHorizontalAlignmentProperty, value);
282 /// The item (text or icon or both) vertical alignment.
284 [EditorBrowsable(EditorBrowsableState.Never)]
285 public VerticalAlignment? ItemVerticalAlignment
287 get => (VerticalAlignment?)GetValue(ItemVerticalAlignmentProperty);
288 set => SetValue(ItemVerticalAlignmentProperty, value);
292 /// The space between icon and text.
293 /// The value is applied when there exist icon and text both.
294 /// The width value is used when the items are arranged horizontally. Otherwise, the height value is used.
296 [EditorBrowsable(EditorBrowsableState.Never)]
297 public Size2D ItemSpacing
299 get => (Size2D)GetValue(ItemSpacingProperty);
300 set => SetValue(ItemSpacingProperty, value);
304 /// <since_tizen> 8 </since_tizen>
305 public override void CopyFrom(BindableObject bindableObject)
307 base.CopyFrom(bindableObject);
309 if (bindableObject is ButtonStyle buttonStyle)
311 Overlay.CopyFrom(buttonStyle.Overlay);
312 Text.CopyFrom(buttonStyle.Text);
313 Icon.CopyFrom(buttonStyle.Icon);
318 /// Create corresponding ButtonExtension.
319 /// This is to be called by a Button.
320 /// You may override this function to customize button's behavior.
322 /// <return>The new ButtonExtension instance.</return>
323 [EditorBrowsable(EditorBrowsableState.Never)]
324 public virtual ButtonExtension CreateExtension()
330 /// Dispose ButtonStyle and all children on it.
332 /// <param name="disposing">true in order to free managed objects</param>
333 [EditorBrowsable(EditorBrowsableState.Never)]
334 protected override void Dispose(bool disposing)
338 iconPadding?.Dispose();
339 textPadding?.Dispose();
342 base.Dispose(disposing);