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.Collections.Generic;
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.Components
25 /// ButtonAttributes is a class which saves Button's ux data.
27 /// <since_tizen> 6 </since_tizen>
28 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public class ButtonStyle : ControlStyle
32 private bool? isSelectable;
33 private bool? isSelected;
34 private bool? isEnabled;
35 private Button.IconOrientation? iconRelativeOrientation;
36 private Extents iconPadding;
37 private Extents textPadding;
39 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
40 [EditorBrowsable(EditorBrowsableState.Never)]
41 public static readonly BindableProperty IsSelectableProperty = BindableProperty.Create(nameof(IsSelectable), typeof(bool?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
43 var buttonStyle = (ButtonStyle)bindable;
44 buttonStyle.isSelectable = (bool?)newValue;
46 defaultValueCreator: (bindable) =>
48 var buttonStyle = (ButtonStyle)bindable;
49 return buttonStyle.isSelectable;
51 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
52 [EditorBrowsable(EditorBrowsableState.Never)]
53 public static readonly BindableProperty IsSelectedProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
55 var buttonStyle = (ButtonStyle)bindable;
56 buttonStyle.isSelected = (bool?)newValue;
58 defaultValueCreator: (bindable) =>
60 var buttonStyle = (ButtonStyle)bindable;
61 return buttonStyle.isSelected;
63 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
67 var buttonStyle = (ButtonStyle)bindable;
68 buttonStyle.isEnabled = (bool?)newValue;
70 defaultValueCreator: (bindable) =>
72 var buttonStyle = (ButtonStyle)bindable;
73 return buttonStyle.isEnabled;
75 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
76 [EditorBrowsable(EditorBrowsableState.Never)]
77 public static readonly BindableProperty IconRelativeOrientationProperty = BindableProperty.Create(nameof(IconRelativeOrientation), typeof(Button.IconOrientation?), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
79 var buttonStyle = (ButtonStyle)bindable;
80 buttonStyle.iconRelativeOrientation = (Button.IconOrientation?)newValue;
82 defaultValueCreator: (bindable) =>
84 var buttonStyle = (ButtonStyle)bindable;
85 return buttonStyle.iconRelativeOrientation;
87 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 public static readonly BindableProperty IconPaddingProperty = BindableProperty.Create(nameof(IconPadding), typeof(Extents), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
91 var buttonStyle = (ButtonStyle)bindable;
92 buttonStyle.iconPadding = (Extents)newValue;
94 defaultValueCreator: (bindable) =>
96 var buttonStyle = (ButtonStyle)bindable;
97 return buttonStyle.iconPadding;
99 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
100 [EditorBrowsable(EditorBrowsableState.Never)]
101 public static readonly BindableProperty TextPaddingProperty = BindableProperty.Create(nameof(TextPadding), typeof(Extents), typeof(ButtonStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
103 var buttonStyle = (ButtonStyle)bindable;
104 buttonStyle.textPadding = (Extents)newValue;
106 defaultValueCreator: (bindable) =>
108 var buttonStyle = (ButtonStyle)bindable;
109 return buttonStyle.textPadding;
112 static ButtonStyle() { }
115 /// Creates a new instance of a ButtonStyle.
117 /// <since_tizen> 6 </since_tizen>
118 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
119 [EditorBrowsable(EditorBrowsableState.Never)]
120 public ButtonStyle() : base()
126 /// Creates a new instance of a ButtonStyle with style.
128 /// <param name="style">Create ButtonStyle by style customized by user.</param>
129 /// <since_tizen> 6 </since_tizen>
130 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public ButtonStyle(ButtonStyle style) : base(style)
141 this.CopyFrom(style);
144 /// Overlay image's Style.
146 /// <since_tizen> 6 </since_tizen>
147 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
148 [EditorBrowsable(EditorBrowsableState.Never)]
149 public ImageViewStyle Overlay { get; set; }
154 /// <since_tizen> 6 </since_tizen>
155 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
156 [EditorBrowsable(EditorBrowsableState.Never)]
157 public TextLabelStyle Text { get; set; }
162 /// <since_tizen> 6 </since_tizen>
163 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
164 [EditorBrowsable(EditorBrowsableState.Never)]
165 public ImageControlStyle Icon { get; set; }
167 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
168 [EditorBrowsable(EditorBrowsableState.Never)]
169 public bool? IsSelectable
171 get => (bool?)GetValue(IsSelectableProperty);
172 set => SetValue(IsSelectableProperty, value);
175 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
176 [EditorBrowsable(EditorBrowsableState.Never)]
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> 6 </since_tizen>
187 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
188 [EditorBrowsable(EditorBrowsableState.Never)]
189 public bool? IsEnabled
191 get => (bool?)GetValue(IsEnabledProperty);
192 set => SetValue(IsEnabledProperty, value);
196 /// Icon relative orientation.
198 /// <since_tizen> 6 </since_tizen>
199 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
200 [EditorBrowsable(EditorBrowsableState.Never)]
201 public Button.IconOrientation? IconRelativeOrientation
203 get => (Button.IconOrientation?)GetValue(IconRelativeOrientationProperty);
204 set => SetValue(IconRelativeOrientationProperty, value);
207 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
208 [EditorBrowsable(EditorBrowsableState.Never)]
209 public Extents IconPadding
213 Extents padding = (Extents)GetValue(IconPaddingProperty);
214 return (null != padding) ? padding : new Extents((ushort start, ushort end, ushort top, ushort bottom) => { IconPadding = new Extents(start, end, top, bottom); }, 0, 0, 0, 0);
216 set => SetValue(IconPaddingProperty, value);
219 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
220 [EditorBrowsable(EditorBrowsableState.Never)]
221 public Extents TextPadding
225 Extents padding = (Extents)GetValue(TextPaddingProperty);
226 return (null != padding) ? padding : new Extents((ushort start, ushort end, ushort top, ushort bottom) => { TextPadding = new Extents(start, end, top, bottom); }, 0, 0, 0, 0);
228 set => SetValue(TextPaddingProperty, value);
231 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
232 [EditorBrowsable(EditorBrowsableState.Never)]
233 public override void CopyFrom(BindableObject bindableObject)
235 base.CopyFrom(bindableObject);
237 ButtonStyle buttonStyle = bindableObject as ButtonStyle;
239 if (null != buttonStyle)
241 if (null != buttonStyle.Overlay)
243 Overlay.CopyFrom(buttonStyle.Overlay);
246 if (null != buttonStyle.Text)
248 Text.CopyFrom(buttonStyle.Text);
251 if (null != buttonStyle.Icon)
253 Icon.CopyFrom(buttonStyle.Icon);
256 IsSelectable = buttonStyle.IsSelectable;
257 IconRelativeOrientation = buttonStyle.IconRelativeOrientation;
261 private void InitSubStyle()
263 Overlay = new ImageViewStyle()
265 PositionUsesPivotPoint = true,
266 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
267 PivotPoint = Tizen.NUI.PivotPoint.Center,
268 WidthResizePolicy = ResizePolicyType.FillToParent,
269 HeightResizePolicy = ResizePolicyType.FillToParent
271 Overlay.PropertyChanged += SubStyleCalledEvent;
273 Text = new TextLabelStyle()
275 PositionUsesPivotPoint = true,
276 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
277 PivotPoint = Tizen.NUI.PivotPoint.Center,
278 WidthResizePolicy = ResizePolicyType.FillToParent,
279 HeightResizePolicy = ResizePolicyType.FillToParent,
280 HorizontalAlignment = HorizontalAlignment.Center,
281 VerticalAlignment = VerticalAlignment.Center
283 Text.PropertyChanged += SubStyleCalledEvent;
285 Icon = new ImageControlStyle()
287 PositionUsesPivotPoint = true,
288 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
289 PivotPoint = Tizen.NUI.PivotPoint.Center,
290 WidthResizePolicy = ResizePolicyType.FitToChildren,
291 HeightResizePolicy = ResizePolicyType.FitToChildren,
293 Icon.PropertyChanged += SubStyleCalledEvent;
296 private void SubStyleCalledEvent(object sender, global::System.EventArgs e)