[ACR-564] deprecate unused API
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Wearable / src / public / CircularScrollbar.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;
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
21 using Tizen.NUI.Components;
22
23 namespace Tizen.NUI.Wearable
24 {
25     /// <summary>
26     /// The CircualrScrollbar is a wearable NUI component that can be linked to the scrollable objects
27     /// indicating the current scroll position of the scrollable object.<br />
28     /// </summary>
29     [Obsolete("This has been deprecated in API12")]
30     [EditorBrowsable(EditorBrowsableState.Never)]
31     public class CircularScrollbar : ScrollbarBase
32     {
33         #region Fields
34
35         /// <summary>Bindable property of Thickness</summary>
36         [Obsolete("This has been deprecated in API12")]
37         [EditorBrowsable(EditorBrowsableState.Never)]
38         public static readonly BindableProperty ThicknessProperty = BindableProperty.Create(nameof(Thickness), typeof(float), typeof(CircularScrollbar), default(float), propertyChanged: (bindable, oldValue, newValue) =>
39         {
40             var instance = ((CircularScrollbar)bindable);
41             float value = (float?)newValue ?? 0;
42             instance.CurrentStyle.Thickness = value;
43             instance.UpdateVisualThickness(value);
44         },
45         defaultValueCreator: (bindable) =>
46         {
47             var instance = (CircularScrollbar)bindable;
48             return instance.CurrentStyle.Thickness ?? 0;
49         });
50
51         /// <summary>Bindable property of TrackSweepAngle</summary>
52         [EditorBrowsable(EditorBrowsableState.Never)]
53         public static readonly BindableProperty TrackSweepAngleProperty = BindableProperty.Create(nameof(TrackSweepAngle), typeof(float), typeof(CircularScrollbar), default(float), propertyChanged: (bindable, oldValue, newValue) =>
54         {
55             var instance = ((CircularScrollbar)bindable);
56             float value = (float?)newValue ?? 0;
57             instance.CurrentStyle.TrackSweepAngle = value;
58             instance.UpdateTrackVisualSweepAngle(value);
59         },
60         defaultValueCreator: (bindable) =>
61         {
62             var instance = (CircularScrollbar)bindable;
63             return instance.CurrentStyle.TrackSweepAngle ?? 0;
64         });
65
66         /// <summary>Bindable property of TrackColor</summary>
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public static readonly BindableProperty TrackColorProperty = BindableProperty.Create(nameof(TrackColor), typeof(Color), typeof(CircularScrollbar), null, propertyChanged: (bindable, oldValue, newValue) =>
69         {
70             var instance = ((CircularScrollbar)bindable);
71             instance.CurrentStyle.TrackColor = (Color)newValue;
72             instance.UpdateTrackVisualColor((Color)newValue);
73         },
74         defaultValueCreator: (bindable) =>
75         {
76             return ((CircularScrollbar)bindable).CurrentStyle.TrackColor;
77         });
78
79         /// <summary>Bindable property of ThumbColor</summary>
80         [EditorBrowsable(EditorBrowsableState.Never)]
81         public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(CircularScrollbar), null, propertyChanged: (bindable, oldValue, newValue) =>
82         {
83             var instance = ((CircularScrollbar)bindable);
84             instance.CurrentStyle.ThumbColor = (Color)newValue;
85             instance.UpdateThumbVisualColor((Color)newValue);
86         },
87         defaultValueCreator: (bindable) =>
88         {
89             return ((CircularScrollbar)bindable).CurrentStyle.ThumbColor;
90         });
91
92         private ArcVisual trackVisual;
93         private ArcVisual thumbVisual;
94         private float contentLength;
95         private float visibleLength;
96         private float previousPosition;
97         private float currentPosition;
98         private float directionAlpha;
99         private Size containerSize = new Size(0, 0);
100         private Animation thumbStartAngleAnimation;
101         private Animation thumbSweepAngleAnimation;
102
103         #endregion Fields
104
105
106         #region Constructors
107
108         /// <summary>
109         /// Create an empty CircularScrollbar.
110         /// </summary>
111         [Obsolete("This has been deprecated in API12")]
112         public CircularScrollbar() : base()
113         {
114         }
115
116         /// <summary>
117         /// Create a CircularScrollbar and initialize with properties.
118         /// </summary>
119         /// <param name="contentLength">The length of the scrollable content area.</param>
120         /// <param name="viewportLength">The length of the viewport representing the amount of visible content.</param>
121         /// <param name="currentPosition">The current position of the viewport in scrollable content area. This is the viewport's top position if the scroller is vertical, otherwise, left.</param>
122         /// <param name="isHorizontal">Whether the direction of scrolling is horizontal or not. It is vertical by default.</param>
123         [Obsolete("This has been deprecated in API12")]
124         [EditorBrowsable(EditorBrowsableState.Never)]
125         public CircularScrollbar(float contentLength, float viewportLength, float currentPosition, bool isHorizontal = false) : base()
126         {
127             Initialize(contentLength, viewportLength, currentPosition, isHorizontal);
128         }
129
130         /// <summary>
131         /// Create an empty CircularScrollbar with a CircularScrollbarStyle instance to set style properties.
132         /// </summary>
133         [Obsolete("This has been deprecated in API12")]
134         [EditorBrowsable(EditorBrowsableState.Never)]
135         public CircularScrollbar(CircularScrollbarStyle style) : base(style)
136         {
137         }
138
139         /// <summary>
140         /// Static constructor to initialize bindable properties when loading.
141         /// </summary>
142         static CircularScrollbar()
143         {
144             ThemeManager.AddPackageTheme(DefaultThemeCreator.Instance);
145         }
146
147         #endregion Constructors
148
149
150         #region Properties
151
152         /// <summary>
153         /// The thickness of the scrollbar and track.
154         /// </summary>
155         [Obsolete("This has been deprecated in API12")]
156         [EditorBrowsable(EditorBrowsableState.Never)]
157         public float Thickness
158         {
159             get => (float)GetValue(ThicknessProperty);
160             set => SetValue(ThicknessProperty, value);
161         }
162
163         /// <summary>
164         /// The sweep angle of track area in degrees.
165         /// </summary>
166         /// <remarks>
167         /// Values below 6 degrees are treated as 6 degrees.
168         /// Values exceeding 180 degrees are treated as 180 degrees.
169         /// </remarks>
170         [Obsolete("This has been deprecated in API12")]
171         [EditorBrowsable(EditorBrowsableState.Never)]
172         public float TrackSweepAngle
173         {
174             get => (float)GetValue(TrackSweepAngleProperty);
175             set => SetValue(TrackSweepAngleProperty, value);
176         }
177
178         /// <summary>
179         /// The color of the track part.
180         /// </summary>
181         [Obsolete("This has been deprecated in API12")]
182         [EditorBrowsable(EditorBrowsableState.Never)]
183         public Color TrackColor
184         {
185             get => (Color)GetValue(TrackColorProperty);
186             set => SetValue(TrackColorProperty, value);
187         }
188
189         /// <summary>
190         /// The color of the thumb part.
191         /// </summary>
192         [Obsolete("This has been deprecated in API12")]
193         [EditorBrowsable(EditorBrowsableState.Never)]
194         public Color ThumbColor
195         {
196             get => (Color)GetValue(ThumbColorProperty);
197             set => SetValue(ThumbColorProperty, value);
198         }
199
200         private CircularScrollbarStyle CurrentStyle => ViewStyle as CircularScrollbarStyle;
201
202         #endregion Properties
203
204
205         #region Methods
206
207         /// <inheritdoc/>
208         [Obsolete("This has been deprecated in API12")]
209         [EditorBrowsable(EditorBrowsableState.Never)]
210         public override void Initialize(float contentLength, float viewportLenth, float currentPosition, bool isHorizontal = false)
211         {
212             this.contentLength = contentLength > 0.0f ? contentLength : 0.0f;
213             this.visibleLength = viewportLenth;
214             this.currentPosition = currentPosition;
215             this.directionAlpha = isHorizontal ? 270.0f : 0.0f;
216
217             thumbStartAngleAnimation?.Stop();
218             thumbStartAngleAnimation = null;
219
220             thumbSweepAngleAnimation?.Stop();
221             thumbSweepAngleAnimation = null;
222
223
224             float trackSweepAngle = CalculateTrackSweepAngle(TrackSweepAngle);
225             float trackStartAngle = CalculateTrackStartAngle(trackSweepAngle);
226             float thumbSweepAngle = CalculateThumbSweepAngle(TrackSweepAngle);
227             float thumbStartAngle = CalculateThumbStartAngle(currentPosition, trackStartAngle, trackSweepAngle, thumbSweepAngle);
228
229             if (trackVisual == null)
230             {
231                 trackVisual = new ArcVisual
232                 {
233                     SuppressUpdateVisual = true,
234                     Thickness = this.Thickness,
235                     Cap = ArcVisual.CapType.Round,
236                     MixColor = TrackColor,
237                     Size = containerSize - new Size(2, 2),
238                     SizePolicy = VisualTransformPolicyType.Absolute,
239                     SweepAngle = trackSweepAngle,
240                     StartAngle = trackStartAngle,
241                 };
242
243                 AddVisual("Track", trackVisual);
244             }
245             else
246             {
247                 trackVisual.SweepAngle = trackSweepAngle;
248                 trackVisual.StartAngle = trackStartAngle;
249                 trackVisual.UpdateVisual(true);
250             }
251
252             if (thumbVisual == null)
253             {
254                 thumbVisual = new ArcVisual
255                 {
256                     SuppressUpdateVisual = true,
257                     Thickness = trackVisual.Thickness,
258                     Cap = ArcVisual.CapType.Round,
259                     MixColor = ThumbColor,
260                     Size = containerSize - new Size(2, 2),
261                     SizePolicy = VisualTransformPolicyType.Absolute,
262                     SweepAngle = thumbSweepAngle,
263                     StartAngle = thumbStartAngle,
264                     Opacity = CalculateThumbVisibility() ? 1.0f : 0.0f,
265                 };
266
267                 AddVisual("Thumb", thumbVisual);
268             }
269             else
270             {
271                 thumbVisual.SweepAngle = thumbSweepAngle;
272                 thumbVisual.StartAngle = thumbStartAngle;
273                 thumbVisual.UpdateVisual(true);
274             }
275         }
276
277         /// <inheritdoc/>
278         [Obsolete("This has been deprecated in API12")]
279         [EditorBrowsable(EditorBrowsableState.Never)]
280         public override void Update(float contentLength, float viewportLength, float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
281         {
282             this.visibleLength = viewportLength;
283             Update(contentLength, position, durationMs, alphaFunction);
284         }
285
286         /// <inheritdoc/>
287         [Obsolete("This has been deprecated in API12")]
288         [EditorBrowsable(EditorBrowsableState.Never)]
289         public override void Update(float contentLength, float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
290         {
291             this.previousPosition = this.currentPosition;
292             this.currentPosition = position;
293             this.contentLength = contentLength > 0.0f ? contentLength : 0.0f;
294
295             if (thumbVisual == null)
296             {
297                 return;
298             }
299
300             thumbVisual.SweepAngle = CalculateThumbSweepAngle(TrackSweepAngle);
301             thumbVisual.StartAngle = CalculateThumbStartAngle(position, trackVisual.StartAngle, trackVisual.SweepAngle, thumbVisual.SweepAngle);
302             thumbVisual.Opacity = CalculateThumbVisibility() ? 1.0f : 0.0f;
303
304             if (durationMs == 0)
305             {
306                 thumbVisual.UpdateVisual(true);
307
308                 return;
309             }
310
311             // TODO Support non built-in alpha function for visual trainsition in DALi.
312             AlphaFunction.BuiltinFunctions builtinAlphaFunction = alphaFunction?.GetBuiltinFunction() ?? AlphaFunction.BuiltinFunctions.Default;
313
314             thumbStartAngleAnimation?.Stop();
315             thumbStartAngleAnimation = AnimateVisual(thumbVisual, "startAngle", thumbVisual.StartAngle, 0, (int)durationMs, builtinAlphaFunction);
316             thumbStartAngleAnimation.Play();
317
318             thumbSweepAngleAnimation?.Stop();
319             thumbSweepAngleAnimation = AnimateVisual(thumbVisual, "sweepAngle", thumbVisual.SweepAngle, 0, (int)durationMs, builtinAlphaFunction);
320             thumbSweepAngleAnimation.Play();
321         }
322
323         /// <inheritdoc/>
324         [Obsolete("This has been deprecated in API12")]
325         [EditorBrowsable(EditorBrowsableState.Never)]
326         public override void ScrollTo(float position, uint durationMs = 0, AlphaFunction alphaFunction = null)
327         {
328             previousPosition = currentPosition;
329             currentPosition = position;
330
331             if (ControlState == ControlState.Disabled)
332             {
333                 return;
334             }
335
336             if (thumbVisual == null)
337             {
338                 return;
339             }
340
341             var oldThumbStartAngle = thumbVisual.StartAngle;
342
343             thumbVisual.StartAngle = CalculateThumbStartAngle(position, trackVisual.StartAngle, trackVisual.SweepAngle, thumbVisual.SweepAngle);
344
345             if (durationMs == 0)
346             {
347                 thumbVisual.UpdateVisual(true);
348
349                 return;
350             }
351
352             // TODO Support non built-in alpha function for visual trainsition in DALi.
353             AlphaFunction.BuiltinFunctions builtinAlphaFunction = alphaFunction?.GetBuiltinFunction() ?? AlphaFunction.BuiltinFunctions.Default;
354
355             thumbStartAngleAnimation?.Stop();
356             thumbStartAngleAnimation = AnimateVisual(thumbVisual, "startAngle", thumbVisual.StartAngle, 0, (int)durationMs, builtinAlphaFunction);
357             thumbStartAngleAnimation.Play();
358         }
359
360         /// <inheritdoc/>
361         [Obsolete("This has been deprecated in API12")]
362         [EditorBrowsable(EditorBrowsableState.Never)]
363         public override void OnRelayout(Vector2 size, RelayoutContainer container)
364         {
365             base.OnRelayout(size, container);
366
367             if (size == null || container == null || containerSize == null)
368             {
369                 return;
370             }
371
372             if (size.Width == containerSize.Width && size.Height == containerSize.Height)
373             {
374                 return;
375             }
376
377             containerSize = new Size(size.Width, size.Height);
378
379             if (trackVisual == null)
380             {
381                 return;
382             }
383
384             trackVisual.Size = containerSize - new Size(2, 2);
385             thumbVisual.Size = containerSize - new Size(2, 2);
386             
387             trackVisual.UpdateVisual(true);
388             thumbVisual.UpdateVisual(true);
389         }
390
391         /// <inheritdoc/>
392         [Obsolete("This has been deprecated in API12")]
393         [EditorBrowsable(EditorBrowsableState.Never)]
394         public override void ApplyStyle(ViewStyle viewStyle)
395         {
396             if (viewStyle == null) return;
397             if (viewStyle.WidthResizePolicy == null) viewStyle.WidthResizePolicy = ResizePolicyType.FillToParent;
398             if (viewStyle.HeightResizePolicy == null) viewStyle.HeightResizePolicy = ResizePolicyType.FillToParent;
399
400             base.ApplyStyle(viewStyle);
401         }
402
403         /// <inheritdoc/>
404         [Obsolete("This has been deprecated in API12")]
405         [EditorBrowsable(EditorBrowsableState.Never)]
406         protected override ViewStyle CreateViewStyle()
407         {
408             return new CircularScrollbarStyle();
409         }
410
411         private float CalculateTrackStartAngle(float currentTrackSweepAngle)
412         {
413             return ((180.0f - currentTrackSweepAngle) / 2.0f) + directionAlpha;
414         }
415
416         private float CalculateTrackSweepAngle(float inputTrackSweepAngle)
417         {
418             return Math.Min(Math.Max(inputTrackSweepAngle, 3), 180);
419         }
420
421         private float CalculateThumbStartAngle(float position, float trackStartAngle, float trackSweepAngle, float thumbSweepAngle)
422         {
423             float minAngle = trackStartAngle;
424             float maxAngle = trackStartAngle + trackSweepAngle - thumbSweepAngle;
425             float resultAngle = trackStartAngle + (trackSweepAngle * (position < 0.0f ? 0.0f : position) / contentLength);
426
427             return Math.Min(Math.Max(resultAngle, minAngle), maxAngle);
428         }
429
430         private float CalculateThumbSweepAngle(float trackSweepAngle)
431         {
432             return trackSweepAngle * visibleLength / contentLength;
433         }
434
435         private bool CalculateThumbVisibility()
436         {
437             return contentLength > visibleLength;
438         }
439
440         private void UpdateVisualThickness(float thickness)
441         {
442             if (trackVisual == null)
443             {
444                 return;
445             }
446
447             trackVisual.Thickness = thickness;
448             thumbVisual.Thickness = thickness;
449
450             trackVisual.UpdateVisual(true);
451             thumbVisual.UpdateVisual(true);
452         }
453
454         private void UpdateTrackVisualSweepAngle(float trackSweepAngle)
455         {
456             if (trackVisual == null || thumbVisual == null)
457             {
458                 return;
459             }
460
461             trackVisual.SweepAngle = CalculateTrackSweepAngle(trackSweepAngle);
462             trackVisual.StartAngle = CalculateTrackStartAngle(trackVisual.SweepAngle);
463
464             thumbVisual.SweepAngle = CalculateThumbSweepAngle(TrackSweepAngle);
465             thumbVisual.StartAngle = CalculateThumbStartAngle(currentPosition, trackVisual.StartAngle, trackVisual.SweepAngle, thumbVisual.SweepAngle);
466
467             trackVisual.UpdateVisual(true);
468             thumbVisual.UpdateVisual(true);
469         }
470
471         private void UpdateTrackVisualColor(Color trackColor)
472         {
473             if (trackVisual == null)
474             {
475                 return;
476             }
477
478             trackVisual.MixColor = trackColor;
479             trackVisual.UpdateVisual(true);
480         }
481
482         private void UpdateThumbVisualColor(Color thumbColor)
483         {
484             if (thumbVisual == null)
485             {
486                 return;
487             }
488
489             thumbVisual.MixColor = thumbColor;
490             thumbVisual.UpdateVisual(true);
491         }
492
493         /// <inheritdoc/>
494         [Obsolete("This has been deprecated in API12")]
495         [EditorBrowsable(EditorBrowsableState.Never)]
496         public override float ScrollPosition
497         {
498             get => Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
499         }
500
501         /// <inheritdoc/>
502         [Obsolete("This has been deprecated in API12")]
503         [EditorBrowsable(EditorBrowsableState.Never)]
504         public override float ScrollCurrentPosition
505         {
506             get
507             {
508                 float length = Math.Min(Math.Max(currentPosition, 0.0f), contentLength - visibleLength);
509
510                 if (thumbStartAngleAnimation != null)
511                 {
512                     float progress = thumbStartAngleAnimation.CurrentProgress;
513                     float previousLength = Math.Min(Math.Max(previousPosition, 0.0f), contentLength - visibleLength);
514
515                     length = ((1.0f - progress) * previousLength) + (progress * length);
516                 }
517
518                 return length;
519             }
520         }
521
522         #endregion Methods
523     }
524 }