[NUI] Add ImageList property (#2449)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Style / LoadingStyle.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.Collections.Generic;
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// LoadingStyle is a class which saves Loading's ux data.
26     /// </summary>
27     /// <since_tizen> 8 </since_tizen>
28     public class LoadingStyle : ControlStyle
29     {
30         /// <summary>The FrameRateSelector bindable property.</summary>
31         [EditorBrowsable(EditorBrowsableState.Never)]
32         public static readonly BindableProperty FrameRateSelectorProperty = BindableProperty.Create("FrameRateSelector", typeof(Selector<int?>), typeof(LoadingStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
33         {
34             ((LoadingStyle)bindable).frameRate = ((Selector<int?>)newValue)?.Clone();
35         },
36         defaultValueCreator: (bindable) =>
37         {
38             return ((LoadingStyle)bindable).frameRate;
39         });
40
41         /// <summary>The LoadingSize bindable property.</summary>
42         [EditorBrowsable(EditorBrowsableState.Never)]
43         public static readonly BindableProperty LoadingSizeProperty = BindableProperty.Create(nameof(LoadingSize), typeof(Size), typeof(LoadingStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
44         {
45             ((LoadingStyle)bindable).Size = (Size)newValue;
46         },
47         defaultValueCreator: (bindable) =>
48         {
49             return ((LoadingStyle)bindable).Size;
50         });
51
52         /// <summary>The Images bindable property.</summary>
53         [EditorBrowsable(EditorBrowsableState.Never)]
54         public static readonly BindableProperty ImagesProperty = BindableProperty.Create(nameof(Images), typeof(string[]), typeof(LoadingStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
55         {
56             ((LoadingStyle)bindable).images = new List<string>((string[])newValue);
57         },
58         defaultValueCreator: (bindable) =>
59         {
60             if (((LoadingStyle)bindable).images == null)
61             {
62                 ((LoadingStyle)bindable).images = new List<string>();
63             }
64             return ((LoadingStyle)bindable).images?.ToArray();
65         });
66
67         /// <summary>The Images bindable property.</summary>
68         [EditorBrowsable(EditorBrowsableState.Never)]
69         public static readonly BindableProperty ImageListProperty = BindableProperty.Create(nameof(ImageList), typeof(IList<string>), typeof(LoadingStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
70         {
71             ((LoadingStyle)bindable).images = newValue as List<string>;
72         },
73         defaultValueCreator: (bindable) =>
74         {
75             if(((LoadingStyle)bindable).images == null)
76             {
77                 ((LoadingStyle)bindable).images = new List<string>();
78             }
79             return ((LoadingStyle)bindable).images;
80         });
81
82         private Selector<int?> frameRate;
83         private List<string> images;
84
85         static LoadingStyle() { }
86
87         /// <summary>
88         /// Creates a new instance of a LoadingStyle.
89         /// </summary>
90         /// <since_tizen> 8 </since_tizen>
91         public LoadingStyle() : base() { }
92
93         /// <summary>
94         /// Creates a new instance of a LoadingStyle with style.
95         /// </summary>
96         /// <param name="style">Create LoadingStyle by style customized by user.</param>
97         /// <since_tizen> 8 </since_tizen>
98         public LoadingStyle(LoadingStyle style) : base(style)
99         {
100         }
101
102         /// <summary>
103         /// Gets or sets loading image resources.
104         /// </summary>
105         /// <since_tizen> 8 </since_tizen>
106         public string[] Images
107         {
108             get => (string[])GetValue(ImagesProperty);
109             set => SetValue(ImagesProperty, value);
110         }
111
112         /// <summary>
113         /// Gets loading image resources.
114         /// </summary>
115         [EditorBrowsable(EditorBrowsableState.Never)]
116         public IList<string> ImageList
117         {
118             get => GetValue(ImageListProperty) as List<string>;
119             internal set => SetValue(ImageListProperty, value);
120         }
121
122         /// <summary>
123         /// Gets or sets loading image size.
124         /// </summary>
125         /// <since_tizen> 8 </since_tizen>
126         public Size LoadingSize
127         {
128             get => (Size)GetValue(LoadingSizeProperty);
129             set => SetValue(LoadingSizeProperty, value);
130         }
131
132         /// <summary>
133         /// Gets or sets loading frame per second.
134         /// </summary>
135         /// <since_tizen> 8 </since_tizen>
136         public Selector<int?> FrameRate
137         {
138             get => (Selector<int?>)GetValue(FrameRateSelectorProperty);
139             set => SetValue(FrameRateSelectorProperty, value);
140         }
141
142         /// <summary>
143         /// Style's clone function.
144         /// </summary>
145         /// <param name="bindableObject">The style that need to copy.</param>
146         /// <since_tizen> 8 </since_tizen>
147         public override void CopyFrom(BindableObject bindableObject)
148         {
149             base.CopyFrom(bindableObject);
150         }
151     }
152 }