Replace duplicate documentation of CopyFrom with inheritdoc
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Style / ButtonStyle.cs
1 /*
2  * Copyright(c) 2019 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 IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
57         {
58             var buttonStyle = (ButtonStyle)bindable;
59             buttonStyle.isEnabled = (bool?)newValue;
60         },
61         defaultValueCreator: (bindable) =>
62         {
63             var buttonStyle = (ButtonStyle)bindable;
64             return buttonStyle.isEnabled;
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 IconRelativeOrientationProperty = BindableProperty.Create(nameof(IconRelativeOrientation), typeof(Button.IconOrientation?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
69         {
70             var buttonStyle = (ButtonStyle)bindable;
71             buttonStyle.iconRelativeOrientation = (Button.IconOrientation?)newValue;
72         },
73         defaultValueCreator: (bindable) =>
74         {
75             var buttonStyle = (ButtonStyle)bindable;
76             return buttonStyle.iconRelativeOrientation;
77         });
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) =>
81         {
82             ((ButtonStyle)bindable).iconPadding = null == newValue ? null : new Extents((Extents)newValue);
83         },
84         defaultValueCreator: (bindable) =>
85         {
86             var buttonStyle = (ButtonStyle)bindable;
87             return buttonStyle.iconPadding;
88         });
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) =>
92         {
93             ((ButtonStyle)bindable).textPadding = null == newValue ? null : new Extents((Extents)newValue);
94         },
95         defaultValueCreator: (bindable) =>
96         {
97             var buttonStyle = (ButtonStyle)bindable;
98             return buttonStyle.textPadding;
99         });
100
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) =>
104         {
105             ((ButtonStyle)bindable).itemAlignment = (LinearLayout.Alignment?)newValue;
106         },
107         defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemAlignment);
108
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) =>
112         {
113             ((ButtonStyle)bindable).itemSpacing = (Size2D)newValue;
114         },
115         defaultValueCreator: (bindable) => ((ButtonStyle)bindable).itemSpacing);
116
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;
125
126         static ButtonStyle() { }
127
128         /// <summary>
129         /// Creates a new instance of a ButtonStyle.
130         /// </summary>
131         /// <since_tizen> 8 </since_tizen>
132         public ButtonStyle() : base()
133         {
134         }
135
136         /// <summary>
137         /// Creates a new instance of a ButtonStyle with style.
138         /// </summary>
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)
142         {
143         }
144
145         /// <summary>
146         /// Overlay image's Style.
147         /// </summary>
148         /// <since_tizen> 8 </since_tizen>
149         public ImageViewStyle Overlay { get; set; } = new ImageViewStyle();
150
151         /// <summary>
152         /// Text's Style.
153         /// </summary>
154         /// <since_tizen> 8 </since_tizen>
155         public TextLabelStyle Text { get; set; } = new TextLabelStyle();
156
157         /// <summary>
158         /// Icon's Style.
159         /// </summary>
160         /// <since_tizen> 8 </since_tizen>
161         public ImageViewStyle Icon { get; set; } = new ImageViewStyle();
162
163         /// <summary>
164         /// Flag to decide Button can be selected or not.
165         /// </summary>
166         /// <since_tizen> 8 </since_tizen>
167         public bool? IsSelectable
168         {
169             get => (bool?)GetValue(IsSelectableProperty);
170             set => SetValue(IsSelectableProperty, value);
171         }
172
173         /// <summary>
174         /// Flag to decide selected state in Button.
175         /// </summary>
176         /// <since_tizen> 8 </since_tizen>
177         public bool? IsSelected
178         {
179             get => (bool?)GetValue(IsSelectedProperty);
180             set => SetValue(IsSelectedProperty, value);
181         }
182
183         /// <summary>
184         /// Flag to decide button can be selected or not.
185         /// </summary>
186         /// <since_tizen> 8 </since_tizen>
187         public bool? IsEnabled
188         {
189             get => (bool?)GetValue(IsEnabledProperty);
190             set => SetValue(IsEnabledProperty, value);
191         }
192
193         /// <summary>
194         /// Icon relative orientation.
195         /// </summary>
196         /// <since_tizen> 8 </since_tizen>
197         public Button.IconOrientation? IconRelativeOrientation
198         {
199             get => (Button.IconOrientation?)GetValue(IconRelativeOrientationProperty);
200             set => SetValue(IconRelativeOrientationProperty, value);
201         }
202
203         /// <summary>
204         /// Icon padding in Button. It is shortcut of Icon.Padding.
205         /// </summary>
206         /// <since_tizen> 8 </since_tizen>
207         public Extents IconPadding
208         {
209             // TODO Fixme
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);
213         }
214
215         /// <summary>
216         /// Text padding in Button. It is shortcut of Text.Padding.
217         /// </summary>
218         /// <since_tizen> 8 </since_tizen>
219         public Extents TextPadding
220         {
221             get => ((Extents)GetValue(TextPaddingProperty)) ?? (textPadding = new Extents());
222             set => SetValue(TextPaddingProperty, value);
223         }
224
225         /// <summary>
226         /// The item (text or icon or both) alignment.
227         /// </summary>
228         [EditorBrowsable(EditorBrowsableState.Never)]
229         public LinearLayout.Alignment? ItemAlignment
230         {
231             get => (LinearLayout.Alignment?)GetValue(ItemAlignmentProperty);
232             set => SetValue(ItemAlignmentProperty, value);
233         }
234
235         /// <summary>
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.
239         /// </summary>
240         [EditorBrowsable(EditorBrowsableState.Never)]
241         public Size2D ItemSpacing
242         {
243             get => (Size2D)GetValue(ItemSpacingProperty);
244             set => SetValue(ItemSpacingProperty, value);
245         }
246
247         /// <inheritdoc/>
248         /// <since_tizen> 8 </since_tizen>
249         public override void CopyFrom(BindableObject bindableObject)
250         {
251             base.CopyFrom(bindableObject);
252
253             if (bindableObject is ButtonStyle buttonStyle)
254             {
255                 Overlay.CopyFrom(buttonStyle.Overlay);
256                 Text.CopyFrom(buttonStyle.Text);
257                 Icon.CopyFrom(buttonStyle.Icon);
258             }
259         }
260
261         /// <summary>
262         /// Create corresponding ButtonExtension.
263         /// This is to be called by a Button.
264         /// You may override this function to customize button's behavior.
265         /// </summary>
266         /// <return>The new ButtonExtension instance.</return>
267         [EditorBrowsable(EditorBrowsableState.Never)]
268         public virtual ButtonExtension CreateExtension()
269         {
270             return null;
271         }
272
273         /// <summary>
274         /// Dispose ButtonStyle and all children on it.
275         /// </summary>
276         /// <param name="disposing">true in order to free managed objects</param>
277         [EditorBrowsable(EditorBrowsableState.Never)]
278         protected override void Dispose(bool disposing)
279         {
280             if (disposing)
281             {
282                 iconPadding?.Dispose();
283                 textPadding?.Dispose();
284             }
285
286             base.Dispose(disposing);
287         }
288     }
289 }