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("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("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("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("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("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("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;
113 /// Creates a new instance of a ButtonStyle.
115 /// <since_tizen> 6 </since_tizen>
116 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
117 [EditorBrowsable(EditorBrowsableState.Never)]
118 public ButtonStyle() : base()
124 /// Creates a new instance of a ButtonStyle with style.
126 /// <param name="style">Create ButtonStyle by style customized by user.</param>
127 /// <since_tizen> 6 </since_tizen>
128 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
129 [EditorBrowsable(EditorBrowsableState.Never)]
130 public ButtonStyle(ButtonStyle style) : base(style)
139 this.CopyFrom(style);
142 /// Overlay image's Style.
144 /// <since_tizen> 6 </since_tizen>
145 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
146 [EditorBrowsable(EditorBrowsableState.Never)]
147 public ImageViewStyle Overlay { get; set; }
152 /// <since_tizen> 6 </since_tizen>
153 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public TextLabelStyle Text { get; set; }
160 /// <since_tizen> 6 </since_tizen>
161 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
162 [EditorBrowsable(EditorBrowsableState.Never)]
163 public ImageControlStyle Icon { get; set; }
165 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
166 [EditorBrowsable(EditorBrowsableState.Never)]
167 public bool? IsSelectable
169 get => (bool?)GetValue(IsSelectableProperty);
170 set => SetValue(IsSelectableProperty, value);
173 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
174 [EditorBrowsable(EditorBrowsableState.Never)]
175 public bool? IsSelected
177 get => (bool?)GetValue(IsSelectedProperty);
178 set => SetValue(IsSelectedProperty, value);
182 /// Flag to decide button can be selected or not.
184 /// <since_tizen> 6 </since_tizen>
185 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
186 [EditorBrowsable(EditorBrowsableState.Never)]
187 public bool? IsEnabled
189 get => (bool?)GetValue(IsEnabledProperty);
190 set => SetValue(IsEnabledProperty, value);
194 /// Icon relative orientation.
196 /// <since_tizen> 6 </since_tizen>
197 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
198 [EditorBrowsable(EditorBrowsableState.Never)]
199 public Button.IconOrientation? IconRelativeOrientation
201 get => (Button.IconOrientation?)GetValue(IconRelativeOrientationProperty);
202 set => SetValue(IconRelativeOrientationProperty, value);
205 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
206 [EditorBrowsable(EditorBrowsableState.Never)]
207 public Extents IconPadding
211 Extents padding = (Extents)GetValue(IconPaddingProperty);
212 return (null != padding) ? padding : iconPadding = new Extents((ushort start, ushort end, ushort top, ushort bottom) => { IconPadding = new Extents(start, end, top, bottom); }, 0, 0, 0, 0);
214 set => SetValue(IconPaddingProperty, value);
217 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
218 [EditorBrowsable(EditorBrowsableState.Never)]
219 public Extents TextPadding
223 Extents padding = (Extents)GetValue(TextPaddingProperty);
224 return (null != padding) ? padding : textPadding = new Extents((ushort start, ushort end, ushort top, ushort bottom) => { TextPadding = new Extents(start, end, top, bottom); }, 0, 0, 0, 0);
226 set => SetValue(TextPaddingProperty, value);
229 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
230 [EditorBrowsable(EditorBrowsableState.Never)]
231 public override void CopyFrom(BindableObject bindableObject)
233 base.CopyFrom(bindableObject);
235 ButtonStyle buttonStyle = bindableObject as ButtonStyle;
237 if (null != buttonStyle)
239 if (null != buttonStyle.Overlay)
241 Overlay.CopyFrom(buttonStyle.Overlay);
244 if (null != buttonStyle.Text)
246 Text.CopyFrom(buttonStyle.Text);
249 if (null != buttonStyle.Icon)
251 Icon.CopyFrom(buttonStyle.Icon);
254 IsSelectable = buttonStyle.IsSelectable;
255 IconRelativeOrientation = buttonStyle.IconRelativeOrientation;
259 private void InitSubStyle()
261 Overlay = new ImageViewStyle()
263 PositionUsesPivotPoint = true,
264 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
265 PivotPoint = Tizen.NUI.PivotPoint.Center,
266 WidthResizePolicy = ResizePolicyType.FillToParent,
267 HeightResizePolicy = ResizePolicyType.FillToParent
269 Overlay.PropertyChanged += SubStyleCalledEvent;
271 Text = new TextLabelStyle()
273 PositionUsesPivotPoint = true,
274 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
275 PivotPoint = Tizen.NUI.PivotPoint.Center,
276 WidthResizePolicy = ResizePolicyType.FillToParent,
277 HeightResizePolicy = ResizePolicyType.FillToParent,
278 HorizontalAlignment = HorizontalAlignment.Center,
279 VerticalAlignment = VerticalAlignment.Center
281 Text.PropertyChanged += SubStyleCalledEvent;
283 Icon = new ImageControlStyle()
285 PositionUsesPivotPoint = true,
286 ParentOrigin = Tizen.NUI.ParentOrigin.Center,
287 PivotPoint = Tizen.NUI.PivotPoint.Center,
288 WidthResizePolicy = ResizePolicyType.FitToChildren,
289 HeightResizePolicy = ResizePolicyType.FitToChildren,
291 Icon.PropertyChanged += SubStyleCalledEvent;
294 private void SubStyleCalledEvent(object sender, global::System.EventArgs e)