[NUI] Revert patch about StyleManager (#1970)
[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> 8 </since_tizen>
28     public class SliderStyle : ControlStyle
29     {
30         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
31         [EditorBrowsable(EditorBrowsableState.Never)]
32         public static readonly BindableProperty IndicatorTypeProperty = BindableProperty.Create(nameof(IndicatorType), typeof(IndicatorType?), typeof(SliderStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
33         {
34             var instance = (SliderStyle)bindable;
35             if (newValue != null)
36             {
37                 instance.privateIndicatorType = (IndicatorType)newValue;
38             }
39         },
40         defaultValueCreator: (bindable) =>
41         {
42             var instance = (SliderStyle)bindable;
43             return instance.privateIndicatorType;
44         });
45         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
46         [EditorBrowsable(EditorBrowsableState.Never)]
47         public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create(nameof(SpaceBetweenTrackAndIndicator), typeof(uint?), typeof(SliderStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
48         {
49             var instance = (SliderStyle)bindable;
50             if (newValue != null)
51             {
52                 instance.privateSpaceBetweenTrackAndIndicator = (uint?)newValue;
53             }
54         },
55         defaultValueCreator: (bindable) =>
56         {
57             var instance = (SliderStyle)bindable;
58             return instance.privateSpaceBetweenTrackAndIndicator;
59         });
60         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
61         [EditorBrowsable(EditorBrowsableState.Never)]
62         public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(uint?), typeof(SliderStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
63         {
64             var instance = (SliderStyle)bindable;
65             if (newValue != null)
66             {
67                 instance.privateTrackThickness = (uint?)newValue;
68             }
69         },
70         defaultValueCreator: (bindable) =>
71         {
72             var instance = (SliderStyle)bindable;
73             return instance.privateTrackThickness;
74         });
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 TrackPaddingProperty = BindableProperty.Create(nameof(TrackPadding), typeof(Extents), typeof(SliderStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
78         {
79             var instance = (SliderStyle)bindable;
80             if (newValue != null)
81             {
82                 if (null == instance.trackPadding) instance.trackPadding = new Extents(instance.OnTrackPaddingChanged, 0, 0, 0, 0);
83                 instance.trackPadding.CopyFrom(null == newValue ? new Extents() : (Extents)newValue);
84             }
85         },
86         defaultValueCreator: (bindable) =>
87         {
88             var instance = (SliderStyle)bindable;
89             return instance.trackPadding;
90         });
91
92         private IndicatorType? privateIndicatorType;
93         private uint? privateTrackThickness;
94         private uint? privateSpaceBetweenTrackAndIndicator;
95         private Extents trackPadding;
96
97         static SliderStyle() { }
98
99         /// <summary>
100         /// Creates a new instance of a SliderStyle.
101         /// </summary>
102         /// <since_tizen> 8 </since_tizen>
103         public SliderStyle() : base()
104         {
105             IndicatorType = Slider.IndicatorType.None;
106             InitSubStyle();
107         }
108
109         /// <summary>
110         /// Creates a new instance of a SliderStyle with style.
111         /// </summary>
112         /// <param name="style">Create SliderStyle by style customized by user.</param>
113         /// <since_tizen> 8 </since_tizen>
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> 8 </since_tizen>
132         public ImageViewStyle Track { get; set; }
133
134         /// <summary>
135         /// Get or set slided track.
136         /// </summary>
137         /// <since_tizen> 8 </since_tizen>
138         public ImageViewStyle Progress { get; set; }
139
140         /// <summary>
141         /// Get or set thumb.
142         /// </summary>
143         /// <since_tizen> 8 </since_tizen>
144         public ImageViewStyle Thumb { get; set; }
145
146         /// <summary>
147         /// Get or set low indicator image.
148         /// </summary>
149         /// <since_tizen> 8 </since_tizen>
150         public ImageViewStyle LowIndicatorImage { get; set; }
151
152         /// <summary>
153         /// Get or set high indicator image.
154         /// </summary>
155         /// <since_tizen> 8 </since_tizen>
156         public ImageViewStyle HighIndicatorImage { get; set; }
157
158         /// <summary>
159         /// Get or set low indicator text.
160         /// </summary>
161         /// <since_tizen> 8 </since_tizen>
162         public TextLabelStyle LowIndicator { get; set; }
163
164         /// <summary>
165         /// Get or set high indicator text.
166         /// </summary>
167         /// <since_tizen> 8 </since_tizen>
168         public TextLabelStyle HighIndicator { get; set; }
169
170         /// <summary>
171         /// Get or set Indicator type
172         /// </summary>
173         /// <since_tizen> 8 </since_tizen>
174         public IndicatorType? IndicatorType
175         {
176             get => (IndicatorType?)GetValue(IndicatorTypeProperty);
177             set => SetValue(IndicatorTypeProperty, value);
178         }
179
180         /// <summary>
181         /// Get or set track thickness
182         /// </summary>
183         /// <since_tizen> 8 </since_tizen>
184         public uint? TrackThickness
185         {
186             get => (uint?)GetValue(TrackThicknessProperty);
187             set => SetValue(TrackThicknessProperty, value);
188         }
189
190         /// <summary>
191         /// Get or set space between track and indicator
192         /// </summary>
193         /// <since_tizen> 8 </since_tizen>
194         public uint? SpaceBetweenTrackAndIndicator
195         {
196             get => (uint?)GetValue(SpaceBetweenTrackAndIndicatorProperty);
197             set => SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
198         }
199
200         /// <summary>
201         /// Get or set space between track and indicator
202         /// </summary>
203         /// <since_tizen> 8 </since_tizen>
204         public Extents TrackPadding
205         {
206             get
207             {
208                 Extents tmp = (Extents)GetValue(TrackPaddingProperty);
209                 return (null != tmp) ? tmp : trackPadding = new Extents(OnTrackPaddingChanged, 0, 0, 0, 0);
210             }
211             set => SetValue(TrackPaddingProperty, value);
212         }
213
214         /// <summary>
215         /// Style's clone function.
216         /// </summary>
217         /// <param name="bindableObject">The style that need to copy.</param>
218         /// <since_tizen> 8 </since_tizen>
219         public override void CopyFrom(BindableObject bindableObject)
220         {
221             base.CopyFrom(bindableObject);
222
223             SliderStyle sliderStyle = bindableObject as SliderStyle;
224
225             if (null != sliderStyle)
226             {
227                 if (sliderStyle.Track != null)
228                 {
229                     Track?.CopyFrom(sliderStyle.Track);
230                 }
231
232                 if (sliderStyle.Progress != null)
233                 {
234                     Progress?.CopyFrom(sliderStyle.Progress);
235                 }
236
237                 if (sliderStyle.Thumb != null)
238                 {
239                     Thumb?.CopyFrom(sliderStyle.Thumb);
240                 }
241
242                 if (sliderStyle.LowIndicatorImage != null)
243                 {
244                     LowIndicatorImage?.CopyFrom(sliderStyle.LowIndicatorImage);
245                 }
246
247                 if (sliderStyle.HighIndicatorImage != null)
248                 {
249                     HighIndicatorImage?.CopyFrom(sliderStyle.HighIndicatorImage);
250                 }
251
252                 if (sliderStyle.LowIndicator != null)
253                 {
254                     LowIndicator?.CopyFrom(sliderStyle.LowIndicator);
255                 }
256
257                 if (sliderStyle.HighIndicator != null)
258                 {
259                     HighIndicator?.CopyFrom(sliderStyle.HighIndicator);
260                 }
261
262                 if (sliderStyle.TrackThickness != null)
263                 {
264                     TrackThickness = sliderStyle.TrackThickness;
265                 }
266
267                 if (sliderStyle.TrackPadding != null)
268                 {
269                     TrackPadding = sliderStyle.TrackPadding;
270                 }
271             }
272         }
273
274         /// <summary>
275         /// Dispose SliderStyle and all children on it.
276         /// </summary>
277         /// <param name="type">Dispose type.</param>
278         [EditorBrowsable(EditorBrowsableState.Never)]
279         protected override void Dispose(DisposeTypes type)
280         {
281             if (disposed)
282             {
283                 return;
284             }
285
286             if (type == DisposeTypes.Explicit)
287             {
288                 trackPadding?.Dispose();
289             }
290
291             base.Dispose(type);
292         }
293
294         private void InitSubStyle()
295         {
296             Track = new ImageViewStyle();
297             Progress = new ImageViewStyle();
298             Thumb = new ImageViewStyle();
299             LowIndicatorImage = new ImageViewStyle();
300             HighIndicatorImage = new ImageViewStyle();
301             LowIndicator = new TextLabelStyle();
302             HighIndicator = new TextLabelStyle();
303         }
304
305         private void OnTrackPaddingChanged(ushort start, ushort end, ushort top, ushort bottom)
306         {
307             TrackPadding = new Extents(start, end, top, bottom);
308         }
309     }
310 }