c97f84aca95480089d0b96dd647ac8c14a383c58
[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             ((SliderStyle)bindable).trackPadding = newValue == null ? null : new Extents((Extents)newValue);
80         },
81         defaultValueCreator: (bindable) =>
82         {
83             var instance = (SliderStyle)bindable;
84             return instance.trackPadding;
85         });
86
87         private IndicatorType? privateIndicatorType = Slider.IndicatorType.None;
88         private uint? privateTrackThickness;
89         private uint? privateSpaceBetweenTrackAndIndicator;
90         private Extents trackPadding;
91
92         static SliderStyle() { }
93
94         /// <summary>
95         /// Creates a new instance of a SliderStyle.
96         /// </summary>
97         /// <since_tizen> 8 </since_tizen>
98         public SliderStyle() : base()
99         {
100         }
101
102         /// <summary>
103         /// Creates a new instance of a SliderStyle with style.
104         /// </summary>
105         /// <param name="style">Create SliderStyle by style customized by user.</param>
106         /// <since_tizen> 8 </since_tizen>
107         public SliderStyle(SliderStyle style) : base(style)
108         {
109         }
110
111         /// <summary>
112         /// Get or set background track.
113         /// </summary>
114         /// <since_tizen> 8 </since_tizen>
115         public ImageViewStyle Track { get; set; } = new ImageViewStyle();
116
117         /// <summary>
118         /// Get or set slided track.
119         /// </summary>
120         /// <since_tizen> 8 </since_tizen>
121         public ImageViewStyle Progress { get; set; } = new ImageViewStyle();
122
123         /// <summary>
124         /// Get or set thumb.
125         /// </summary>
126         /// <since_tizen> 8 </since_tizen>
127         public ImageViewStyle Thumb { get; set; } = new ImageViewStyle();
128
129         /// <summary>
130         /// Get or set low indicator image.
131         /// </summary>
132         /// <since_tizen> 8 </since_tizen>
133         public ImageViewStyle LowIndicatorImage { get; set; } = new ImageViewStyle();
134
135         /// <summary>
136         /// Get or set high indicator image.
137         /// </summary>
138         /// <since_tizen> 8 </since_tizen>
139         public ImageViewStyle HighIndicatorImage { get; set; } = new ImageViewStyle();
140
141         /// <summary>
142         /// Get or set low indicator text.
143         /// </summary>
144         /// <since_tizen> 8 </since_tizen>
145         public TextLabelStyle LowIndicator { get; set; } = new TextLabelStyle();
146
147         /// <summary>
148         /// Get or set high indicator text.
149         /// </summary>
150         /// <since_tizen> 8 </since_tizen>
151         public TextLabelStyle HighIndicator { get; set; } = new TextLabelStyle();
152
153         /// <summary>
154         /// Get or set Indicator type
155         /// </summary>
156         /// <since_tizen> 8 </since_tizen>
157         public IndicatorType? IndicatorType
158         {
159             get => (IndicatorType?)GetValue(IndicatorTypeProperty);
160             set => SetValue(IndicatorTypeProperty, value);
161         }
162
163         /// <summary>
164         /// Get or set track thickness
165         /// </summary>
166         /// <since_tizen> 8 </since_tizen>
167         public uint? TrackThickness
168         {
169             get => (uint?)GetValue(TrackThicknessProperty);
170             set => SetValue(TrackThicknessProperty, value);
171         }
172
173         /// <summary>
174         /// Get or set space between track and indicator
175         /// </summary>
176         /// <since_tizen> 8 </since_tizen>
177         public uint? SpaceBetweenTrackAndIndicator
178         {
179             get => (uint?)GetValue(SpaceBetweenTrackAndIndicatorProperty);
180             set => SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
181         }
182
183         /// <summary>
184         /// Get or set space between track and indicator
185         /// </summary>
186         /// <since_tizen> 8 </since_tizen>
187         public Extents TrackPadding
188         {
189             get => ((Extents)GetValue(TrackPaddingProperty)) ?? (trackPadding = new Extents(0, 0, 0, 0));
190             set => SetValue(TrackPaddingProperty, value);
191         }
192
193         /// <summary>
194         /// Style's clone function.
195         /// </summary>
196         /// <param name="bindableObject">The style that need to copy.</param>
197         /// <since_tizen> 8 </since_tizen>
198         public override void CopyFrom(BindableObject bindableObject)
199         {
200             base.CopyFrom(bindableObject);
201
202             if (bindableObject is SliderStyle sliderStyle)
203             {
204                 Track.CopyFrom(sliderStyle.Track);
205                 Progress.CopyFrom(sliderStyle.Progress);
206                 Thumb.CopyFrom(sliderStyle.Thumb);
207                 LowIndicatorImage.CopyFrom(sliderStyle.LowIndicatorImage);
208                 HighIndicatorImage.CopyFrom(sliderStyle.HighIndicatorImage);
209                 LowIndicator.CopyFrom(sliderStyle.LowIndicator);
210                 HighIndicator.CopyFrom(sliderStyle.HighIndicator);
211             }
212         }
213
214         /// <summary>
215         /// Dispose SliderStyle and all children on it.
216         /// </summary>
217         /// <param name="type">Dispose type.</param>
218         [EditorBrowsable(EditorBrowsableState.Never)]
219         protected override void Dispose(DisposeTypes type)
220         {
221             if (disposed)
222             {
223                 return;
224             }
225
226             if (type == DisposeTypes.Explicit)
227             {
228                 trackPadding?.Dispose();
229             }
230
231             base.Dispose(type);
232         }
233     }
234 }