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 private import std.algorithm;
37 
38 
39 /**
40  * `GtkLevelBar` is a widget that can be used as a level indicator.
41  * 
42  * Typical use cases are displaying the strength of a password, or
43  * showing the charge level of a battery.
44  * 
45  * ![An example GtkLevelBar](levelbar.png)
46  * 
47  * Use [method@Gtk.LevelBar.set_value] to set the current value, and
48  * [method@Gtk.LevelBar.add_offset_value] to set the value offsets at which
49  * the bar will be considered in a different state. GTK will add a few
50  * offsets by default on the level bar: %GTK_LEVEL_BAR_OFFSET_LOW,
51  * %GTK_LEVEL_BAR_OFFSET_HIGH and %GTK_LEVEL_BAR_OFFSET_FULL, with
52  * values 0.25, 0.75 and 1.0 respectively.
53  * 
54  * Note that it is your responsibility to update preexisting offsets
55  * when changing the minimum or maximum value. GTK will simply clamp
56  * them to the new range.
57  * 
58  * ## Adding a custom offset on the bar
59  * 
60  * ```c
61  * static GtkWidget *
62  * create_level_bar (void)
63  * {
64  * GtkWidget *widget;
65  * GtkLevelBar *bar;
66  * 
67  * widget = gtk_level_bar_new ();
68  * bar = GTK_LEVEL_BAR (widget);
69  * 
70  * // This changes the value of the default low offset
71  * 
72  * gtk_level_bar_add_offset_value (bar,
73  * GTK_LEVEL_BAR_OFFSET_LOW,
74  * 0.10);
75  * 
76  * // This adds a new offset to the bar; the application will
77  * // be able to change its color CSS like this:
78  * //
79  * // levelbar block.my-offset {
80  * //   background-color: magenta;
81  * //   border-style: solid;
82  * //   border-color: black;
83  * //   border-style: 1px;
84  * // }
85  * 
86  * gtk_level_bar_add_offset_value (bar, "my-offset", 0.60);
87  * 
88  * return widget;
89  * }
90  * ```
91  * 
92  * The default interval of values is between zero and one, but it’s possible
93  * to modify the interval using [method@Gtk.LevelBar.set_min_value] and
94  * [method@Gtk.LevelBar.set_max_value]. The value will be always drawn in
95  * proportion to the admissible interval, i.e. a value of 15 with a specified
96  * interval between 10 and 20 is equivalent to a value of 0.5 with an interval
97  * between 0 and 1. When #GTK_LEVEL_BAR_MODE_DISCRETE is used, the bar level
98  * is rendered as a finite number of separated blocks instead of a single one.
99  * The number of blocks that will be rendered is equal to the number of units
100  * specified by the admissible interval.
101  * 
102  * For instance, to build a bar rendered with five blocks, it’s sufficient to
103  * set the minimum value to 0 and the maximum value to 5 after changing the
104  * indicator mode to discrete.
105  * 
106  * # GtkLevelBar as GtkBuildable
107  * 
108  * The `GtkLevelBar` implementation of the `GtkBuildable` interface supports a
109  * custom <offsets> element, which can contain any number of <offset> elements,
110  * each of which must have name and value attributes.
111  * 
112  * # CSS nodes
113  * 
114  * ```
115  * levelbar[.discrete]
116  * ╰── trough
117  * ├── block.filled.level-name
118  * ┊
119  * ├── block.empty
120  * ┊
121  * ```
122  * 
123  * `GtkLevelBar` has a main CSS node with name levelbar and one of the style
124  * classes .discrete or .continuous and a subnode with name trough. Below the
125  * trough node are a number of nodes with name block and style class .filled
126  * or .empty. In continuous mode, there is exactly one node of each, in discrete
127  * mode, the number of filled and unfilled nodes corresponds to blocks that are
128  * drawn. The block.filled nodes also get a style class .level-name corresponding
129  * to the level for the current value.
130  * 
131  * In horizontal orientation, the nodes are always arranged from left to right,
132  * regardless of text direction.
133  * 
134  * # Accessibility
135  * 
136  * `GtkLevelBar` uses the #GTK_ACCESSIBLE_ROLE_METER role.
137  */
138 public class LevelBar : Widget, OrientableIF
139 {
140 	/** the main Gtk struct */
141 	protected GtkLevelBar* gtkLevelBar;
142 
143 	/** Get the main Gtk struct */
144 	public GtkLevelBar* getLevelBarStruct(bool transferOwnership = false)
145 	{
146 		if (transferOwnership)
147 			ownedRef = false;
148 		return gtkLevelBar;
149 	}
150 
151 	/** the main Gtk struct as a void* */
152 	protected override void* getStruct()
153 	{
154 		return cast(void*)gtkLevelBar;
155 	}
156 
157 	/**
158 	 * Sets our main struct and passes it to the parent class.
159 	 */
160 	public this (GtkLevelBar* gtkLevelBar, bool ownedRef = false)
161 	{
162 		this.gtkLevelBar = gtkLevelBar;
163 		super(cast(GtkWidget*)gtkLevelBar, ownedRef);
164 	}
165 
166 	// add the Orientable capabilities
167 	mixin OrientableT!(GtkLevelBar);
168 
169 
170 	/** */
171 	public static GType getType()
172 	{
173 		return gtk_level_bar_get_type();
174 	}
175 
176 	/**
177 	 * Creates a new `GtkLevelBar`.
178 	 *
179 	 * Returns: a `GtkLevelBar`.
180 	 *
181 	 * Throws: ConstructionException GTK+ fails to create the object.
182 	 */
183 	public this()
184 	{
185 		auto __p = gtk_level_bar_new();
186 
187 		if(__p is null)
188 		{
189 			throw new ConstructionException("null returned by new");
190 		}
191 
192 		this(cast(GtkLevelBar*) __p);
193 	}
194 
195 	/**
196 	 * Creates a new `GtkLevelBar` for the specified interval.
197 	 *
198 	 * Params:
199 	 *     minValue = a positive value
200 	 *     maxValue = a positive value
201 	 *
202 	 * Returns: a `GtkLevelBar`
203 	 *
204 	 * Throws: ConstructionException GTK+ fails to create the object.
205 	 */
206 	public this(double minValue, double maxValue)
207 	{
208 		auto __p = gtk_level_bar_new_for_interval(minValue, maxValue);
209 
210 		if(__p is null)
211 		{
212 			throw new ConstructionException("null returned by new_for_interval");
213 		}
214 
215 		this(cast(GtkLevelBar*) __p);
216 	}
217 
218 	/**
219 	 * Adds a new offset marker on @self at the position specified by @value.
220 	 *
221 	 * When the bar value is in the interval topped by @value (or between @value
222 	 * and [property@Gtk.LevelBar:max-value] in case the offset is the last one
223 	 * on the bar) a style class named `level-`@name will be applied
224 	 * when rendering the level bar fill.
225 	 *
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 	public void addOffsetValue(string name, double value)
234 	{
235 		gtk_level_bar_add_offset_value(gtkLevelBar, Str.toStringz(name), value);
236 	}
237 
238 	/**
239 	 * Returns whether the levelbar is inverted.
240 	 *
241 	 * Returns: %TRUE if the level bar is inverted
242 	 */
243 	public bool getInverted()
244 	{
245 		return gtk_level_bar_get_inverted(gtkLevelBar) != 0;
246 	}
247 
248 	/**
249 	 * Returns the `max-value` of the `GtkLevelBar`.
250 	 *
251 	 * Returns: a positive value
252 	 */
253 	public double getMaxValue()
254 	{
255 		return gtk_level_bar_get_max_value(gtkLevelBar);
256 	}
257 
258 	/**
259 	 * Returns the `min-value of the `GtkLevelBar`.
260 	 *
261 	 * Returns: a positive value
262 	 */
263 	public double getMinValue()
264 	{
265 		return gtk_level_bar_get_min_value(gtkLevelBar);
266 	}
267 
268 	/**
269 	 * Returns the `mode` of the `GtkLevelBar`.
270 	 *
271 	 * Returns: a `GtkLevelBarMode`
272 	 */
273 	public GtkLevelBarMode getMode()
274 	{
275 		return gtk_level_bar_get_mode(gtkLevelBar);
276 	}
277 
278 	/**
279 	 * Fetches the value specified for the offset marker @name in @self.
280 	 *
281 	 * Params:
282 	 *     name = the name of an offset in the bar
283 	 *     value = location where to store the value
284 	 *
285 	 * Returns: %TRUE if the specified offset is found
286 	 */
287 	public bool getOffsetValue(string name, out double value)
288 	{
289 		return gtk_level_bar_get_offset_value(gtkLevelBar, Str.toStringz(name), &value) != 0;
290 	}
291 
292 	/**
293 	 * Returns the `value` of the `GtkLevelBar`.
294 	 *
295 	 * Returns: a value in the interval between
296 	 *     `GtkLevelBar`:min-value and `GtkLevelBar`:max-value
297 	 */
298 	public double getValue()
299 	{
300 		return gtk_level_bar_get_value(gtkLevelBar);
301 	}
302 
303 	/**
304 	 * Removes an offset marker from a `GtkLevelBar`.
305 	 *
306 	 * The marker must have been previously added with
307 	 * [method@Gtk.LevelBar.add_offset_value].
308 	 *
309 	 * Params:
310 	 *     name = the name of an offset in the bar
311 	 */
312 	public void removeOffsetValue(string name)
313 	{
314 		gtk_level_bar_remove_offset_value(gtkLevelBar, Str.toStringz(name));
315 	}
316 
317 	/**
318 	 * Sets whether the `GtkLevelBar` is inverted.
319 	 *
320 	 * Params:
321 	 *     inverted = %TRUE to invert the level bar
322 	 */
323 	public void setInverted(bool inverted)
324 	{
325 		gtk_level_bar_set_inverted(gtkLevelBar, inverted);
326 	}
327 
328 	/**
329 	 * Sets the `max-value` of the `GtkLevelBar`.
330 	 *
331 	 * You probably want to update preexisting level offsets after calling
332 	 * this function.
333 	 *
334 	 * Params:
335 	 *     value = a positive value
336 	 */
337 	public void setMaxValue(double value)
338 	{
339 		gtk_level_bar_set_max_value(gtkLevelBar, value);
340 	}
341 
342 	/**
343 	 * Sets the `min-value` of the `GtkLevelBar`.
344 	 *
345 	 * You probably want to update preexisting level offsets after calling
346 	 * this function.
347 	 *
348 	 * Params:
349 	 *     value = a positive value
350 	 */
351 	public void setMinValue(double value)
352 	{
353 		gtk_level_bar_set_min_value(gtkLevelBar, value);
354 	}
355 
356 	/**
357 	 * Sets the `mode` of the `GtkLevelBar`.
358 	 *
359 	 * Params:
360 	 *     mode = a `GtkLevelBarMode`
361 	 */
362 	public void setMode(GtkLevelBarMode mode)
363 	{
364 		gtk_level_bar_set_mode(gtkLevelBar, mode);
365 	}
366 
367 	/**
368 	 * Sets the value of the `GtkLevelBar`.
369 	 *
370 	 * Params:
371 	 *     value = a value in the interval between
372 	 *         [property@Gtk.LevelBar:min-value] and [property@Gtk.LevelBar:max-value]
373 	 */
374 	public void setValue(double value)
375 	{
376 		gtk_level_bar_set_value(gtkLevelBar, value);
377 	}
378 
379 	/**
380 	 * Emitted when an offset specified on the bar changes value.
381 	 *
382 	 * This typically is the result of a [method@Gtk.LevelBar.add_offset_value]
383 	 * call.
384 	 *
385 	 * The signal supports detailed connections; you can connect to the
386 	 * detailed signal "changed::x" in order to only receive callbacks when
387 	 * the value of offset "x" changes.
388 	 *
389 	 * Params:
390 	 *     name = the name of the offset that changed value
391 	 */
392 	gulong addOnOffsetChanged(void delegate(string, LevelBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
393 	{
394 		return Signals.connect(this, "offset-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
395 	}
396 }