1 /** 2 * Outline width module. 3 * 4 * License: 5 * MIT. See LICENSE for full details. 6 */ 7 module tkd.widget.common.canvas.outlinewidth; 8 9 /** 10 * These are common commands that apply to all widgets that have them injected. 11 */ 12 mixin template OutlineWidth() 13 { 14 import std.typecons : Nullable; 15 16 /** 17 * The width of the outline. 18 */ 19 private Nullable!(int) _outlineWidth; 20 21 /** 22 * The active width of the outline. 23 */ 24 private Nullable!(int) _activeOutlineWidth; 25 26 /** 27 * The disabled width of the outline. 28 */ 29 private Nullable!(int) _disabledOutlineWidth; 30 31 /** 32 * Get the width of the outline. 33 * 34 * Returns: 35 * The width of the outline; 36 */ 37 public int getOutlineWidth() 38 { 39 if (this._parent) 40 { 41 this._tk.eval("%s itemcget %s -width", this._parent.id, this.id); 42 this._outlineWidth = this._tk.getResult!(int); 43 } 44 45 return this._outlineWidth.isNull ? 0 : this._outlineWidth.get; 46 } 47 48 /** 49 * Set the width of the outline. 50 * 51 * Params: 52 * width = The width of the outline. 53 * 54 * Returns: 55 * This widget to aid method chaining. 56 */ 57 public auto setOutlineWidth(this T, W)(W width) if (is(W == int) || is(W == Nullable!(int))) 58 { 59 static if (is(W == Nullable!(int))) 60 { 61 if (width.isNull) 62 { 63 return cast(T) this; 64 } 65 } 66 67 this._outlineWidth = width; 68 69 if (this._parent) 70 { 71 this._tk.eval("%s itemconfigure %s -width %s", this._parent.id, this.id, this._outlineWidth); 72 } 73 74 return cast(T) this; 75 } 76 77 /** 78 * Get the width of the active outline. 79 * An item's active state is triggered when the mouse rolls over the item. 80 * 81 * Returns: 82 * The width of the active outline; 83 */ 84 public int getActiveOutlineWidth() 85 { 86 if (this._parent) 87 { 88 this._tk.eval("%s itemcget %s -activewidth", this._parent.id, this.id); 89 this._activeOutlineWidth = this._tk.getResult!(int); 90 } 91 92 return this._activeOutlineWidth.isNull ? 0 : this._activeOutlineWidth.get; 93 } 94 95 /** 96 * Set the width of the active outline. 97 * An item's active state is triggered when the mouse rolls over the item. 98 * 99 * Params: 100 * width = The width of the active outline. 101 * 102 * Returns: 103 * This widget to aid method chaining. 104 */ 105 public auto setActiveOutlineWidth(this T, W)(W width) if (is(W == int) || is(W == Nullable!(int))) 106 { 107 static if (is(W == Nullable!(int))) 108 { 109 if (width.isNull) 110 { 111 return cast(T) this; 112 } 113 } 114 115 this._activeOutlineWidth = width; 116 117 if (this._parent) 118 { 119 this._tk.eval("%s itemconfigure %s -activewidth %s", this._parent.id, this.id, this._activeOutlineWidth); 120 } 121 122 return cast(T) this; 123 } 124 125 /** 126 * Get the width of the disabled outline. 127 * 128 * Returns: 129 * The width of the disabled outline; 130 */ 131 public int getDisabledOutlineWidth() 132 { 133 if (this._parent) 134 { 135 this._tk.eval("%s itemcget %s -disabledwidth", this._parent.id, this.id); 136 this._disabledOutlineWidth = this._tk.getResult!(int); 137 } 138 139 return this._disabledOutlineWidth.isNull ? 0 : this._disabledOutlineWidth.get; 140 } 141 142 /** 143 * Set the width of the disabled outline. 144 * 145 * Params: 146 * width = The width of the disabled outline. 147 * 148 * Returns: 149 * This widget to aid method chaining. 150 * 151 * Bugs: 152 * This doesn't seem to have any effect in Tcl/Tk v8.6.1. It ignores 153 * this setting and applies a 1 pixel width. 154 */ 155 public auto setDisabledOutlineWidth(this T, W)(W width) if (is(W == int) || is(W == Nullable!(int))) 156 { 157 static if (is(W == Nullable!(int))) 158 { 159 if (width.isNull) 160 { 161 return cast(T) this; 162 } 163 } 164 165 this._disabledOutlineWidth = width; 166 167 if (this._parent) 168 { 169 this._tk.eval("%s itemconfigure %s -disabledwidth %s", this._parent.id, this.id, this._disabledOutlineWidth); 170 } 171 172 return cast(T) this; 173 } 174 }