7b9497623c05aa1295e6df0cb70d02d1155c3068
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Attributes / SliderAttributes.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 static Tizen.NUI.Components.Slider;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// SliderStyle is a class which saves Slider's ux data.
26     /// </summary>
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 SliderStyle : ControlStyle
31     {
32         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
33         [EditorBrowsable(EditorBrowsableState.Never)]
34         public static readonly BindableProperty IndicatorTypeProperty = BindableProperty.Create("IndicatorType", typeof(IndicatorType?), typeof(SliderStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
35         {
36             var instance = (Tizen.NUI.Components.SliderStyle)bindable;
37             if (newValue != null)
38             {
39                 instance.privateIndicatorType = (IndicatorType)newValue;
40             }
41         },
42         defaultValueCreator: (bindable) =>
43         {
44             var instance = (SliderStyle)bindable;
45             return instance.privateIndicatorType;
46         });
47         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
48         [EditorBrowsable(EditorBrowsableState.Never)]
49         public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create("SpaceBetweenTrackAndIndicator", typeof(uint?), typeof(SliderStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
50         {
51             var instance = (SliderStyle)bindable;
52             if (newValue != null)
53             {
54                 instance.privateSpaceBetweenTrackAndIndicator = (uint?)newValue;
55             }
56         },
57         defaultValueCreator: (bindable) =>
58         {
59             var instance = (SliderStyle)bindable;
60             return instance.privateSpaceBetweenTrackAndIndicator;
61         });
62         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
63         [EditorBrowsable(EditorBrowsableState.Never)]
64         public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create("TrackThickness", typeof(uint?), typeof(SliderStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
65         {
66             var instance = (SliderStyle)bindable;
67             if (newValue != null)
68             {
69                 instance.privateTrackThickness = (uint?)newValue;
70             }
71         },
72         defaultValueCreator: (bindable) =>
73         {
74             var instance = (SliderStyle)bindable;
75             return instance.privateTrackThickness;
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 TrackPaddingProperty = BindableProperty.Create("TrackPadding", typeof(Extents), typeof(SliderStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
80         {
81             var instance = (SliderStyle)bindable;
82             if (newValue != null)
83             {
84                 instance.trackPadding.CopyFrom((Extents)newValue);
85             }
86         },
87         defaultValueCreator: (bindable) =>
88         {
89             var instance = (SliderStyle)bindable;
90             return instance.trackPadding;
91         });
92         /// <summary>
93         /// Creates a new instance of a SliderStyle.
94         /// </summary>
95         /// <since_tizen> 6 </since_tizen>
96         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
97         [EditorBrowsable(EditorBrowsableState.Never)]
98         public SliderStyle() : base()
99         {
100             IndicatorType = Slider.IndicatorType.None;
101             InitSubStyle();
102         }
103
104         /// <summary>
105         /// Creates a new instance of a SliderStyle with style.
106         /// </summary>
107         /// <param name="style">Create SliderStyle by style customized by user.</param>
108         /// <since_tizen> 6 </since_tizen>
109         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
110         [EditorBrowsable(EditorBrowsableState.Never)]
111         public SliderStyle(SliderStyle style) : base(style)
112         {
113             if(style == null)
114             {
115                 return;
116             }
117
118             InitSubStyle();
119
120             this.CopyFrom(style);
121
122             IndicatorType = style.IndicatorType;
123         }
124
125         /// <summary>
126         /// Get or set background track.
127         /// </summary>
128         /// <since_tizen> 6 </since_tizen>
129         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
130         [EditorBrowsable(EditorBrowsableState.Never)]
131         public ImageViewStyle Track { get; set; }
132
133         /// <summary>
134         /// Get or set slided track.
135         /// </summary>
136         /// <since_tizen> 6 </since_tizen>
137         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
138         [EditorBrowsable(EditorBrowsableState.Never)]
139         public ImageViewStyle Progress { get; set; }
140
141         /// <summary>
142         /// Get or set thumb.
143         /// </summary>
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 Thumb { get; set; }
148
149         /// <summary>
150         /// Get or set low indicator image.
151         /// </summary>
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 ImageViewStyle LowIndicatorImage { get; set; }
156
157         /// <summary>
158         /// Get or set high indicator image.
159         /// </summary>
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 ImageViewStyle HighIndicatorImage { get; set; }
164
165         /// <summary>
166         /// Get or set low indicator text.
167         /// </summary>
168         /// <since_tizen> 6 </since_tizen>
169         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
170         [EditorBrowsable(EditorBrowsableState.Never)]
171         public TextLabelStyle LowIndicator { get; set; }
172
173         /// <summary>
174         /// Get or set high indicator text.
175         /// </summary>
176         /// <since_tizen> 6 </since_tizen>
177         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
178         [EditorBrowsable(EditorBrowsableState.Never)]
179         public TextLabelStyle HighIndicator { get; set; }
180
181         /// <summary>
182         /// Get or set Indicator type
183         /// </summary>
184         /// <since_tizen> 6 </since_tizen>
185         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
186         [EditorBrowsable(EditorBrowsableState.Never)]
187         public IndicatorType? IndicatorType
188         {
189             get => (IndicatorType?)GetValue(IndicatorTypeProperty);
190             set => SetValue(IndicatorTypeProperty, value);
191         }
192
193         private IndicatorType? privateIndicatorType { get; set; }
194
195         /// <summary>
196         /// Get or set track thickness
197         /// </summary>
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 uint? TrackThickness
202         {
203             get => (uint?)GetValue(TrackThicknessProperty);
204             set => SetValue(TrackThicknessProperty, value);
205         }
206         private uint? privateTrackThickness { get; set; }
207
208         /// <summary>
209         /// Get or set space between track and indicator
210         /// </summary>
211         /// <since_tizen> 6 </since_tizen>
212         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
213         [EditorBrowsable(EditorBrowsableState.Never)]
214         public uint? SpaceBetweenTrackAndIndicator
215         {
216             get => (uint?)GetValue(SpaceBetweenTrackAndIndicatorProperty);
217             set => SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
218         }
219         private uint? privateSpaceBetweenTrackAndIndicator { get; set; }
220
221         /// <summary>
222         /// Get or set space between track and indicator
223         /// </summary>
224         /// <since_tizen> 6 </since_tizen>
225         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
226         [EditorBrowsable(EditorBrowsableState.Never)]
227         public Extents TrackPadding
228         {
229             get => (Extents)GetValue(TrackPaddingProperty);
230             set => SetValue(TrackPaddingProperty, value);
231         }
232         private Extents _trackPadding;
233         private Extents trackPadding
234         {
235             get
236             {
237                 if (null == _trackPadding)
238                 {
239                     _trackPadding = new Extents((ushort start, ushort end, ushort top, ushort bottom)=>
240                                         {
241                                             Extents extents = new Extents(start, end, top, bottom);
242                                             _trackPadding.CopyFrom(extents);
243                                         }, 0, 0, 0, 0);
244                 }
245                 return _trackPadding;
246             }
247         }
248
249         /// <summary>
250         /// Attributes's clone function.
251         /// </summary>
252         /// <since_tizen> 6 </since_tizen>
253         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
254         [EditorBrowsable(EditorBrowsableState.Never)]
255         public override void CopyFrom(BindableObject bindableObject)
256         {
257             base.CopyFrom(bindableObject);
258
259             SliderStyle sliderAttributes = bindableObject as SliderStyle;
260
261             if (null != sliderAttributes)
262             {
263                 if (sliderAttributes.Track != null)
264                 {
265                     if (null == Track)
266                     {
267                         Track = new ImageViewStyle();
268                     }
269                     Track.CopyFrom(sliderAttributes.Track);
270                 }
271
272                 if (sliderAttributes.Progress != null)
273                 {
274                     if (null == Progress)
275                     {
276                         Progress = new ImageViewStyle();
277                     }
278                     Progress.CopyFrom(sliderAttributes.Progress);
279                 }
280
281                 if (sliderAttributes.Thumb != null)
282                 {
283                     if (null == Thumb)
284                     {
285                         Thumb = new ImageViewStyle();
286                     }
287                     Thumb.CopyFrom(sliderAttributes.Thumb);
288                 }
289
290                 if (sliderAttributes.LowIndicatorImage != null)
291                 {
292                     if (null == LowIndicatorImage)
293                     {
294                         LowIndicatorImage = new ImageViewStyle();
295                     }
296                     LowIndicatorImage.CopyFrom(sliderAttributes.LowIndicatorImage);
297                 }
298
299                 if (sliderAttributes.HighIndicatorImage != null)
300                 {
301                     if (null == HighIndicatorImage)
302                     {
303                         HighIndicatorImage = new ImageViewStyle();
304                     }
305                     HighIndicatorImage.CopyFrom(sliderAttributes.HighIndicatorImage);
306                 }
307
308                 if (sliderAttributes.LowIndicator != null)
309                 {
310                     if (null == LowIndicator)
311                     {
312                         LowIndicator = new TextLabelStyle();
313                     }
314                     LowIndicator.CopyFrom(sliderAttributes.LowIndicator);
315                 }
316
317                 if (sliderAttributes.HighIndicator != null)
318                 {
319                     if (null == HighIndicator)
320                     {
321                         HighIndicator = new TextLabelStyle();
322                     }
323                     HighIndicator.CopyFrom(sliderAttributes.HighIndicator);
324                 }
325
326                 if (sliderAttributes.TrackThickness != null)
327                 {
328                     TrackThickness = sliderAttributes.TrackThickness;
329                 }
330
331                 if (sliderAttributes.TrackPadding != null)
332                 {
333                     TrackPadding = sliderAttributes.TrackPadding;
334                 }
335             }
336         }
337
338         private void InitSubStyle()
339         {
340             Track = new ImageViewStyle();
341             Progress = new ImageViewStyle();
342             Thumb = new ImageViewStyle();
343             LowIndicatorImage = new ImageViewStyle();
344             HighIndicatorImage = new ImageViewStyle();
345             LowIndicator = new TextLabelStyle();
346             HighIndicator = new TextLabelStyle();
347         }
348     }
349 }