Follow formatting NUI
[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         private bool? isSelectable;
102         private bool? isSelected;
103         private bool? isEnabled;
104         private Button.IconOrientation? iconRelativeOrientation;
105         private Extents iconPadding;
106         private Extents textPadding;
107
108         static ButtonStyle() { }
109
110         /// <summary>
111         /// Creates a new instance of a ButtonStyle.
112         /// </summary>
113         /// <since_tizen> 8 </since_tizen>
114         public ButtonStyle() : base()
115         {
116         }
117
118         /// <summary>
119         /// Creates a new instance of a ButtonStyle with style.
120         /// </summary>
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)
124         {
125         }
126
127         /// <summary>
128         /// Overlay image's Style.
129         /// </summary>
130         /// <since_tizen> 8 </since_tizen>
131         public ImageViewStyle Overlay { get; set; } = new ImageViewStyle();
132
133         /// <summary>
134         /// Text's Style.
135         /// </summary>
136         /// <since_tizen> 8 </since_tizen>
137         public TextLabelStyle Text { get; set; } = new TextLabelStyle();
138
139         /// <summary>
140         /// Icon's Style.
141         /// </summary>
142         /// <since_tizen> 8 </since_tizen>
143         public ImageViewStyle Icon { get; set; } = new ImageViewStyle();
144
145         /// <summary>
146         /// Flag to decide Button can be selected or not.
147         /// </summary>
148         /// <since_tizen> 8 </since_tizen>
149         public bool? IsSelectable
150         {
151             get => (bool?)GetValue(IsSelectableProperty);
152             set => SetValue(IsSelectableProperty, value);
153         }
154
155         /// <summary>
156         /// Flag to decide selected state in Button.
157         /// </summary>
158         /// <since_tizen> 8 </since_tizen>
159         public bool? IsSelected
160         {
161             get => (bool?)GetValue(IsSelectedProperty);
162             set => SetValue(IsSelectedProperty, value);
163         }
164
165         /// <summary>
166         /// Flag to decide button can be selected or not.
167         /// </summary>
168         /// <since_tizen> 8 </since_tizen>
169         public bool? IsEnabled
170         {
171             get => (bool?)GetValue(IsEnabledProperty);
172             set => SetValue(IsEnabledProperty, value);
173         }
174
175         /// <summary>
176         /// Icon relative orientation.
177         /// </summary>
178         /// <since_tizen> 8 </since_tizen>
179         public Button.IconOrientation? IconRelativeOrientation
180         {
181             get => (Button.IconOrientation?)GetValue(IconRelativeOrientationProperty);
182             set => SetValue(IconRelativeOrientationProperty, value);
183         }
184
185         /// <summary>
186         /// Icon padding in Button, work only when show icon and text.
187         /// </summary>
188         /// <since_tizen> 8 </since_tizen>
189         public Extents IconPadding
190         {
191             get => ((Extents)GetValue(IconPaddingProperty)) ?? (iconPadding = new Extents());
192             set => SetValue(IconPaddingProperty, value);
193         }
194
195         /// <summary>
196         /// Text padding in Button, work only when show icon and text.
197         /// </summary>
198         /// <since_tizen> 8 </since_tizen>
199         public Extents TextPadding
200         {
201             get => ((Extents)GetValue(TextPaddingProperty)) ?? (textPadding = new Extents());
202             set => SetValue(TextPaddingProperty, value);
203         }
204
205         /// <summary>
206         /// Style's clone function.
207         /// </summary>
208         /// <param name="bindableObject">The style that need to copy.</param>
209         /// <since_tizen> 8 </since_tizen>
210         public override void CopyFrom(BindableObject bindableObject)
211         {
212             base.CopyFrom(bindableObject);
213
214             if (bindableObject is ButtonStyle buttonStyle)
215             {
216                 Overlay.CopyFrom(buttonStyle.Overlay);
217                 Text.CopyFrom(buttonStyle.Text);
218                 Icon.CopyFrom(buttonStyle.Icon);
219             }
220         }
221
222         /// <summary>
223         /// Create corresponding ButtonExtension.
224         /// This is to be called by a Button.
225         /// You may override this function to customize button's behavior.
226         /// </summary>
227         /// <return>The new ButtonExtension instance.</return>
228         [EditorBrowsable(EditorBrowsableState.Never)]
229         public virtual ButtonExtension CreateExtension()
230         {
231             return null;
232         }
233
234         /// <summary>
235         /// Dispose ButtonStyle and all children on it.
236         /// </summary>
237         /// <param name="type">Dispose type.</param>
238         [EditorBrowsable(EditorBrowsableState.Never)]
239         protected override void Dispose(DisposeTypes type)
240         {
241             if (disposed)
242             {
243                 return;
244             }
245
246             if (type == DisposeTypes.Explicit)
247             {
248                 iconPadding?.Dispose();
249                 textPadding?.Dispose();
250             }
251
252             base.Dispose(type);
253         }
254     }
255 }