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 public import gtkc.gdktypes; 35 private import gtkc.gtk; 36 public import gtkc.gtktypes; 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() 141 { 142 return gtkLevelBar; 143 } 144 145 /** the main Gtk struct as a void* */ 146 protected override void* getStruct() 147 { 148 return cast(void*)gtkLevelBar; 149 } 150 151 protected override void setStruct(GObject* obj) 152 { 153 gtkLevelBar = cast(GtkLevelBar*)obj; 154 super.setStruct(obj); 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 * Return: a #GtkLevelBar. 180 * 181 * Since: 3.6 182 * 183 * Throws: ConstructionException GTK+ fails to create the object. 184 */ 185 public this() 186 { 187 auto p = gtk_level_bar_new(); 188 189 if(p is null) 190 { 191 throw new ConstructionException("null returned by new"); 192 } 193 194 this(cast(GtkLevelBar*) p); 195 } 196 197 /** 198 * Utility constructor that creates a new #GtkLevelBar for the specified 199 * interval. 200 * 201 * Params: 202 * minValue = a positive value 203 * maxValue = a positive value 204 * 205 * Return: a #GtkLevelBar 206 * 207 * Since: 3.6 208 * 209 * Throws: ConstructionException GTK+ fails to create the object. 210 */ 211 public this(double minValue, double maxValue) 212 { 213 auto p = gtk_level_bar_new_for_interval(minValue, maxValue); 214 215 if(p is null) 216 { 217 throw new ConstructionException("null returned by new_for_interval"); 218 } 219 220 this(cast(GtkLevelBar*) p); 221 } 222 223 /** 224 * Adds a new offset marker on @self at the position specified by @value. 225 * When the bar value is in the interval topped by @value (or between @value 226 * and #GtkLevelBar:max-value in case the offset is the last one on the bar) 227 * a style class named `level-`@name will be applied 228 * when rendering the level bar fill. 229 * If another offset marker named @name exists, its value will be 230 * replaced by @value. 231 * 232 * Params: 233 * name = the name of the new offset 234 * value = the value for the new offset 235 * 236 * Since: 3.6 237 */ 238 public void addOffsetValue(string name, double value) 239 { 240 gtk_level_bar_add_offset_value(gtkLevelBar, Str.toStringz(name), value); 241 } 242 243 /** 244 * Return the value of the #GtkLevelBar:inverted property. 245 * 246 * Return: %TRUE if the level bar is inverted 247 * 248 * Since: 3.8 249 */ 250 public bool getInverted() 251 { 252 return gtk_level_bar_get_inverted(gtkLevelBar) != 0; 253 } 254 255 /** 256 * Returns the value of the #GtkLevelBar:max-value property. 257 * 258 * Return: a positive value 259 * 260 * Since: 3.6 261 */ 262 public double getMaxValue() 263 { 264 return gtk_level_bar_get_max_value(gtkLevelBar); 265 } 266 267 /** 268 * Returns the value of the #GtkLevelBar:min-value property. 269 * 270 * Return: a positive value 271 * 272 * Since: 3.6 273 */ 274 public double getMinValue() 275 { 276 return gtk_level_bar_get_min_value(gtkLevelBar); 277 } 278 279 /** 280 * Returns the value of the #GtkLevelBar:mode property. 281 * 282 * Return: a #GtkLevelBarMode 283 * 284 * Since: 3.6 285 */ 286 public GtkLevelBarMode getMode() 287 { 288 return gtk_level_bar_get_mode(gtkLevelBar); 289 } 290 291 /** 292 * Fetches the value specified for the offset marker @name in @self, 293 * returning %TRUE in case an offset named @name was found. 294 * 295 * Params: 296 * name = the name of an offset in the bar 297 * value = location where to store the value 298 * 299 * Return: %TRUE if the specified offset is found 300 * 301 * Since: 3.6 302 */ 303 public bool getOffsetValue(string name, out double value) 304 { 305 return gtk_level_bar_get_offset_value(gtkLevelBar, Str.toStringz(name), &value) != 0; 306 } 307 308 /** 309 * Returns the value of the #GtkLevelBar:value property. 310 * 311 * Return: a value in the interval between 312 * #GtkLevelBar:min-value and #GtkLevelBar:max-value 313 * 314 * Since: 3.6 315 */ 316 public double getValue() 317 { 318 return gtk_level_bar_get_value(gtkLevelBar); 319 } 320 321 /** 322 * Removes an offset marker previously added with 323 * gtk_level_bar_add_offset_value(). 324 * 325 * Params: 326 * name = the name of an offset in the bar 327 * 328 * Since: 3.6 329 */ 330 public void removeOffsetValue(string name) 331 { 332 gtk_level_bar_remove_offset_value(gtkLevelBar, Str.toStringz(name)); 333 } 334 335 /** 336 * Sets the value of the #GtkLevelBar:inverted property. 337 * 338 * Params: 339 * inverted = %TRUE to invert the level bar 340 * 341 * Since: 3.8 342 */ 343 public void setInverted(bool inverted) 344 { 345 gtk_level_bar_set_inverted(gtkLevelBar, inverted); 346 } 347 348 /** 349 * Sets the value of the #GtkLevelBar:max-value property. 350 * 351 * You probably want to update preexisting level offsets after calling 352 * this function. 353 * 354 * Params: 355 * value = a positive value 356 * 357 * Since: 3.6 358 */ 359 public void setMaxValue(double value) 360 { 361 gtk_level_bar_set_max_value(gtkLevelBar, value); 362 } 363 364 /** 365 * Sets the value of the #GtkLevelBar:min-value property. 366 * 367 * You probably want to update preexisting level offsets after calling 368 * this function. 369 * 370 * Params: 371 * value = a positive value 372 * 373 * Since: 3.6 374 */ 375 public void setMinValue(double value) 376 { 377 gtk_level_bar_set_min_value(gtkLevelBar, value); 378 } 379 380 /** 381 * Sets the value of the #GtkLevelBar:mode property. 382 * 383 * Params: 384 * mode = a #GtkLevelBarMode 385 * 386 * Since: 3.6 387 */ 388 public void setMode(GtkLevelBarMode mode) 389 { 390 gtk_level_bar_set_mode(gtkLevelBar, mode); 391 } 392 393 /** 394 * Sets the value of the #GtkLevelBar:value property. 395 * 396 * Params: 397 * value = a value in the interval between 398 * #GtkLevelBar:min-value and #GtkLevelBar:max-value 399 * 400 * Since: 3.6 401 */ 402 public void setValue(double value) 403 { 404 gtk_level_bar_set_value(gtkLevelBar, value); 405 } 406 407 int[string] connectedSignals; 408 409 void delegate(string, LevelBar)[] onOffsetChangedListeners; 410 /** 411 * Emitted when an offset specified on the bar changes value as an 412 * effect to gtk_level_bar_add_offset_value() being called. 413 * 414 * The signal supports detailed connections; you can connect to the 415 * detailed signal "changed::x" in order to only receive callbacks when 416 * the value of offset "x" changes. 417 * 418 * Params: 419 * name = the name of the offset that changed value 420 * 421 * Since: 3.6 422 */ 423 void addOnOffsetChanged(void delegate(string, LevelBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 424 { 425 if ( "offset-changed" !in connectedSignals ) 426 { 427 Signals.connectData( 428 this, 429 "offset-changed", 430 cast(GCallback)&callBackOffsetChanged, 431 cast(void*)this, 432 null, 433 connectFlags); 434 connectedSignals["offset-changed"] = 1; 435 } 436 onOffsetChangedListeners ~= dlg; 437 } 438 extern(C) static void callBackOffsetChanged(GtkLevelBar* levelbarStruct, char* name, LevelBar _levelbar) 439 { 440 foreach ( void delegate(string, LevelBar) dlg; _levelbar.onOffsetChangedListeners ) 441 { 442 dlg(Str.toString(name), _levelbar); 443 } 444 } 445 }