1 /** 2 * Value module. 3 * 4 * License: 5 * MIT. See LICENSE for full details. 6 */ 7 module tkd.widget.common.value; 8 9 /** 10 * These are common commands that apply to all widgets that have them injected. 11 * 12 * Params: 13 * valueVariable = The name of the variable that holds the widget's value. 14 * V = The type of the variable to set. 15 */ 16 mixin template Value(alias valueVariable, V) 17 { 18 import std.conv; 19 20 /** 21 * Get the value of the widget. 22 * 23 * Params: 24 * T = The type of the value to return. 25 * 26 * Returns: 27 * The value of the widget. 28 */ 29 public T getValue(T = V)() 30 { 31 return this._tk.getVariable(valueVariable).to!(T); 32 } 33 34 /** 35 * Set the string value of the widget. 36 * 37 * Params: 38 * value = The new widget value. 39 * 40 * Returns: 41 * This widget to aid method chaining. 42 */ 43 public auto setValue(this T)(V value) 44 { 45 this._tk.setVariable(valueVariable, value); 46 47 return cast(T) this; 48 } 49 50 /** 51 * Destroy this widget. 52 * 53 * Caveats: 54 * Once a widget is destroyed it can no longer be referenced in your 55 * code or a segmentation fault will occur and potentially crash your 56 * program. 57 */ 58 override public void destroy() 59 { 60 this._tk.deleteVariable(valueVariable); 61 super.destroy(); 62 } 63 }