[NUI][AT-SPI] Add IAtspiTable and IAtspiTableCell interfaces (#5305)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Style / ButtonStyle.cs
1 /*
2  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System.ComponentModel;
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Binding;
20 using Tizen.NUI.Components.Extension;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// ButtonStyle is a class which saves Button's ux data.
26     /// </summary>
27     /// <since_tizen> 8 </since_tizen>
28     public class ButtonStyle : ControlStyle
29     {
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) =>
33         {
34             var buttonStyle = (ButtonStyle)bindable;
35             buttonStyle.isSelectable = (bool?)newValue;
36         },
37         defaultValueCreator: (bindable) =>
38         {
39             var buttonStyle = (ButtonStyle)bindable;
40             return buttonStyle.isSelectable;
41         });
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) =>
45         {
46             var buttonStyle = (ButtonStyle)bindable;
47             buttonStyle.isSelected = (bool?)newValue;
48         },
49         defaultValueCreator: (bindable) =>
50         {
51             var buttonStyle = (ButtonStyle)bindable;
52             return buttonStyle.isSelected;
53         });
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) =>
57         {
58             var buttonStyle = (ButtonStyle)bindable;
59             buttonStyle.iconRelativeOrientation = (Button.IconOrientation?)newValue;
60         },
61         defaultValueCreator: (bindable) =>
62         {
63             var buttonStyle = (ButtonStyle)bindable;
64             return buttonStyle.iconRelativeOrientation;
65         });
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) =>
69         {
70             ((ButtonStyle)bindable).iconPadding = null == newValue ? null : new Extents((Extents)newValue);
71         },
72         defaultValueCreator: (bindable) =>
73         {
74             var buttonStyle = (ButtonStyle)bindable;
75             return buttonStyle.iconPadding;
76         });
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) =>
80         {
81             ((ButtonStyle)bindable).textPadding = null == newValue ? null : new Extents((Extents)newValue);
82         },
83         defaultValueCreator: (bindable) =>
84         {
85             var buttonStyle = (ButtonStyle)bindable;
86             return buttonStyle.textPadding;
87         });
88
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) =>
92         {
93             ((ButtonStyle)bindable).itemAlignment = (LinearLayout.Alignment?)newValue;
94
95             switch (newValue)
96             {
97                 case LinearLayout.Alignment.Begin:
98                     ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.Begin;
99                     break;
100                 case LinearLayout.Alignment.End:
101                     ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.End;
102                     break;
103                 case LinearLayout.Alignment.CenterHorizontal:
104                     ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.Center;
105                     break;
106                 case LinearLayout.Alignment.Top:
107                     ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Top;
108                     break;
109                 case LinearLayout.Alignment.Bottom:
110                     ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Bottom;
111                     break;
112                 case LinearLayout.Alignment.CenterVertical:
113                     ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Center;
114                     break;
115                 case LinearLayout.Alignment.Center:
116                     ((ButtonStyle)bindable).itemHorizontalAlignment = HorizontalAlignment.Center;
117                     ((ButtonStyle)bindable).itemVerticalAlignment = VerticalAlignment.Center;
118                     break;
119                 default:
120                     break;
121             }
122         },
123         defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemAlignment);
124
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) =>
128         {
129             ((ButtonStyle)bindable).itemHorizontalAlignment = (HorizontalAlignment?)newValue;
130         },
131         defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemHorizontalAlignment);
132
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) =>
136         {
137             ((ButtonStyle)bindable).itemVerticalAlignment = (VerticalAlignment?)newValue;
138         },
139         defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemVerticalAlignment);
140
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) =>
144         {
145             ((ButtonStyle)bindable).itemSpacing = (Size2D)newValue;
146         },
147         defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemSpacing);
148
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;
158
159         static ButtonStyle() { }
160
161         /// <summary>
162         /// Creates a new instance of a ButtonStyle.
163         /// </summary>
164         /// <since_tizen> 8 </since_tizen>
165         public ButtonStyle() : base()
166         {
167         }
168
169         /// <summary>
170         /// Creates a new instance of a ButtonStyle with style.
171         /// </summary>
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)
175         {
176         }
177
178         /// <summary>
179         /// Overlay image's Style.
180         /// </summary>
181         /// <since_tizen> 8 </since_tizen>
182         public ImageViewStyle Overlay { get; set; } = new ImageViewStyle();
183
184         /// <summary>
185         /// Text's Style.
186         /// </summary>
187         /// <since_tizen> 8 </since_tizen>
188         public TextLabelStyle Text { get; set; } = new TextLabelStyle();
189
190         /// <summary>
191         /// Icon's Style.
192         /// </summary>
193         /// <since_tizen> 8 </since_tizen>
194         public ImageViewStyle Icon { get; set; } = new ImageViewStyle();
195
196         /// <summary>
197         /// Flag to decide Button can be selected or not.
198         /// </summary>
199         /// <since_tizen> 8 </since_tizen>
200         public bool? IsSelectable
201         {
202             get => (bool?)GetValue(IsSelectableProperty);
203             set => SetValue(IsSelectableProperty, value);
204         }
205
206         /// <summary>
207         /// Flag to decide selected state in Button.
208         /// </summary>
209         /// <since_tizen> 8 </since_tizen>
210         public bool? IsSelected
211         {
212             get => (bool?)GetValue(IsSelectedProperty);
213             set => SetValue(IsSelectedProperty, value);
214         }
215
216         /// <summary>
217         /// Flag to decide button can be selected or not.
218         /// </summary>
219         /// <since_tizen> 8 </since_tizen>
220         public new bool? IsEnabled
221         {
222             get => (bool?)base.IsEnabled;
223             set
224             {
225                 base.IsEnabled = value;
226             }
227         }
228
229         /// <summary>
230         /// Icon relative orientation.
231         /// </summary>
232         /// <since_tizen> 8 </since_tizen>
233         public Button.IconOrientation? IconRelativeOrientation
234         {
235             get => (Button.IconOrientation?)GetValue(IconRelativeOrientationProperty);
236             set => SetValue(IconRelativeOrientationProperty, value);
237         }
238
239         /// <summary>
240         /// Icon padding in Button. It is shortcut of Icon.Padding.
241         /// </summary>
242         /// <since_tizen> 8 </since_tizen>
243         public Extents IconPadding
244         {
245             // TODO Fixme
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);
249         }
250
251         /// <summary>
252         /// Text padding in Button. It is shortcut of Text.Padding.
253         /// </summary>
254         /// <since_tizen> 8 </since_tizen>
255         public Extents TextPadding
256         {
257             get => ((Extents)GetValue(TextPaddingProperty)) ?? (textPadding = new Extents());
258             set => SetValue(TextPaddingProperty, value);
259         }
260
261         /// <summary>
262         /// The item (text or icon or both) alignment.
263         /// </summary>
264         [EditorBrowsable(EditorBrowsableState.Never)]
265         public LinearLayout.Alignment? ItemAlignment
266         {
267             get => (LinearLayout.Alignment?)GetValue(ItemAlignmentProperty);
268             set => SetValue(ItemAlignmentProperty, value);
269         }
270
271         /// <summary>
272         /// The item (text or icon or both) horizontal alignment.
273         /// </summary>
274         [EditorBrowsable(EditorBrowsableState.Never)]
275         public HorizontalAlignment? ItemHorizontalAlignment
276         {
277             get => (HorizontalAlignment?)GetValue(ItemHorizontalAlignmentProperty);
278             set => SetValue(ItemHorizontalAlignmentProperty, value);
279         }
280
281         /// <summary>
282         /// The item (text or icon or both) vertical alignment.
283         /// </summary>
284         [EditorBrowsable(EditorBrowsableState.Never)]
285         public VerticalAlignment? ItemVerticalAlignment
286         {
287             get => (VerticalAlignment?)GetValue(ItemVerticalAlignmentProperty);
288             set => SetValue(ItemVerticalAlignmentProperty, value);
289         }
290
291         /// <summary>
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.
295         /// </summary>
296         [EditorBrowsable(EditorBrowsableState.Never)]
297         public Size2D ItemSpacing
298         {
299             get => (Size2D)GetValue(ItemSpacingProperty);
300             set => SetValue(ItemSpacingProperty, value);
301         }
302
303         /// <inheritdoc/>
304         /// <since_tizen> 8 </since_tizen>
305         public override void CopyFrom(BindableObject bindableObject)
306         {
307             base.CopyFrom(bindableObject);
308
309             if (bindableObject is ButtonStyle buttonStyle)
310             {
311                 Overlay.CopyFrom(buttonStyle.Overlay);
312                 Text.CopyFrom(buttonStyle.Text);
313                 Icon.CopyFrom(buttonStyle.Icon);
314             }
315         }
316
317         /// <summary>
318         /// Create corresponding ButtonExtension.
319         /// This is to be called by a Button.
320         /// You may override this function to customize button's behavior.
321         /// </summary>
322         /// <return>The new ButtonExtension instance.</return>
323         [EditorBrowsable(EditorBrowsableState.Never)]
324         public virtual ButtonExtension CreateExtension()
325         {
326             return null;
327         }
328
329         /// <summary>
330         /// Dispose ButtonStyle and all children on it.
331         /// </summary>
332         /// <param name="disposing">true in order to free managed objects</param>
333         [EditorBrowsable(EditorBrowsableState.Never)]
334         protected override void Dispose(bool disposing)
335         {
336             if (disposing)
337             {
338                 iconPadding?.Dispose();
339                 textPadding?.Dispose();
340             }
341
342             base.Dispose(disposing);
343         }
344     }
345 }