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 gtkc.gtk; 35 public import gtkc.gtktypes; 36 private import std.algorithm; 37 38 39 /** 40 * The #GtkLevelBar is a bar widget that can be used 41 * as a level indicator. Typical use cases are displaying the strength 42 * of a password, or showing the charge level of a battery. 43 * 44 * Use gtk_level_bar_set_value() to set the current value, and 45 * gtk_level_bar_add_offset_value() to set the value offsets at which 46 * the bar will be considered in a different state. GTK will add a few 47 * offsets by default on the level bar: #GTK_LEVEL_BAR_OFFSET_LOW, 48 * #GTK_LEVEL_BAR_OFFSET_HIGH and #GTK_LEVEL_BAR_OFFSET_FULL, with 49 * values 0.25, 0.75 and 1.0 respectively. 50 * 51 * Note that it is your responsibility to update preexisting offsets 52 * when changing the minimum or maximum value. GTK+ will simply clamp 53 * them to the new range. 54 * 55 * ## Adding a custom offset on the bar 56 * 57 * |[<!-- language="C" --> 58 * 59 * static GtkWidget * 60 * create_level_bar (void) 61 * { 62 * GtkWidget *widget; 63 * GtkLevelBar *bar; 64 * 65 * widget = gtk_level_bar_new (); 66 * bar = GTK_LEVEL_BAR (widget); 67 * 68 * // This changes the value of the default low offset 69 * 70 * gtk_level_bar_add_offset_value (bar, 71 * GTK_LEVEL_BAR_OFFSET_LOW, 72 * 0.10); 73 * 74 * // This adds a new offset to the bar; the application will 75 * // be able to change its color CSS like this: 76 * // 77 * // levelbar block.my-offset { 78 * // background-color: magenta; 79 * // border-style: solid; 80 * // border-color: black; 81 * // border-style: 1px; 82 * // } 83 * 84 * gtk_level_bar_add_offset_value (bar, "my-offset", 0.60); 85 * 86 * return widget; 87 * } 88 * ]| 89 * 90 * The default interval of values is between zero and one, but it’s possible to 91 * modify the interval using gtk_level_bar_set_min_value() and 92 * gtk_level_bar_set_max_value(). The value will be always drawn in proportion to 93 * the admissible interval, i.e. a value of 15 with a specified interval between 94 * 10 and 20 is equivalent to a value of 0.5 with an interval between 0 and 1. 95 * When #GTK_LEVEL_BAR_MODE_DISCRETE is used, the bar level is rendered 96 * as a finite number of separated blocks instead of a single one. The number 97 * of blocks that will be rendered is equal to the number of units specified by 98 * the admissible interval. 99 * 100 * For instance, to build a bar rendered with five blocks, it’s sufficient to 101 * set the minimum value to 0 and the maximum value to 5 after changing the indicator 102 * mode to discrete. 103 * 104 * GtkLevelBar was introduced in GTK+ 3.6. 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 * |[<!-- language="plain" --> 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 public class LevelBar : Widget, OrientableIF 135 { 136 /** the main Gtk struct */ 137 protected GtkLevelBar* gtkLevelBar; 138 139 /** Get the main Gtk struct */ 140 public GtkLevelBar* getLevelBarStruct(bool transferOwnership = false) 141 { 142 if (transferOwnership) 143 ownedRef = false; 144 return gtkLevelBar; 145 } 146 147 /** the main Gtk struct as a void* */ 148 protected override void* getStruct() 149 { 150 return cast(void*)gtkLevelBar; 151 } 152 153 protected override void setStruct(GObject* obj) 154 { 155 gtkLevelBar = cast(GtkLevelBar*)obj; 156 super.setStruct(obj); 157 } 158 159 /** 160 * Sets our main struct and passes it to the parent class. 161 */ 162 public this (GtkLevelBar* gtkLevelBar, bool ownedRef = false) 163 { 164 this.gtkLevelBar = gtkLevelBar; 165 super(cast(GtkWidget*)gtkLevelBar, ownedRef); 166 } 167 168 // add the Orientable capabilities 169 mixin OrientableT!(GtkLevelBar); 170 171 172 /** */ 173 public static GType getType() 174 { 175 return gtk_level_bar_get_type(); 176 } 177 178 /** 179 * Creates a new #GtkLevelBar. 180 * 181 * Returns: a #GtkLevelBar. 182 * 183 * Since: 3.6 184 * 185 * Throws: ConstructionException GTK+ fails to create the object. 186 */ 187 public this() 188 { 189 auto p = gtk_level_bar_new(); 190 191 if(p is null) 192 { 193 throw new ConstructionException("null returned by new"); 194 } 195 196 this(cast(GtkLevelBar*) p); 197 } 198 199 /** 200 * Utility constructor that creates a new #GtkLevelBar for the specified 201 * interval. 202 * 203 * Params: 204 * minValue = a positive value 205 * maxValue = a positive value 206 * 207 * Returns: a #GtkLevelBar 208 * 209 * Since: 3.6 210 * 211 * Throws: ConstructionException GTK+ fails to create the object. 212 */ 213 public this(double minValue, double maxValue) 214 { 215 auto p = gtk_level_bar_new_for_interval(minValue, maxValue); 216 217 if(p is null) 218 { 219 throw new ConstructionException("null returned by new_for_interval"); 220 } 221 222 this(cast(GtkLevelBar*) p); 223 } 224 225 /** 226 * Adds a new offset marker on @self at the position specified by @value. 227 * When the bar value is in the interval topped by @value (or between @value 228 * and #GtkLevelBar:max-value in case the offset is the last one on the bar) 229 * a style class named `level-`@name will be applied 230 * when rendering the level bar fill. 231 * If another offset marker named @name exists, its value will be 232 * replaced by @value. 233 * 234 * Params: 235 * name = the name of the new offset 236 * value = the value for the new offset 237 * 238 * Since: 3.6 239 */ 240 public void addOffsetValue(string name, double value) 241 { 242 gtk_level_bar_add_offset_value(gtkLevelBar, Str.toStringz(name), value); 243 } 244 245 /** 246 * Return the value of the #GtkLevelBar:inverted property. 247 * 248 * Returns: %TRUE if the level bar is inverted 249 * 250 * Since: 3.8 251 */ 252 public bool getInverted() 253 { 254 return gtk_level_bar_get_inverted(gtkLevelBar) != 0; 255 } 256 257 /** 258 * Returns the value of the #GtkLevelBar:max-value property. 259 * 260 * Returns: a positive value 261 * 262 * Since: 3.6 263 */ 264 public double getMaxValue() 265 { 266 return gtk_level_bar_get_max_value(gtkLevelBar); 267 } 268 269 /** 270 * Returns the value of the #GtkLevelBar:min-value property. 271 * 272 * Returns: a positive value 273 * 274 * Since: 3.6 275 */ 276 public double getMinValue() 277 { 278 return gtk_level_bar_get_min_value(gtkLevelBar); 279 } 280 281 /** 282 * Returns the value of the #GtkLevelBar:mode property. 283 * 284 * Returns: a #GtkLevelBarMode 285 * 286 * Since: 3.6 287 */ 288 public GtkLevelBarMode getMode() 289 { 290 return gtk_level_bar_get_mode(gtkLevelBar); 291 } 292 293 /** 294 * Fetches the value specified for the offset marker @name in @self, 295 * returning %TRUE in case an offset named @name was found. 296 * 297 * Params: 298 * name = the name of an offset in the bar 299 * value = location where to store the value 300 * 301 * Returns: %TRUE if the specified offset is found 302 * 303 * Since: 3.6 304 */ 305 public bool getOffsetValue(string name, out double value) 306 { 307 return gtk_level_bar_get_offset_value(gtkLevelBar, Str.toStringz(name), &value) != 0; 308 } 309 310 /** 311 * Returns the value of the #GtkLevelBar:value property. 312 * 313 * Returns: a value in the interval between 314 * #GtkLevelBar:min-value and #GtkLevelBar:max-value 315 * 316 * Since: 3.6 317 */ 318 public double getValue() 319 { 320 return gtk_level_bar_get_value(gtkLevelBar); 321 } 322 323 /** 324 * Removes an offset marker previously added with 325 * gtk_level_bar_add_offset_value(). 326 * 327 * Params: 328 * name = the name of an offset in the bar 329 * 330 * Since: 3.6 331 */ 332 public void removeOffsetValue(string name) 333 { 334 gtk_level_bar_remove_offset_value(gtkLevelBar, Str.toStringz(name)); 335 } 336 337 /** 338 * Sets the value of the #GtkLevelBar:inverted property. 339 * 340 * Params: 341 * inverted = %TRUE to invert the level bar 342 * 343 * Since: 3.8 344 */ 345 public void setInverted(bool inverted) 346 { 347 gtk_level_bar_set_inverted(gtkLevelBar, inverted); 348 } 349 350 /** 351 * Sets the value of the #GtkLevelBar:max-value property. 352 * 353 * You probably want to update preexisting level offsets after calling 354 * this function. 355 * 356 * Params: 357 * value = a positive value 358 * 359 * Since: 3.6 360 */ 361 public void setMaxValue(double value) 362 { 363 gtk_level_bar_set_max_value(gtkLevelBar, value); 364 } 365 366 /** 367 * Sets the value of the #GtkLevelBar:min-value property. 368 * 369 * You probably want to update preexisting level offsets after calling 370 * this function. 371 * 372 * Params: 373 * value = a positive value 374 * 375 * Since: 3.6 376 */ 377 public void setMinValue(double value) 378 { 379 gtk_level_bar_set_min_value(gtkLevelBar, value); 380 } 381 382 /** 383 * Sets the value of the #GtkLevelBar:mode property. 384 * 385 * Params: 386 * mode = a #GtkLevelBarMode 387 * 388 * Since: 3.6 389 */ 390 public void setMode(GtkLevelBarMode mode) 391 { 392 gtk_level_bar_set_mode(gtkLevelBar, mode); 393 } 394 395 /** 396 * Sets the value of the #GtkLevelBar:value property. 397 * 398 * Params: 399 * value = a value in the interval between 400 * #GtkLevelBar:min-value and #GtkLevelBar:max-value 401 * 402 * Since: 3.6 403 */ 404 public void setValue(double value) 405 { 406 gtk_level_bar_set_value(gtkLevelBar, value); 407 } 408 409 protected class OnOffsetChangedDelegateWrapper 410 { 411 void delegate(string, LevelBar) dlg; 412 gulong handlerId; 413 414 this(void delegate(string, LevelBar) dlg) 415 { 416 this.dlg = dlg; 417 onOffsetChangedListeners ~= this; 418 } 419 420 void remove(OnOffsetChangedDelegateWrapper source) 421 { 422 foreach(index, wrapper; onOffsetChangedListeners) 423 { 424 if (wrapper.handlerId == source.handlerId) 425 { 426 onOffsetChangedListeners[index] = null; 427 onOffsetChangedListeners = std.algorithm.remove(onOffsetChangedListeners, index); 428 break; 429 } 430 } 431 } 432 } 433 OnOffsetChangedDelegateWrapper[] onOffsetChangedListeners; 434 435 /** 436 * Emitted when an offset specified on the bar changes value as an 437 * effect to gtk_level_bar_add_offset_value() being called. 438 * 439 * The signal supports detailed connections; you can connect to the 440 * detailed signal "changed::x" in order to only receive callbacks when 441 * the value of offset "x" changes. 442 * 443 * Params: 444 * name = the name of the offset that changed value 445 * 446 * Since: 3.6 447 */ 448 gulong addOnOffsetChanged(void delegate(string, LevelBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 449 { 450 auto wrapper = new OnOffsetChangedDelegateWrapper(dlg); 451 wrapper.handlerId = Signals.connectData( 452 this, 453 "offset-changed", 454 cast(GCallback)&callBackOffsetChanged, 455 cast(void*)wrapper, 456 cast(GClosureNotify)&callBackOffsetChangedDestroy, 457 connectFlags); 458 return wrapper.handlerId; 459 } 460 461 extern(C) static void callBackOffsetChanged(GtkLevelBar* levelbarStruct, char* name, OnOffsetChangedDelegateWrapper wrapper) 462 { 463 wrapper.dlg(Str.toString(name), wrapper.outer); 464 } 465 466 extern(C) static void callBackOffsetChangedDestroy(OnOffsetChangedDelegateWrapper wrapper, GClosure* closure) 467 { 468 wrapper.remove(wrapper); 469 } 470 }