[NUI.Components] Fix Background Image not works issue (#1246)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Style / SliderStyle.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(nameof(IndicatorType), typeof(IndicatorType?), typeof(SliderStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
35         {
36             var instance = (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(nameof(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(nameof(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(nameof(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
93         static SliderStyle() { }
94
95         /// <summary>
96         /// Creates a new instance of a SliderStyle.
97         /// </summary>
98         /// <since_tizen> 6 </since_tizen>
99         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
100         [EditorBrowsable(EditorBrowsableState.Never)]
101         public SliderStyle() : base()
102         {
103             IndicatorType = Slider.IndicatorType.None;
104             InitSubStyle();
105         }
106
107         /// <summary>
108         /// Creates a new instance of a SliderStyle with style.
109         /// </summary>
110         /// <param name="style">Create SliderStyle by style customized by user.</param>
111         /// <since_tizen> 6 </since_tizen>
112         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
113         [EditorBrowsable(EditorBrowsableState.Never)]
114         public SliderStyle(SliderStyle style) : base(style)
115         {
116             if(style == null)
117             {
118                 return;
119             }
120
121             InitSubStyle();
122
123             this.CopyFrom(style);
124
125             IndicatorType = style.IndicatorType;
126         }
127
128         /// <summary>
129         /// Get or set background track.
130         /// </summary>
131         /// <since_tizen> 6 </since_tizen>
132         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
133         [EditorBrowsable(EditorBrowsableState.Never)]
134         public ImageViewStyle Track { get; set; }
135
136         /// <summary>
137         /// Get or set slided track.
138         /// </summary>
139         /// <since_tizen> 6 </since_tizen>
140         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
141         [EditorBrowsable(EditorBrowsableState.Never)]
142         public ImageViewStyle Progress { get; set; }
143
144         /// <summary>
145         /// Get or set thumb.
146         /// </summary>
147         /// <since_tizen> 6 </since_tizen>
148         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
149         [EditorBrowsable(EditorBrowsableState.Never)]
150         public ImageViewStyle Thumb { get; set; }
151
152         /// <summary>
153         /// Get or set low indicator image.
154         /// </summary>
155         /// <since_tizen> 6 </since_tizen>
156         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
157         [EditorBrowsable(EditorBrowsableState.Never)]
158         public ImageViewStyle LowIndicatorImage { get; set; }
159
160         /// <summary>
161         /// Get or set high indicator image.
162         /// </summary>
163         /// <since_tizen> 6 </since_tizen>
164         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
165         [EditorBrowsable(EditorBrowsableState.Never)]
166         public ImageViewStyle HighIndicatorImage { get; set; }
167
168         /// <summary>
169         /// Get or set low indicator text.
170         /// </summary>
171         /// <since_tizen> 6 </since_tizen>
172         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
173         [EditorBrowsable(EditorBrowsableState.Never)]
174         public TextLabelStyle LowIndicator { get; set; }
175
176         /// <summary>
177         /// Get or set high indicator text.
178         /// </summary>
179         /// <since_tizen> 6 </since_tizen>
180         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
181         [EditorBrowsable(EditorBrowsableState.Never)]
182         public TextLabelStyle HighIndicator { get; set; }
183
184         /// <summary>
185         /// Get or set Indicator type
186         /// </summary>
187         /// <since_tizen> 6 </since_tizen>
188         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
189         [EditorBrowsable(EditorBrowsableState.Never)]
190         public IndicatorType? IndicatorType
191         {
192             get => (IndicatorType?)GetValue(IndicatorTypeProperty);
193             set => SetValue(IndicatorTypeProperty, value);
194         }
195
196         private IndicatorType? privateIndicatorType { get; set; }
197
198         /// <summary>
199         /// Get or set track thickness
200         /// </summary>
201         /// <since_tizen> 6 </since_tizen>
202         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
203         [EditorBrowsable(EditorBrowsableState.Never)]
204         public uint? TrackThickness
205         {
206             get => (uint?)GetValue(TrackThicknessProperty);
207             set => SetValue(TrackThicknessProperty, value);
208         }
209         private uint? privateTrackThickness { get; set; }
210
211         /// <summary>
212         /// Get or set space between track and indicator
213         /// </summary>
214         /// <since_tizen> 6 </since_tizen>
215         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
216         [EditorBrowsable(EditorBrowsableState.Never)]
217         public uint? SpaceBetweenTrackAndIndicator
218         {
219             get => (uint?)GetValue(SpaceBetweenTrackAndIndicatorProperty);
220             set => SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
221         }
222         private uint? privateSpaceBetweenTrackAndIndicator { get; set; }
223
224         /// <summary>
225         /// Get or set space between track and indicator
226         /// </summary>
227         /// <since_tizen> 6 </since_tizen>
228         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
229         [EditorBrowsable(EditorBrowsableState.Never)]
230         public Extents TrackPadding
231         {
232             get => (Extents)GetValue(TrackPaddingProperty);
233             set => SetValue(TrackPaddingProperty, value);
234         }
235         private Extents _trackPadding;
236         private Extents trackPadding
237         {
238             get
239             {
240                 if (null == _trackPadding)
241                 {
242                     _trackPadding = new Extents((ushort start, ushort end, ushort top, ushort bottom)=>
243                                         {
244                                             Extents extents = new Extents(start, end, top, bottom);
245                                             _trackPadding.CopyFrom(extents);
246                                         }, 0, 0, 0, 0);
247                 }
248                 return _trackPadding;
249             }
250         }
251
252         /// <summary>
253         /// Attributes's clone function.
254         /// </summary>
255         /// <since_tizen> 6 </since_tizen>
256         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
257         [EditorBrowsable(EditorBrowsableState.Never)]
258         public override void CopyFrom(BindableObject bindableObject)
259         {
260             base.CopyFrom(bindableObject);
261
262             SliderStyle sliderAttributes = bindableObject as SliderStyle;
263
264             if (null != sliderAttributes)
265             {
266                 if (sliderAttributes.Track != null)
267                 {
268                     if (null == Track)
269                     {
270                         Track = new ImageViewStyle();
271                     }
272                     Track.CopyFrom(sliderAttributes.Track);
273                 }
274
275                 if (sliderAttributes.Progress != null)
276                 {
277                     if (null == Progress)
278                     {
279                         Progress = new ImageViewStyle();
280                     }
281                     Progress.CopyFrom(sliderAttributes.Progress);
282                 }
283
284                 if (sliderAttributes.Thumb != null)
285                 {
286                     if (null == Thumb)
287                     {
288                         Thumb = new ImageViewStyle();
289                     }
290                     Thumb.CopyFrom(sliderAttributes.Thumb);
291                 }
292
293                 if (sliderAttributes.LowIndicatorImage != null)
294                 {
295                     if (null == LowIndicatorImage)
296                     {
297                         LowIndicatorImage = new ImageViewStyle();
298                     }
299                     LowIndicatorImage.CopyFrom(sliderAttributes.LowIndicatorImage);
300                 }
301
302                 if (sliderAttributes.HighIndicatorImage != null)
303                 {
304                     if (null == HighIndicatorImage)
305                     {
306                         HighIndicatorImage = new ImageViewStyle();
307                     }
308                     HighIndicatorImage.CopyFrom(sliderAttributes.HighIndicatorImage);
309                 }
310
311                 if (sliderAttributes.LowIndicator != null)
312                 {
313                     if (null == LowIndicator)
314                     {
315                         LowIndicator = new TextLabelStyle();
316                     }
317                     LowIndicator.CopyFrom(sliderAttributes.LowIndicator);
318                 }
319
320                 if (sliderAttributes.HighIndicator != null)
321                 {
322                     if (null == HighIndicator)
323                     {
324                         HighIndicator = new TextLabelStyle();
325                     }
326                     HighIndicator.CopyFrom(sliderAttributes.HighIndicator);
327                 }
328
329                 if (sliderAttributes.TrackThickness != null)
330                 {
331                     TrackThickness = sliderAttributes.TrackThickness;
332                 }
333
334                 if (sliderAttributes.TrackPadding != null)
335                 {
336                     TrackPadding = sliderAttributes.TrackPadding;
337                 }
338             }
339         }
340
341         private void InitSubStyle()
342         {
343             Track = new ImageViewStyle();
344             Progress = new ImageViewStyle();
345             Thumb = new ImageViewStyle();
346             LowIndicatorImage = new ImageViewStyle();
347             HighIndicatorImage = new ImageViewStyle();
348             LowIndicator = new TextLabelStyle();
349             HighIndicator = new TextLabelStyle();
350         }
351     }
352 }