[NUI] Add CircularProgress to Wearable components (#1609)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Wearable / src / public / WearableStyle / CircularProgressStyle.cs
1 /*
2  * Copyright(c) 2020 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 Tizen.NUI.Components;
21
22 namespace Tizen.NUI.Wearable
23 {
24     /// <summary>
25     /// CircularProgressStyle is a class which saves CircularProgress's ux data.
26     /// </summary>
27     [EditorBrowsable(EditorBrowsableState.Never)]
28     public class CircularProgressStyle : ControlStyle
29     {
30         /// <summary>Bindable property of Thickness</summary>
31         [EditorBrowsable(EditorBrowsableState.Never)]
32         public static readonly BindableProperty ThicknessProperty = BindableProperty.Create(nameof(Thickness), typeof(float?), typeof(CircularProgressStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
33         {
34             ((CircularProgressStyle)bindable).thickness = (float?)newValue;
35         },
36         defaultValueCreator: (bindable) =>
37         {
38             return ((CircularProgressStyle)bindable).thickness;
39         });
40
41         /// <summary>Bindable property of MaxValue</summary>
42         [EditorBrowsable(EditorBrowsableState.Never)]
43         public static readonly BindableProperty MaxValueProperty = BindableProperty.Create(nameof(MaxValue), typeof(float), typeof(CircularProgressStyle), default(float), propertyChanged: (bindable, oldValue, newValue) =>
44         {
45             ((CircularProgressStyle)bindable).maxValue = (float)newValue;
46         },
47         defaultValueCreator: (bindable) =>
48         {
49             return ((CircularProgressStyle)bindable).maxValue;
50         });
51
52         /// <summary>Bindable property of MinValue</summary>
53         [EditorBrowsable(EditorBrowsableState.Never)]
54         public static readonly BindableProperty MinValueProperty = BindableProperty.Create(nameof(MinValue), typeof(float), typeof(CircularProgressStyle), default(float), propertyChanged: (bindable, oldValue, newValue) =>
55         {
56             ((CircularProgressStyle)bindable).minValue = (float)newValue;
57         },
58         defaultValueCreator: (bindable) =>
59         {
60             return ((CircularProgressStyle)bindable).minValue;
61         });
62
63         /// <summary>Bindable property of CurrentValue</summary>
64         [EditorBrowsable(EditorBrowsableState.Never)]
65         public static readonly BindableProperty CurrentValueProperty = BindableProperty.Create("currentValue", typeof(float), typeof(CircularProgressStyle), default(float), propertyChanged: (bindable, oldValue, newValue) =>
66         {
67             ((CircularProgressStyle)bindable).currentValue = (float)newValue;
68         },
69         defaultValueCreator: (bindable) =>
70         {
71             return ((CircularProgressStyle)bindable).currentValue;
72         });
73
74         /// <summary>Bindable property of TrackColor</summary>
75         [EditorBrowsable(EditorBrowsableState.Never)]
76         public static readonly BindableProperty TrackColorProperty = BindableProperty.Create("trackColor", typeof(Color), typeof(CircularProgressStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
77         {
78             ((CircularProgressStyle)bindable).trackColor = (Color)newValue;
79         },
80         defaultValueCreator: (bindable) =>
81         {
82             return ((CircularProgressStyle)bindable).trackColor;
83         });
84
85         /// <summary>Bindable property of ProgressColor</summary>
86         [EditorBrowsable(EditorBrowsableState.Never)]
87         public static readonly BindableProperty ProgressColorProperty = BindableProperty.Create("progressColor", typeof(Color), typeof(CircularProgressStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
88         {
89             ((CircularProgressStyle)bindable).progressColor = (Color)newValue;
90         },
91         defaultValueCreator: (bindable) =>
92         {
93             return ((CircularProgressStyle)bindable).progressColor;
94         });
95
96         /// <summary>Bindable property of IsEnabled</summary>
97         [EditorBrowsable(EditorBrowsableState.Never)]
98         public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool?), typeof(CircularProgressStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
99         {
100             ((CircularProgressStyle)bindable).isEnabled = (bool?)newValue;
101         },
102         defaultValueCreator: (bindable) =>
103         {
104             return ((CircularProgressStyle)bindable).isEnabled;
105         });
106
107         private float? thickness;
108         private float maxValue;
109         private float minValue;
110         private float currentValue;
111         private Color trackColor;
112         private Color progressColor;
113         private bool? isEnabled;
114
115         static CircularProgressStyle() { }
116
117         /// <summary>
118         /// Creates a new instance of a CircularProgressStyle.
119         /// </summary>
120         [EditorBrowsable(EditorBrowsableState.Never)]
121         public CircularProgressStyle() : base()
122         {
123             Initialize();
124         }
125
126         /// <summary>
127         /// Creates a new instance of a CircularProgressStyle with style.
128         /// </summary>
129         /// <param name="style">Create CircularProgressStyle by style customized by user.</param>
130         [EditorBrowsable(EditorBrowsableState.Never)]
131         public CircularProgressStyle(CircularProgressStyle style) : base(style)
132         {
133             if (null == style) return;
134             this.CopyFrom(style);
135         }
136
137         /// <summary>
138         /// The thickness of the track and progress.
139         /// </summary>
140         [EditorBrowsable(EditorBrowsableState.Never)]
141         public float? Thickness
142         {
143             get
144             {
145                 return (float?)GetValue(ThicknessProperty);
146             }
147             set
148             {
149                 SetValue(ThicknessProperty, value);
150             }
151         }
152
153         /// <summary>
154         /// The property to get/set the maximum value of the CircularProgress.
155         /// </summary>
156         [EditorBrowsable(EditorBrowsableState.Never)]
157         public float MaxValue
158         {
159             get
160             {
161                 return (float)GetValue(MaxValueProperty);
162             }
163             set
164             {
165                 SetValue(MaxValueProperty, value);
166             }
167         }
168
169         /// <summary>
170         /// The property to get/set the minim value of the CircularProgress.
171         /// </summary>
172         [EditorBrowsable(EditorBrowsableState.Never)]
173         public float MinValue
174         {
175             get
176             {
177                 return (float)GetValue(MinValueProperty);
178             }
179             set
180             {
181                 SetValue(MinValueProperty, value);
182             }
183         }
184
185         /// <summary>
186         /// The property to get/set the current value of the CircularProgress.
187         /// </summary>
188         [EditorBrowsable(EditorBrowsableState.Never)]
189         public float CurrentValue
190         {
191             get
192             {
193                 return (float)GetValue(CurrentValueProperty);
194             }
195             set
196             {
197                 SetValue(CurrentValueProperty, value);
198             }
199         }
200
201         /// <summary>
202         /// The property to get/set Track object color of the CircularProgress.
203         /// </summary>
204         [EditorBrowsable(EditorBrowsableState.Never)]
205         public Color TrackColor
206         {
207             get
208             {
209                 return (Color)GetValue(TrackColorProperty);
210             }
211             set
212             {
213                 SetValue(TrackColorProperty, value);
214             }
215         }
216
217         /// <summary>
218         /// The property to get/set Progress object color of the CircularProgress.
219         /// </summary>
220         [EditorBrowsable(EditorBrowsableState.Never)]
221         public Color ProgressColor
222         {
223             get
224             {
225                 return (Color)GetValue(ProgressColorProperty);
226             }
227             set
228             {
229                 SetValue(ProgressColorProperty, value);
230             }
231         }
232
233         /// <summary>
234         /// Flag to be enabled or disabled in CircularProgress.
235         /// </summary>
236         /// <since_tizen> 8 </since_tizen>
237         public bool? IsEnabled
238         {
239             get
240             {
241                 return (bool?)GetValue(IsEnabledProperty);
242             }
243             set
244             {
245                 SetValue(IsEnabledProperty, value);
246             }
247         }
248
249         /// <summary>
250         /// Style's clone function.
251         /// </summary>
252         /// <param name="bindableObject">The style that need to copy.</param>
253         [EditorBrowsable(EditorBrowsableState.Never)]
254         public override void CopyFrom(BindableObject bindableObject)
255         {
256             base.CopyFrom(bindableObject);
257
258             CircularProgressStyle progressStyle = bindableObject as CircularProgressStyle;
259
260             if (null != progressStyle)
261             {
262                 isEnabled = progressStyle.isEnabled;
263                 thickness = progressStyle.Thickness;
264                 maxValue = progressStyle.maxValue;
265                 minValue = progressStyle.minValue;
266                 currentValue = progressStyle.currentValue;
267                 trackColor = progressStyle.trackColor;
268                 progressColor = progressStyle.progressColor;
269             }
270         }
271
272         private void Initialize()
273         {
274             isEnabled = true;
275             thickness = 6.0f;
276             maxValue = 100.0f;
277             minValue = 0.0f;
278             currentValue = 0.0f;
279             trackColor = new Color(0.0f, 0.16f, 0.30f, 1.0f);
280             progressColor = new Color(0.0f, 0.55f, 1.0f, 1.0f);
281         }
282     }
283 }