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.Scale; 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.Adjustment; 32 private import gtk.Range; 33 private import gtk.Widget; 34 public import gtkc.gdktypes; 35 private import gtkc.gtk; 36 public import gtkc.gtktypes; 37 private import pango.PgLayout; 38 39 40 /** 41 * A GtkScale is a slider control used to select a numeric value. 42 * To use it, you’ll probably want to investigate the methods on 43 * its base class, #GtkRange, in addition to the methods for GtkScale itself. 44 * To set the value of a scale, you would normally use gtk_range_set_value(). 45 * To detect changes to the value, you would normally use the 46 * #GtkRange::value-changed signal. 47 * 48 * Note that using the same upper and lower bounds for the #GtkScale (through 49 * the #GtkRange methods) will hide the slider itself. This is useful for 50 * applications that want to show an undeterminate value on the scale, without 51 * changing the layout of the application (such as movie or music players). 52 * 53 * # GtkScale as GtkBuildable 54 * 55 * GtkScale supports a custom <marks> element, which can contain multiple 56 * <mark> elements. The “value” and “position” attributes have the same 57 * meaning as gtk_scale_add_mark() parameters of the same name. If the 58 * element is not empty, its content is taken as the markup to show at 59 * the mark. It can be translated with the usual ”translatable” and 60 * “context” attributes. 61 * 62 * # CSS nodes 63 * 64 * |[<!-- language="plain" --> 65 * scale[.fine-tune] 66 * ├── marks.top 67 * │ ├── mark 68 * │ ┊ ├── [label] 69 * │ ┊ ╰── indicator 70 * ┊ ┊ 71 * │ ╰── mark 72 * ├── contents 73 * │ ╰── trough 74 * │ ├── slider 75 * │ ├── [highlight] 76 * │ ╰── [fill] 77 * ╰── marks.bottom 78 * ├── mark 79 * ┊ ├── indicator 80 * ┊ ╰── [label] 81 * ╰── mark 82 * ]| 83 * 84 * GtkScale has a main CSS node with name scale and a subnode for its contents, 85 * with subnodes named trough and slider. 86 * 87 * The main node gets the style class .fine-tune added when the scale is in 88 * 'fine-tuning' mode. 89 * 90 * If the scale has an origin (see gtk_scale_set_has_origin()), there is a 91 * subnode with name highlight below the trough node that is used for rendering 92 * the highlighted part of the trough. 93 * 94 * If the scale is showing a fill level (see gtk_range_set_show_fill_level()), 95 * there is a subnode with name fill below the trough node that is used for 96 * rendering the filled in part of the trough. 97 * 98 * If marks are present, there is a marks subnode before or after the contents 99 * node, below which each mark gets a node with name mark. The marks nodes get 100 * either the .top or .bottom style class. 101 * 102 * The mark node has a subnode named indicator. If the mark has text, it also 103 * has a subnode named label. When the mark is either above or left of the 104 * scale, the label subnode is the first when present. Otherwise, the indicator 105 * subnode is the first. 106 */ 107 public class Scale : Range 108 { 109 /** the main Gtk struct */ 110 protected GtkScale* gtkScale; 111 112 /** Get the main Gtk struct */ 113 public GtkScale* getScaleStruct() 114 { 115 return gtkScale; 116 } 117 118 /** the main Gtk struct as a void* */ 119 protected override void* getStruct() 120 { 121 return cast(void*)gtkScale; 122 } 123 124 protected override void setStruct(GObject* obj) 125 { 126 gtkScale = cast(GtkScale*)obj; 127 super.setStruct(obj); 128 } 129 130 /** 131 * Sets our main struct and passes it to the parent class. 132 */ 133 public this (GtkScale* gtkScale, bool ownedRef = false) 134 { 135 this.gtkScale = gtkScale; 136 super(cast(GtkRange*)gtkScale, ownedRef); 137 } 138 139 140 /** */ 141 public static GType getType() 142 { 143 return gtk_scale_get_type(); 144 } 145 146 /** 147 * Creates a new #GtkScale. 148 * 149 * Params: 150 * orientation = the scale’s orientation. 151 * adjustment = the #GtkAdjustment which sets the range 152 * of the scale, or %NULL to create a new adjustment. 153 * 154 * Return: a new #GtkScale 155 * 156 * Since: 3.0 157 * 158 * Throws: ConstructionException GTK+ fails to create the object. 159 */ 160 public this(GtkOrientation orientation, Adjustment adjustment) 161 { 162 auto p = gtk_scale_new(orientation, (adjustment is null) ? null : adjustment.getAdjustmentStruct()); 163 164 if(p is null) 165 { 166 throw new ConstructionException("null returned by new"); 167 } 168 169 this(cast(GtkScale*) p); 170 } 171 172 /** 173 * Creates a new scale widget with the given orientation that lets the 174 * user input a number between @min and @max (including @min and @max) 175 * with the increment @step. @step must be nonzero; it’s the distance 176 * the slider moves when using the arrow keys to adjust the scale 177 * value. 178 * 179 * Note that the way in which the precision is derived works best if @step 180 * is a power of ten. If the resulting precision is not suitable for your 181 * needs, use gtk_scale_set_digits() to correct it. 182 * 183 * Params: 184 * orientation = the scale’s orientation. 185 * min = minimum value 186 * max = maximum value 187 * step = step increment (tick size) used with keyboard shortcuts 188 * 189 * Return: a new #GtkScale 190 * 191 * Since: 3.0 192 * 193 * Throws: ConstructionException GTK+ fails to create the object. 194 */ 195 public this(GtkOrientation orientation, double min, double max, double step) 196 { 197 auto p = gtk_scale_new_with_range(orientation, min, max, step); 198 199 if(p is null) 200 { 201 throw new ConstructionException("null returned by new_with_range"); 202 } 203 204 this(cast(GtkScale*) p); 205 } 206 207 /** 208 * Adds a mark at @value. 209 * 210 * A mark is indicated visually by drawing a tick mark next to the scale, 211 * and GTK+ makes it easy for the user to position the scale exactly at the 212 * marks value. 213 * 214 * If @markup is not %NULL, text is shown next to the tick mark. 215 * 216 * To remove marks from a scale, use gtk_scale_clear_marks(). 217 * 218 * Params: 219 * value = the value at which the mark is placed, must be between 220 * the lower and upper limits of the scales’ adjustment 221 * position = where to draw the mark. For a horizontal scale, #GTK_POS_TOP 222 * and %GTK_POS_LEFT are drawn above the scale, anything else below. 223 * For a vertical scale, #GTK_POS_LEFT and %GTK_POS_TOP are drawn to 224 * the left of the scale, anything else to the right. 225 * markup = Text to be shown at the mark, using [Pango markup][PangoMarkupFormat], or %NULL 226 * 227 * Since: 2.16 228 */ 229 public void addMark(double value, GtkPositionType position, string markup) 230 { 231 gtk_scale_add_mark(gtkScale, value, position, Str.toStringz(markup)); 232 } 233 234 /** 235 * Removes any marks that have been added with gtk_scale_add_mark(). 236 * 237 * Since: 2.16 238 */ 239 public void clearMarks() 240 { 241 gtk_scale_clear_marks(gtkScale); 242 } 243 244 /** 245 * Gets the number of decimal places that are displayed in the value. 246 * 247 * Return: the number of decimal places that are displayed 248 */ 249 public int getDigits() 250 { 251 return gtk_scale_get_digits(gtkScale); 252 } 253 254 /** 255 * Returns whether the current value is displayed as a string 256 * next to the slider. 257 * 258 * Return: whether the current value is displayed as a string 259 */ 260 public bool getDrawValue() 261 { 262 return gtk_scale_get_draw_value(gtkScale) != 0; 263 } 264 265 /** 266 * Returns whether the scale has an origin. 267 * 268 * Return: %TRUE if the scale has an origin. 269 * 270 * Since: 3.4 271 */ 272 public bool getHasOrigin() 273 { 274 return gtk_scale_get_has_origin(gtkScale) != 0; 275 } 276 277 /** 278 * Gets the #PangoLayout used to display the scale. The returned 279 * object is owned by the scale so does not need to be freed by 280 * the caller. 281 * 282 * Return: the #PangoLayout for this scale, 283 * or %NULL if the #GtkScale:draw-value property is %FALSE. 284 * 285 * Since: 2.4 286 */ 287 public PgLayout getLayout() 288 { 289 auto p = gtk_scale_get_layout(gtkScale); 290 291 if(p is null) 292 { 293 return null; 294 } 295 296 return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) p); 297 } 298 299 /** 300 * Obtains the coordinates where the scale will draw the 301 * #PangoLayout representing the text in the scale. Remember 302 * when using the #PangoLayout function you need to convert to 303 * and from pixels using PANGO_PIXELS() or #PANGO_SCALE. 304 * 305 * If the #GtkScale:draw-value property is %FALSE, the return 306 * values are undefined. 307 * 308 * Params: 309 * x = location to store X offset of layout, or %NULL 310 * y = location to store Y offset of layout, or %NULL 311 * 312 * Since: 2.4 313 */ 314 public void getLayoutOffsets(out int x, out int y) 315 { 316 gtk_scale_get_layout_offsets(gtkScale, &x, &y); 317 } 318 319 /** 320 * Gets the position in which the current value is displayed. 321 * 322 * Return: the position in which the current value is displayed 323 */ 324 public GtkPositionType getValuePos() 325 { 326 return gtk_scale_get_value_pos(gtkScale); 327 } 328 329 /** 330 * Sets the number of decimal places that are displayed in the value. 331 * Also causes the value of the adjustment to be rounded off to this 332 * number of digits, so the retrieved value matches the value the user saw. 333 * 334 * Params: 335 * digits = the number of decimal places to display, 336 * e.g. use 1 to display 1.0, 2 to display 1.00, etc 337 */ 338 public void setDigits(int digits) 339 { 340 gtk_scale_set_digits(gtkScale, digits); 341 } 342 343 /** 344 * Specifies whether the current value is displayed as a string next 345 * to the slider. 346 * 347 * Params: 348 * drawValue = %TRUE to draw the value 349 */ 350 public void setDrawValue(bool drawValue) 351 { 352 gtk_scale_set_draw_value(gtkScale, drawValue); 353 } 354 355 /** 356 * If @has_origin is set to %TRUE (the default), 357 * the scale will highlight the part of the scale 358 * between the origin (bottom or left side) of the scale 359 * and the current value. 360 * 361 * Params: 362 * hasOrigin = %TRUE if the scale has an origin 363 * 364 * Since: 3.4 365 */ 366 public void setHasOrigin(bool hasOrigin) 367 { 368 gtk_scale_set_has_origin(gtkScale, hasOrigin); 369 } 370 371 /** 372 * Sets the position in which the current value is displayed. 373 * 374 * Params: 375 * pos = the position in which the current value is displayed 376 */ 377 public void setValuePos(GtkPositionType pos) 378 { 379 gtk_scale_set_value_pos(gtkScale, pos); 380 } 381 382 int[string] connectedSignals; 383 384 string delegate(double, Scale)[] onFormatValueListeners; 385 /** 386 * Signal which allows you to change how the scale value is displayed. 387 * Connect a signal handler which returns an allocated string representing 388 * @value. That string will then be used to display the scale's value. 389 * 390 * Here's an example signal handler which displays a value 1.0 as 391 * with "-->1.0<--". 392 * |[<!-- language="C" --> 393 * static gchar* 394 * format_value_callback (GtkScale *scale, 395 * gdouble value) 396 * { 397 * return g_strdup_printf ("-->\%0.*g<--", 398 * gtk_scale_get_digits (scale), value); 399 * } 400 * ]| 401 * 402 * Params: 403 * value = the value to format 404 * 405 * Return: allocated string representing @value 406 */ 407 void addOnFormatValue(string delegate(double, Scale) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 408 { 409 if ( "format-value" !in connectedSignals ) 410 { 411 Signals.connectData( 412 this, 413 "format-value", 414 cast(GCallback)&callBackFormatValue, 415 cast(void*)this, 416 null, 417 connectFlags); 418 connectedSignals["format-value"] = 1; 419 } 420 onFormatValueListeners ~= dlg; 421 } 422 extern(C) static string callBackFormatValue(GtkScale* scaleStruct, double value, Scale _scale) 423 { 424 return _scale.onFormatValueListeners[0](value, _scale); 425 } 426 }