[NUI] Scrollbar : Separate the concept of viewport size and view size. (#1632)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Wearable / src / public / WearableStyle / CircularScrollbarStyle.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.Components;
19 using Tizen.NUI.Binding;
20
21 namespace Tizen.NUI.Wearable
22 {
23     /// <summary>
24     /// CircularScrollbarStyle is a class which saves CircularScrollbar's ux data.
25     /// </summary>
26     [EditorBrowsable(EditorBrowsableState.Never)]
27     public class CircularScrollbarStyle : ControlStyle
28     {
29         #region Fields
30
31         /// <summary>Bindable property of Thickness</summary>
32         [EditorBrowsable(EditorBrowsableState.Never)]
33         public static readonly BindableProperty ThicknessProperty = BindableProperty.Create(nameof(Thickness), typeof(float?), typeof(CircularScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
34         {
35             ((CircularScrollbarStyle)bindable).thickness = (float?)newValue;
36         },
37         defaultValueCreator: (bindable) =>
38         {
39             return ((CircularScrollbarStyle)bindable).thickness;
40         });
41
42         /// <summary>Bindable property of TrackSweepAngle</summary>
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public static readonly BindableProperty TrackSweepAngleProperty = BindableProperty.Create(nameof(TrackSweepAngle), typeof(float?), typeof(CircularScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
45         {
46             ((CircularScrollbarStyle)bindable).trackSweepAngle = (float?)newValue;
47         },
48         defaultValueCreator: (bindable) =>
49         {
50             return ((CircularScrollbarStyle)bindable).trackSweepAngle;
51         });
52
53         /// <summary>Bindable property of TrackColor</summary>
54         [EditorBrowsable(EditorBrowsableState.Never)]
55         public static readonly BindableProperty TrackColorProperty = BindableProperty.Create(nameof(TrackColor), typeof(Color), typeof(CircularScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
56         {
57             ((CircularScrollbarStyle)bindable).trackColor = (Color)newValue;
58         },
59         defaultValueCreator: (bindable) =>
60         {
61             return ((CircularScrollbarStyle)bindable).trackColor;
62         });
63
64         /// <summary>Bindable property of ThumbColor</summary>
65         [EditorBrowsable(EditorBrowsableState.Never)]
66         public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(CircularScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
67         {
68             ((CircularScrollbarStyle)bindable).thumbColor = (Color)newValue;
69         },
70         defaultValueCreator: (bindable) =>
71         {
72             return ((CircularScrollbarStyle)bindable).thumbColor;
73         });
74
75         private float? thickness;
76         private float? trackSweepAngle;
77         private Color trackColor;
78         private Color thumbColor;
79
80         #endregion Fields
81
82
83         #region Constructors
84
85         /// <summary>
86         /// Creates a new instance of a CircularScrollbarStyle.
87         /// </summary>
88         [EditorBrowsable(EditorBrowsableState.Never)]
89         public CircularScrollbarStyle() : base()
90         {
91             Initialize();
92         }
93
94         /// <summary>
95         /// Copy constructor.
96         /// </summary>
97         /// <param name="style">Create ScrollbarStyle by style customized by user.</param>
98         [EditorBrowsable(EditorBrowsableState.Never)]
99         public CircularScrollbarStyle(CircularScrollbarStyle style) : base(style)
100         {
101             this.CopyFrom(style);
102         }
103
104         /// <summary>
105         /// Static constructor to initialize bindable properties when loading.
106         /// </summary>
107         static CircularScrollbarStyle()
108         {
109         }
110
111         #endregion Constructors
112
113
114         #region Properties
115
116         /// <summary>
117         /// The thickness of the scrollbar and track.
118         /// </summary>
119         [EditorBrowsable(EditorBrowsableState.Never)]
120         public float? Thickness
121         {
122             get => (float?)GetValue(ThicknessProperty);
123             set => SetValue(ThicknessProperty, value);
124         }
125
126         /// <summary>
127         /// The sweep angle of track area in degrees.
128         /// </summary>
129         /// <remarks>
130         /// Values below 6 degrees are treated as 6 degrees.
131         /// Values exceeding 180 degrees are treated as 180 degrees.
132         /// </remarks>
133         [EditorBrowsable(EditorBrowsableState.Never)]
134         public float? TrackSweepAngle
135         {
136             get => (float?)GetValue(TrackSweepAngleProperty);
137             set => SetValue(TrackSweepAngleProperty, value);
138         }
139
140         /// <summary>
141         /// The color of the track part.
142         /// </summary>
143         [EditorBrowsable(EditorBrowsableState.Never)]
144         public Color TrackColor
145         {
146             get => (Color)GetValue(TrackColorProperty);
147             set => SetValue(TrackColorProperty, value);
148         }
149
150         /// <summary>
151         /// The color of the thumb part.
152         /// </summary>
153         [EditorBrowsable(EditorBrowsableState.Never)]
154         public Color ThumbColor
155         {
156             get => (Color)GetValue(ThumbColorProperty);
157             set => SetValue(ThumbColorProperty, value);
158         }
159
160         #endregion Properties
161
162
163         #region Methods
164
165         /// <inheritdoc/>
166         [EditorBrowsable(EditorBrowsableState.Never)]
167         public override void CopyFrom(BindableObject bindableObject)
168         {
169             base.CopyFrom(bindableObject);
170
171             var style = bindableObject as CircularScrollbarStyle;
172
173             if (null != style)
174             {
175                 Thickness = style.Thickness;
176                 TrackSweepAngle = style.TrackSweepAngle;
177                 TrackColor = style.TrackColor;
178                 ThumbColor = style.ThumbColor;
179             }
180         }
181
182         private void Initialize()
183         {
184             Thickness = 10.0f;
185             TrackSweepAngle = 60.0f;
186             TrackColor = new Color(1.0f, 1.0f, 1.0f, 0.15f);
187             ThumbColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
188             WidthResizePolicy = ResizePolicyType.FillToParent;
189             HeightResizePolicy = ResizePolicyType.FillToParent;
190         }
191
192         #endregion Methods
193     }
194 }