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.ComponentModel;
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Binding;
20 using static Tizen.NUI.Components.Slider;
22 namespace Tizen.NUI.Components
25 /// SliderStyle is a class which saves Slider's ux data.
27 /// <since_tizen> 8 </since_tizen>
28 public class SliderStyle : ControlStyle
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) =>
34 var instance = (SliderStyle)bindable;
37 instance.privateIndicatorType = (IndicatorType)newValue;
40 defaultValueCreator: (bindable) =>
42 var instance = (SliderStyle)bindable;
43 return instance.privateIndicatorType;
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) =>
49 var instance = (SliderStyle)bindable;
52 instance.privateSpaceBetweenTrackAndIndicator = (uint?)newValue;
55 defaultValueCreator: (bindable) =>
57 var instance = (SliderStyle)bindable;
58 return instance.privateSpaceBetweenTrackAndIndicator;
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) =>
64 var instance = (SliderStyle)bindable;
67 instance.privateTrackThickness = (uint?)newValue;
70 defaultValueCreator: (bindable) =>
72 var instance = (SliderStyle)bindable;
73 return instance.privateTrackThickness;
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) =>
79 var instance = (SliderStyle)bindable;
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);
86 defaultValueCreator: (bindable) =>
88 var instance = (SliderStyle)bindable;
89 return instance.trackPadding;
92 private IndicatorType? privateIndicatorType;
93 private uint? privateTrackThickness;
94 private uint? privateSpaceBetweenTrackAndIndicator;
95 private Extents trackPadding;
97 static SliderStyle() { }
100 /// Creates a new instance of a SliderStyle.
102 /// <since_tizen> 8 </since_tizen>
103 public SliderStyle() : base()
105 IndicatorType = Slider.IndicatorType.None;
110 /// Creates a new instance of a SliderStyle with style.
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)
123 this.CopyFrom(style);
125 IndicatorType = style.IndicatorType;
129 /// Get or set background track.
131 /// <since_tizen> 8 </since_tizen>
132 public ImageViewStyle Track { get; set; }
135 /// Get or set slided track.
137 /// <since_tizen> 8 </since_tizen>
138 public ImageViewStyle Progress { get; set; }
141 /// Get or set thumb.
143 /// <since_tizen> 8 </since_tizen>
144 public ImageViewStyle Thumb { get; set; }
147 /// Get or set low indicator image.
149 /// <since_tizen> 8 </since_tizen>
150 public ImageViewStyle LowIndicatorImage { get; set; }
153 /// Get or set high indicator image.
155 /// <since_tizen> 8 </since_tizen>
156 public ImageViewStyle HighIndicatorImage { get; set; }
159 /// Get or set low indicator text.
161 /// <since_tizen> 8 </since_tizen>
162 public TextLabelStyle LowIndicator { get; set; }
165 /// Get or set high indicator text.
167 /// <since_tizen> 8 </since_tizen>
168 public TextLabelStyle HighIndicator { get; set; }
171 /// Get or set Indicator type
173 /// <since_tizen> 8 </since_tizen>
174 public IndicatorType? IndicatorType
176 get => (IndicatorType?)GetValue(IndicatorTypeProperty);
177 set => SetValue(IndicatorTypeProperty, value);
181 /// Get or set track thickness
183 /// <since_tizen> 8 </since_tizen>
184 public uint? TrackThickness
186 get => (uint?)GetValue(TrackThicknessProperty);
187 set => SetValue(TrackThicknessProperty, value);
191 /// Get or set space between track and indicator
193 /// <since_tizen> 8 </since_tizen>
194 public uint? SpaceBetweenTrackAndIndicator
196 get => (uint?)GetValue(SpaceBetweenTrackAndIndicatorProperty);
197 set => SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
201 /// Get or set space between track and indicator
203 /// <since_tizen> 8 </since_tizen>
204 public Extents TrackPadding
208 Extents tmp = (Extents)GetValue(TrackPaddingProperty);
209 return (null != tmp) ? tmp : trackPadding = new Extents(OnTrackPaddingChanged, 0, 0, 0, 0);
211 set => SetValue(TrackPaddingProperty, value);
215 /// Style's clone function.
217 /// <param name="bindableObject">The style that need to copy.</param>
218 /// <since_tizen> 8 </since_tizen>
219 public override void CopyFrom(BindableObject bindableObject)
221 base.CopyFrom(bindableObject);
223 SliderStyle sliderStyle = bindableObject as SliderStyle;
225 if (null != sliderStyle)
227 if (sliderStyle.Track != null)
229 Track?.CopyFrom(sliderStyle.Track);
232 if (sliderStyle.Progress != null)
234 Progress?.CopyFrom(sliderStyle.Progress);
237 if (sliderStyle.Thumb != null)
239 Thumb?.CopyFrom(sliderStyle.Thumb);
242 if (sliderStyle.LowIndicatorImage != null)
244 LowIndicatorImage?.CopyFrom(sliderStyle.LowIndicatorImage);
247 if (sliderStyle.HighIndicatorImage != null)
249 HighIndicatorImage?.CopyFrom(sliderStyle.HighIndicatorImage);
252 if (sliderStyle.LowIndicator != null)
254 LowIndicator?.CopyFrom(sliderStyle.LowIndicator);
257 if (sliderStyle.HighIndicator != null)
259 HighIndicator?.CopyFrom(sliderStyle.HighIndicator);
262 if (sliderStyle.TrackThickness != null)
264 TrackThickness = sliderStyle.TrackThickness;
267 if (sliderStyle.TrackPadding != null)
269 TrackPadding = sliderStyle.TrackPadding;
275 /// Dispose SliderStyle and all children on it.
277 /// <param name="type">Dispose type.</param>
278 [EditorBrowsable(EditorBrowsableState.Never)]
279 protected override void Dispose(DisposeTypes type)
286 if (type == DisposeTypes.Explicit)
288 trackPadding?.Dispose();
294 private void InitSubStyle()
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();
305 private void OnTrackPaddingChanged(ushort start, ushort end, ushort top, ushort bottom)
307 TrackPadding = new Extents(start, end, top, bottom);