1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.LevelBar;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.OrientableIF;
32 private import gtk.OrientableT;
33 private import gtk.Widget;
34 private import gtk.c.functions;
35 public  import gtk.c.types;
36 public  import gtkc.gtktypes;
37 private import std.algorithm;
38 
39 
40 /**
41  * The #GtkLevelBar is a bar widget that can be used
42  * as a level indicator. Typical use cases are displaying the strength
43  * of a password, or showing the charge level of a battery.
44  * 
45  * Use gtk_level_bar_set_value() to set the current value, and
46  * gtk_level_bar_add_offset_value() to set the value offsets at which
47  * the bar will be considered in a different state. GTK will add a few
48  * offsets by default on the level bar: #GTK_LEVEL_BAR_OFFSET_LOW,
49  * #GTK_LEVEL_BAR_OFFSET_HIGH and #GTK_LEVEL_BAR_OFFSET_FULL, with
50  * values 0.25, 0.75 and 1.0 respectively.
51  * 
52  * Note that it is your responsibility to update preexisting offsets
53  * when changing the minimum or maximum value. GTK+ will simply clamp
54  * them to the new range.
55  * 
56  * ## Adding a custom offset on the bar
57  * 
58  * |[<!-- language="C" -->
59  * 
60  * static GtkWidget *
61  * create_level_bar (void)
62  * {
63  * GtkWidget *widget;
64  * GtkLevelBar *bar;
65  * 
66  * widget = gtk_level_bar_new ();
67  * bar = GTK_LEVEL_BAR (widget);
68  * 
69  * // This changes the value of the default low offset
70  * 
71  * gtk_level_bar_add_offset_value (bar,
72  * GTK_LEVEL_BAR_OFFSET_LOW,
73  * 0.10);
74  * 
75  * // This adds a new offset to the bar; the application will
76  * // be able to change its color CSS like this:
77  * //
78  * // levelbar block.my-offset {
79  * //   background-color: magenta;
80  * //   border-style: solid;
81  * //   border-color: black;
82  * //   border-style: 1px;
83  * // }
84  * 
85  * gtk_level_bar_add_offset_value (bar, "my-offset", 0.60);
86  * 
87  * return widget;
88  * }
89  * ]|
90  * 
91  * The default interval of values is between zero and one, but it’s possible to
92  * modify the interval using gtk_level_bar_set_min_value() and
93  * gtk_level_bar_set_max_value(). The value will be always drawn in proportion to
94  * the admissible interval, i.e. a value of 15 with a specified interval between
95  * 10 and 20 is equivalent to a value of 0.5 with an interval between 0 and 1.
96  * When #GTK_LEVEL_BAR_MODE_DISCRETE is used, the bar level is rendered
97  * as a finite number of separated blocks instead of a single one. The number
98  * of blocks that will be rendered is equal to the number of units specified by
99  * the admissible interval.
100  * 
101  * For instance, to build a bar rendered with five blocks, it’s sufficient to
102  * set the minimum value to 0 and the maximum value to 5 after changing the indicator
103  * mode to discrete.
104  * 
105  * GtkLevelBar was introduced in GTK+ 3.6.
106  * 
107  * # GtkLevelBar as GtkBuildable
108  * 
109  * The GtkLevelBar implementation of the GtkBuildable interface supports a
110  * custom <offsets> element, which can contain any number of <offset> elements,
111  * each of which must have name and value attributes.
112  * 
113  * # CSS nodes
114  * 
115  * |[<!-- language="plain" -->
116  * levelbar[.discrete]
117  * ╰── trough
118  * ├── block.filled.level-name
119  * ┊
120  * ├── block.empty
121  * ┊
122  * ]|
123  * 
124  * GtkLevelBar has a main CSS node with name levelbar and one of the style
125  * classes .discrete or .continuous and a subnode with name trough. Below the
126  * trough node are a number of nodes with name block and style class .filled
127  * or .empty. In continuous mode, there is exactly one node of each, in discrete
128  * mode, the number of filled and unfilled nodes corresponds to blocks that are
129  * drawn. The block.filled nodes also get a style class .level-name corresponding
130  * to the level for the current value.
131  * 
132  * In horizontal orientation, the nodes are always arranged from left to right,
133  * regardless of text direction.
134  */
135 public class LevelBar : Widget, OrientableIF
136 {
137 	/** the main Gtk struct */
138 	protected GtkLevelBar* gtkLevelBar;
139 
140 	/** Get the main Gtk struct */
141 	public GtkLevelBar* getLevelBarStruct(bool transferOwnership = false)
142 	{
143 		if (transferOwnership)
144 			ownedRef = false;
145 		return gtkLevelBar;
146 	}
147 
148 	/** the main Gtk struct as a void* */
149 	protected override void* getStruct()
150 	{
151 		return cast(void*)gtkLevelBar;
152 	}
153 
154 	/**
155 	 * Sets our main struct and passes it to the parent class.
156 	 */
157 	public this (GtkLevelBar* gtkLevelBar, bool ownedRef = false)
158 	{
159 		this.gtkLevelBar = gtkLevelBar;
160 		super(cast(GtkWidget*)gtkLevelBar, ownedRef);
161 	}
162 
163 	// add the Orientable capabilities
164 	mixin OrientableT!(GtkLevelBar);
165 
166 
167 	/** */
168 	public static GType getType()
169 	{
170 		return gtk_level_bar_get_type();
171 	}
172 
173 	/**
174 	 * Creates a new #GtkLevelBar.
175 	 *
176 	 * Returns: a #GtkLevelBar.
177 	 *
178 	 * Since: 3.6
179 	 *
180 	 * Throws: ConstructionException GTK+ fails to create the object.
181 	 */
182 	public this()
183 	{
184 		auto p = gtk_level_bar_new();
185 
186 		if(p is null)
187 		{
188 			throw new ConstructionException("null returned by new");
189 		}
190 
191 		this(cast(GtkLevelBar*) p);
192 	}
193 
194 	/**
195 	 * Utility constructor that creates a new #GtkLevelBar for the specified
196 	 * interval.
197 	 *
198 	 * Params:
199 	 *     minValue = a positive value
200 	 *     maxValue = a positive value
201 	 *
202 	 * Returns: a #GtkLevelBar
203 	 *
204 	 * Since: 3.6
205 	 *
206 	 * Throws: ConstructionException GTK+ fails to create the object.
207 	 */
208 	public this(double minValue, double maxValue)
209 	{
210 		auto p = gtk_level_bar_new_for_interval(minValue, maxValue);
211 
212 		if(p is null)
213 		{
214 			throw new ConstructionException("null returned by new_for_interval");
215 		}
216 
217 		this(cast(GtkLevelBar*) p);
218 	}
219 
220 	/**
221 	 * Adds a new offset marker on @self at the position specified by @value.
222 	 * When the bar value is in the interval topped by @value (or between @value
223 	 * and #GtkLevelBar:max-value in case the offset is the last one on the bar)
224 	 * a style class named `level-`@name will be applied
225 	 * when rendering the level bar fill.
226 	 * If another offset marker named @name exists, its value will be
227 	 * replaced by @value.
228 	 *
229 	 * Params:
230 	 *     name = the name of the new offset
231 	 *     value = the value for the new offset
232 	 *
233 	 * Since: 3.6
234 	 */
235 	public void addOffsetValue(string name, double value)
236 	{
237 		gtk_level_bar_add_offset_value(gtkLevelBar, Str.toStringz(name), value);
238 	}
239 
240 	/**
241 	 * Return the value of the #GtkLevelBar:inverted property.
242 	 *
243 	 * Returns: %TRUE if the level bar is inverted
244 	 *
245 	 * Since: 3.8
246 	 */
247 	public bool getInverted()
248 	{
249 		return gtk_level_bar_get_inverted(gtkLevelBar) != 0;
250 	}
251 
252 	/**
253 	 * Returns the value of the #GtkLevelBar:max-value property.
254 	 *
255 	 * Returns: a positive value
256 	 *
257 	 * Since: 3.6
258 	 */
259 	public double getMaxValue()
260 	{
261 		return gtk_level_bar_get_max_value(gtkLevelBar);
262 	}
263 
264 	/**
265 	 * Returns the value of the #GtkLevelBar:min-value property.
266 	 *
267 	 * Returns: a positive value
268 	 *
269 	 * Since: 3.6
270 	 */
271 	public double getMinValue()
272 	{
273 		return gtk_level_bar_get_min_value(gtkLevelBar);
274 	}
275 
276 	/**
277 	 * Returns the value of the #GtkLevelBar:mode property.
278 	 *
279 	 * Returns: a #GtkLevelBarMode
280 	 *
281 	 * Since: 3.6
282 	 */
283 	public GtkLevelBarMode getMode()
284 	{
285 		return gtk_level_bar_get_mode(gtkLevelBar);
286 	}
287 
288 	/**
289 	 * Fetches the value specified for the offset marker @name in @self,
290 	 * returning %TRUE in case an offset named @name was found.
291 	 *
292 	 * Params:
293 	 *     name = the name of an offset in the bar
294 	 *     value = location where to store the value
295 	 *
296 	 * Returns: %TRUE if the specified offset is found
297 	 *
298 	 * Since: 3.6
299 	 */
300 	public bool getOffsetValue(string name, out double value)
301 	{
302 		return gtk_level_bar_get_offset_value(gtkLevelBar, Str.toStringz(name), &value) != 0;
303 	}
304 
305 	/**
306 	 * Returns the value of the #GtkLevelBar:value property.
307 	 *
308 	 * Returns: a value in the interval between
309 	 *     #GtkLevelBar:min-value and #GtkLevelBar:max-value
310 	 *
311 	 * Since: 3.6
312 	 */
313 	public double getValue()
314 	{
315 		return gtk_level_bar_get_value(gtkLevelBar);
316 	}
317 
318 	/**
319 	 * Removes an offset marker previously added with
320 	 * gtk_level_bar_add_offset_value().
321 	 *
322 	 * Params:
323 	 *     name = the name of an offset in the bar
324 	 *
325 	 * Since: 3.6
326 	 */
327 	public void removeOffsetValue(string name)
328 	{
329 		gtk_level_bar_remove_offset_value(gtkLevelBar, Str.toStringz(name));
330 	}
331 
332 	/**
333 	 * Sets the value of the #GtkLevelBar:inverted property.
334 	 *
335 	 * Params:
336 	 *     inverted = %TRUE to invert the level bar
337 	 *
338 	 * Since: 3.8
339 	 */
340 	public void setInverted(bool inverted)
341 	{
342 		gtk_level_bar_set_inverted(gtkLevelBar, inverted);
343 	}
344 
345 	/**
346 	 * Sets the value of the #GtkLevelBar:max-value property.
347 	 *
348 	 * You probably want to update preexisting level offsets after calling
349 	 * this function.
350 	 *
351 	 * Params:
352 	 *     value = a positive value
353 	 *
354 	 * Since: 3.6
355 	 */
356 	public void setMaxValue(double value)
357 	{
358 		gtk_level_bar_set_max_value(gtkLevelBar, value);
359 	}
360 
361 	/**
362 	 * Sets the value of the #GtkLevelBar:min-value property.
363 	 *
364 	 * You probably want to update preexisting level offsets after calling
365 	 * this function.
366 	 *
367 	 * Params:
368 	 *     value = a positive value
369 	 *
370 	 * Since: 3.6
371 	 */
372 	public void setMinValue(double value)
373 	{
374 		gtk_level_bar_set_min_value(gtkLevelBar, value);
375 	}
376 
377 	/**
378 	 * Sets the value of the #GtkLevelBar:mode property.
379 	 *
380 	 * Params:
381 	 *     mode = a #GtkLevelBarMode
382 	 *
383 	 * Since: 3.6
384 	 */
385 	public void setMode(GtkLevelBarMode mode)
386 	{
387 		gtk_level_bar_set_mode(gtkLevelBar, mode);
388 	}
389 
390 	/**
391 	 * Sets the value of the #GtkLevelBar:value property.
392 	 *
393 	 * Params:
394 	 *     value = a value in the interval between
395 	 *         #GtkLevelBar:min-value and #GtkLevelBar:max-value
396 	 *
397 	 * Since: 3.6
398 	 */
399 	public void setValue(double value)
400 	{
401 		gtk_level_bar_set_value(gtkLevelBar, value);
402 	}
403 
404 	/**
405 	 * Emitted when an offset specified on the bar changes value as an
406 	 * effect to gtk_level_bar_add_offset_value() being called.
407 	 *
408 	 * The signal supports detailed connections; you can connect to the
409 	 * detailed signal "changed::x" in order to only receive callbacks when
410 	 * the value of offset "x" changes.
411 	 *
412 	 * Params:
413 	 *     name = the name of the offset that changed value
414 	 *
415 	 * Since: 3.6
416 	 */
417 	gulong addOnOffsetChanged(void delegate(string, LevelBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
418 	{
419 		return Signals.connect(this, "offset-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
420 	}
421 }