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