e49aa72466a814ea3ceb328200c048b76ed0f91d
[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
132         {
133             get;
134             set;
135         }
136
137         /// <summary>
138         /// Get or set slided track.
139         /// </summary>
140         /// <since_tizen> 6 </since_tizen>
141         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         public ImageViewStyle Progress
144         {
145             get;
146             set;
147         }
148
149         /// <summary>
150         /// Get or set thumb.
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 Thumb
156         {
157             get;
158             set;
159         }
160
161         /// <summary>
162         /// Get or set thumb background.
163         /// </summary>
164         /// <since_tizen> 6 </since_tizen>
165         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
166         [EditorBrowsable(EditorBrowsableState.Never)]
167         public ImageViewStyle ThumbBackground
168         {
169             get;
170             set;
171         }
172
173         /// <summary>
174         /// Get or set low indicator image.
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 ImageViewStyle LowIndicatorImage
180         {
181             get;
182             set;
183         }
184
185         /// <summary>
186         /// Get or set high indicator image.
187         /// </summary>
188         /// <since_tizen> 6 </since_tizen>
189         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
190         [EditorBrowsable(EditorBrowsableState.Never)]
191         public ImageViewStyle HighIndicatorImage
192         {
193             get;
194             set;
195         }
196
197         /// <summary>
198         /// Get or set low indicator text.
199         /// </summary>
200         /// <since_tizen> 6 </since_tizen>
201         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
202         [EditorBrowsable(EditorBrowsableState.Never)]
203         public TextLabelStyle LowIndicator
204         {
205             get;
206             set;
207         }
208
209         /// <summary>
210         /// Get or set high indicator text.
211         /// </summary>
212         /// <since_tizen> 6 </since_tizen>
213         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
214         [EditorBrowsable(EditorBrowsableState.Never)]
215         public TextLabelStyle HighIndicator
216         {
217             get;
218             set;
219         }
220
221         /// <summary>
222         /// Get or set Indicator type
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 IndicatorType? IndicatorType
228         {
229             get
230             {
231                 return (IndicatorType?)GetValue(IndicatorTypeProperty);
232             }
233             set
234             {
235                 SetValue(IndicatorTypeProperty, value);
236             }
237         }
238         private IndicatorType? privateIndicatorType
239         {
240             get;
241             set;
242         }
243
244         /// <summary>
245         /// Get or set track thickness
246         /// </summary>
247         /// <since_tizen> 6 </since_tizen>
248         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
249         [EditorBrowsable(EditorBrowsableState.Never)]
250         public uint? TrackThickness
251         {
252             get
253             {
254                 return (uint?)GetValue(TrackThicknessProperty);
255             }
256             set
257             {
258                 SetValue(TrackThicknessProperty, value);
259             }
260         }
261         private uint? privateTrackThickness
262         {
263             get;
264             set;
265         }
266
267         /// <summary>
268         /// Get or set space between track and indicator
269         /// </summary>
270         /// <since_tizen> 6 </since_tizen>
271         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
272         [EditorBrowsable(EditorBrowsableState.Never)]
273         public uint? SpaceBetweenTrackAndIndicator
274         {
275             get
276             {
277                 return (uint?)GetValue(SpaceBetweenTrackAndIndicatorProperty);
278             }
279             set
280             {
281                 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
282             }
283         }
284         private uint? privateSpaceBetweenTrackAndIndicator
285         {
286             get;
287             set;
288         }
289
290         /// <summary>
291         /// Get or set space between track and indicator
292         /// </summary>
293         /// <since_tizen> 6 </since_tizen>
294         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
295         [EditorBrowsable(EditorBrowsableState.Never)]
296         public Extents TrackPadding
297         {
298             get
299             {
300                 return (Extents)GetValue(TrackPaddingProperty);
301             }
302             set
303             {
304                 SetValue(TrackPaddingProperty, value);
305             }
306         }
307         private Extents _trackPadding;
308         private Extents trackPadding
309         {
310             get
311             {
312                 if (null == _trackPadding)
313                 {
314                     _trackPadding = new Extents((ushort start, ushort end, ushort top, ushort bottom)=>
315                                         {
316                                             Extents extents = new Extents(start, end, top, bottom);
317                                             _trackPadding.CopyFrom(extents);
318                                         }, 0, 0, 0, 0);
319                 }
320                 return _trackPadding;
321             }
322         }
323
324         /// <summary>
325         /// Attributes's clone function.
326         /// </summary>
327         /// <since_tizen> 6 </since_tizen>
328         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
329         [EditorBrowsable(EditorBrowsableState.Never)]
330         public override void CopyFrom(BindableObject bindableObject)
331         {
332             base.CopyFrom(bindableObject);
333
334             SliderStyle sliderAttributes = bindableObject as SliderStyle;
335
336             if (null != sliderAttributes)
337             {
338                 if (sliderAttributes.Track != null)
339                 {
340                     if (null == Track)
341                     {
342                         Track = new ImageViewStyle();
343                     }
344                     Track.CopyFrom(sliderAttributes.Track);
345                 }
346
347                 if (sliderAttributes.Progress != null)
348                 {
349                     if (null == Progress)
350                     {
351                         Progress = new ImageViewStyle();
352                     }
353                     Progress.CopyFrom(sliderAttributes.Progress);
354                 }
355
356                 if (sliderAttributes.Thumb != null)
357                 {
358                     if (null == Thumb)
359                     {
360                         Thumb = new ImageViewStyle();
361                     }
362                     Thumb.CopyFrom(sliderAttributes.Thumb);
363                 }
364
365                 if (sliderAttributes.ThumbBackground != null)
366                 {
367                     if (null == ThumbBackground)
368                     {
369                         ThumbBackground = new ImageViewStyle();
370                     }
371                     ThumbBackground.CopyFrom(sliderAttributes.ThumbBackground);
372                 }
373
374                 if (sliderAttributes.LowIndicatorImage != null)
375                 {
376                     if (null == LowIndicatorImage)
377                     {
378                         LowIndicatorImage = new ImageViewStyle();
379                     }
380                     LowIndicatorImage.CopyFrom(sliderAttributes.LowIndicatorImage);
381                 }
382
383                 if (sliderAttributes.HighIndicatorImage != null)
384                 {
385                     if (null == HighIndicatorImage)
386                     {
387                         HighIndicatorImage = new ImageViewStyle();
388                     }
389                     HighIndicatorImage.CopyFrom(sliderAttributes.HighIndicatorImage);
390                 }
391
392                 if (sliderAttributes.LowIndicator != null)
393                 {
394                     if (null == LowIndicator)
395                     {
396                         LowIndicator = new TextLabelStyle();
397                     }
398                     LowIndicator.CopyFrom(sliderAttributes.LowIndicator);
399                 }
400
401                 if (sliderAttributes.HighIndicator != null)
402                 {
403                     if (null == HighIndicator)
404                     {
405                         HighIndicator = new TextLabelStyle();
406                     }
407                     HighIndicator.CopyFrom(sliderAttributes.HighIndicator);
408                 }
409
410                 if (sliderAttributes.TrackThickness != null)
411                 {
412                     TrackThickness = sliderAttributes.TrackThickness;
413                 }
414
415                 if (sliderAttributes.TrackPadding != null)
416                 {
417                     TrackPadding = sliderAttributes.TrackPadding;
418                 }
419             }
420         }
421
422         private void InitSubStyle()
423         {
424             Track = new ImageViewStyle();
425             Progress = new ImageViewStyle();
426             Thumb = new ImageViewStyle();
427             ThumbBackground = new ImageViewStyle();
428             LowIndicatorImage = new ImageViewStyle();
429             HighIndicatorImage = new ImageViewStyle();
430             LowIndicator = new TextLabelStyle();
431             HighIndicator = new TextLabelStyle();
432         }
433     }
434 }