[NUI] Scrollbar inherits VisualView instead of Control (#1846)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Style / ScrollbarStyle.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
21 namespace Tizen.NUI.Components
22 {
23     /// <summary>
24     /// ScrollbarStyle is a class which saves Scrollbar's style data.
25     /// </summary>
26     [EditorBrowsable(EditorBrowsableState.Never)]
27     public class ScrollbarStyle : ViewStyle
28     {
29         #region Fields
30
31         /// <summary>Bindable property of TrackThickness</summary>
32         [EditorBrowsable(EditorBrowsableState.Never)]
33         public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(float?), typeof(ScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
34         {
35             ((ScrollbarStyle)bindable).trackThickness = (float?)newValue;
36         },
37         defaultValueCreator: (bindable) =>
38         {
39             return ((ScrollbarStyle)bindable).trackThickness;
40         });
41
42         /// <summary>Bindable property of ThumbThickness</summary>
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public static readonly BindableProperty ThumbThicknessProperty = BindableProperty.Create(nameof(ThumbThickness), typeof(float?), typeof(ScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
45         {
46             ((ScrollbarStyle)bindable).thumbThickness = (float?)newValue;
47         },
48         defaultValueCreator: (bindable) =>
49         {
50             return ((ScrollbarStyle)bindable).thumbThickness;
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(ScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
56         {
57             ((ScrollbarStyle)bindable).trackColor = (Color)newValue;
58         },
59         defaultValueCreator: (bindable) =>
60         {
61             return ((ScrollbarStyle)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(ScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
67         {
68             ((ScrollbarStyle)bindable).thumbColor = (Color)newValue;
69         },
70         defaultValueCreator: (bindable) =>
71         {
72             return ((ScrollbarStyle)bindable).thumbColor;
73         });
74
75         /// <summary>Bindable property of TrackPadding</summary>
76         [EditorBrowsable(EditorBrowsableState.Never)]
77         public static readonly BindableProperty TrackPaddingProperty = BindableProperty.Create(nameof(TrackPadding), typeof(Extents), typeof(ScrollbarStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
78         {
79             ((ScrollbarStyle)bindable).trackPadding = (Extents)newValue;
80         },
81         defaultValueCreator: (bindable) =>
82         {
83             return ((ScrollbarStyle)bindable).trackPadding;
84         });
85
86         private float? trackThickness;
87         private float? thumbThickness;
88         private Color trackColor;
89         private Color thumbColor;
90         private Extents trackPadding;
91
92         #endregion Fields
93
94
95         #region Constructors
96
97         /// <summary>
98         /// Creates a new instance of a ScrollbarStyle.
99         /// </summary>
100         [EditorBrowsable(EditorBrowsableState.Never)]
101         public ScrollbarStyle() : base()
102         {
103             Initialize();
104         }
105
106         /// <summary>
107         /// Copy constructor.
108         /// </summary>
109         /// <param name="style">Create ScrollbarStyle by style customized by user.</param>
110         [EditorBrowsable(EditorBrowsableState.Never)]
111         public ScrollbarStyle(ScrollbarStyle style) : base(style)
112         {
113             this.CopyFrom(style);
114         }
115
116         /// <summary>
117         /// Static constructor to initialize bindable properties when loading.
118         /// </summary>
119         static ScrollbarStyle()
120         {
121         }
122
123         #endregion Constructors
124
125
126         #region Properties
127
128         /// <summary>
129         /// The thickness of the track.
130         /// </summary>
131         [EditorBrowsable(EditorBrowsableState.Never)]
132         public float? TrackThickness
133         {
134             get => (float?)GetValue(TrackThicknessProperty);
135             set => SetValue(TrackThicknessProperty, value);
136         }
137
138         /// <summary>
139         /// The thickness of the thumb.
140         /// </summary>
141         [EditorBrowsable(EditorBrowsableState.Never)]
142         public float? ThumbThickness
143         {
144             get => (float?)GetValue(ThumbThicknessProperty);
145             set => SetValue(ThumbThicknessProperty, value);
146         }
147
148         /// <summary>
149         /// The color of the track part.
150         /// </summary>
151         [EditorBrowsable(EditorBrowsableState.Never)]
152         public Color TrackColor
153         {
154             get => (Color)GetValue(TrackColorProperty);
155             set => SetValue(TrackColorProperty, value);
156         }
157
158         /// <summary>
159         /// The color of the thumb part.
160         /// </summary>
161         [EditorBrowsable(EditorBrowsableState.Never)]
162         public Color ThumbColor
163         {
164             get => (Color)GetValue(ThumbColorProperty);
165             set => SetValue(ThumbColorProperty, value);
166         }
167
168         /// <summary>
169         /// The padding value of the track.
170         /// </summary>
171         [EditorBrowsable(EditorBrowsableState.Never)]
172         public Extents TrackPadding
173         {
174             get => (Extents)GetValue(TrackPaddingProperty);
175             set => SetValue(TrackPaddingProperty, value);
176         }
177
178         #endregion Properties
179
180
181         #region Methods
182
183         /// <inheritdoc/>
184         [EditorBrowsable(EditorBrowsableState.Never)]
185         public override void CopyFrom(BindableObject bindableObject)
186         {
187             base.CopyFrom(bindableObject);
188
189             var style = bindableObject as ScrollbarStyle;
190
191             if (null != style)
192             {
193                 TrackThickness = style.TrackThickness;
194                 ThumbThickness = style.ThumbThickness;
195                 TrackColor = style.TrackColor;
196                 ThumbColor = style.ThumbColor;
197                 TrackPadding = style.TrackPadding;
198             }
199         }
200
201         private void Initialize()
202         {
203             TrackThickness = 6.0f;
204             ThumbThickness = 6.0f;
205             TrackColor = new Color(1.0f, 1.0f, 1.0f, 0.15f);
206             ThumbColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
207             TrackPadding = 4;
208             WidthResizePolicy = ResizePolicyType.FillToParent;
209             HeightResizePolicy = ResizePolicyType.FillToParent;
210         }
211
212         #endregion Methods
213     }
214 }