Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / ProgressBar.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// The ProgressBar is a widget for visually representing the progress status of a given job/task.
23     /// </summary>
24     public class ProgressBar : Layout
25     {
26         SmartEvent _changed;
27
28         /// <summary>
29         /// Creates and initializes a new instance of the ProgressBar class.
30         /// </summary>
31         /// <param name="parent">The EvasObject to which the new ProgressBar will be attached as a child.</param>
32         public ProgressBar(EvasObject parent) : base(parent)
33         {
34             _changed = new SmartEvent(this, this.RealHandle, "changed");
35             _changed.On += (s, e) =>
36             {
37                 ValueChanged?.Invoke(this, EventArgs.Empty);
38             };
39         }
40
41         /// <summary>
42         /// ValueChanged will be triggered when value of ProgressBar change.
43         /// </summary>
44         public event EventHandler ValueChanged;
45
46         /// <summary>
47         /// Sets or gets the value wheather a given ProgressBar widget is at the "pulsing mode".
48         /// </summary>
49         /// <remarks>
50         /// By default, progress bars display values from low to high value boundaries.
51         /// There are, though, contexts in which the progress of a given task is unknown.
52         /// For such cases, one can set a progress bar widget to a "pulsing state",
53         /// to give the user an idea that some computation is being held,
54         /// but without exact progress values. In the default theme,
55         /// it animates its bar with the contents filling in constantly and back to non-filled, in a loop.
56         /// </remarks>
57         public bool IsPulseMode
58         {
59             get
60             {
61                 return Interop.Elementary.elm_progressbar_pulse_get(RealHandle);
62             }
63             set
64             {
65                 Interop.Elementary.elm_progressbar_pulse_set(RealHandle, value);
66             }
67         }
68
69         /// <summary>
70         /// Sets or gets the value of ProgressBar.
71         /// </summary>
72         /// <remarks>
73         /// Use this property to set the progress bar levels.
74         /// If you pass a value out of the specified range(0.0~1.0),
75         /// it is interpreted as the closest of the boundary values in the range.
76         /// </remarks>
77         public double Value
78         {
79             get
80             {
81                 return Interop.Elementary.elm_progressbar_value_get(RealHandle);
82             }
83             set
84             {
85                 Interop.Elementary.elm_progressbar_value_set(RealHandle, value);
86             }
87         }
88
89         /// <summary>
90         /// Sets or gets the span value of ProgressBar.
91         /// </summary>
92         public int SpanSize
93         {
94             get
95             {
96                 return Interop.Elementary.elm_progressbar_span_size_get(RealHandle);
97             }
98             set
99             {
100                 Interop.Elementary.elm_progressbar_span_size_set(RealHandle, value);
101             }
102         }
103
104         /// <summary>
105         /// Sets or gets the value wheather a given ProgressBar widget is horizontal.
106         /// </summary>
107         public bool IsHorizontal
108         {
109             get
110             {
111                 return Interop.Elementary.elm_progressbar_horizontal_get(RealHandle);
112             }
113             set
114             {
115                 Interop.Elementary.elm_progressbar_horizontal_set(RealHandle, value);
116             }
117         }
118
119         /// <summary>
120         /// Sets or gets the value whether a given progress bar widget's displaying values are inverted.
121         /// </summary>
122         public bool IsInverted
123         {
124             get
125             {
126                 return Interop.Elementary.elm_progressbar_inverted_get(RealHandle);
127             }
128             set
129             {
130                 Interop.Elementary.elm_progressbar_inverted_set(RealHandle, value);
131             }
132         }
133
134         /// <summary>
135         /// Sets or gets format string for a given progress bar widget's units label.
136         /// </summary>
137         /// <remarks>
138         /// If NULL is passed on format, it makes obj units area to be hidden completely.
139         /// If not, it sets the format string for the units label's text.
140         /// The units label is provided with a floating point value, so the units text displays at most one floating point value.
141         /// Note that the units label is optional. Use a format string such as "%1.2f meters" for example.
142         /// The default format string for a progress bar is an integer percentage, as in "%.0f %%".
143         /// </remarks>
144         public string UnitFormat
145         {
146             get
147             {
148                 return Interop.Elementary.elm_progressbar_unit_format_get(RealHandle);
149             }
150             set
151             {
152                 Interop.Elementary.elm_progressbar_unit_format_set(RealHandle, value);
153             }
154         }
155
156         /// <summary>
157         /// Starts a given progress bar "pulsing" animation, if its under that mode.
158         /// </summary>
159         public void PlayPulse()
160         {
161             Interop.Elementary.elm_progressbar_pulse(RealHandle, true);
162         }
163
164         [Obsolete("use StopPulse instead")]
165         public void StopPluse()
166         {
167             Interop.Elementary.elm_progressbar_pulse(RealHandle, false);
168         }
169
170         /// <summary>
171         /// Stops a given progress bar "pulsing" animation, if its under that mode.
172         /// </summary>
173         public void StopPulse()
174         {
175             Interop.Elementary.elm_progressbar_pulse(RealHandle, false);
176         }
177
178         /// <summary>
179         /// Gets the part value of the given part of the Progressbar.
180         /// </summary>
181         /// <param name="part">Part of the Progressbar.</param>
182         /// <returns>Returns value range is from 0.0 to 1.0.</returns>
183         public double GetPartValue(string part)
184         {
185             return Interop.Elementary.elm_progressbar_part_value_get(RealHandle, part);
186         }
187
188         /// <summary>
189         /// Sets or gets the general or main color of the given Progressbar.
190         /// </summary>
191         public override Color Color
192         {
193             get
194             {
195                 return GetPartColor("bar");
196             }
197             set
198             {
199                 SetPartColor("bar", value);
200             }
201         }
202
203         /// <summary>
204         /// Sets the part value of the give part of the Progressbar.
205         /// </summary>
206         /// <param name="part">Part of the Progressbar.</param>
207         /// <param name="value">Value range is from 0.0 to 1.0.</param>
208         public void SetPartValue(string part, double value)
209         {
210             Interop.Elementary.elm_progressbar_part_value_set(RealHandle, part, value);
211         }
212
213         protected override IntPtr CreateHandle(EvasObject parent)
214         {
215             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
216             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
217
218             RealHandle = Interop.Elementary.elm_progressbar_add(handle);
219             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
220
221             return handle;
222         }
223     }
224 }