1 /** 2 * Line specific module. 3 * 4 * License: 5 * MIT. See LICENSE for full details. 6 */ 7 module tkd.widget.common.canvas.linespecific; 8 9 /** 10 * These are common commands that apply to all widgets that have them injected. 11 */ 12 mixin template LineSpecific() 13 { 14 /** 15 * The arrow position on the line. 16 */ 17 private string _arrowPosition; 18 19 /** 20 * The shape of any arrows used. 21 */ 22 private uint[3] _arrowShape; 23 24 /** 25 * The style of the end caps. 26 */ 27 private string _capStyle; 28 29 /** 30 * Get the arrow position. 31 * 32 * Returns: 33 * The arrow position. 34 */ 35 public string getArrowPosition() 36 { 37 if (this._parent) 38 { 39 this._tk.eval("%s itemcget %s -arrow", this._parent.id, this.id); 40 this._arrowPosition = this._tk.getResult!(string); 41 } 42 43 return this._arrowPosition; 44 } 45 46 /** 47 * Indicates whether or not arrowheads are to be drawn at one or both ends 48 * of the line. 49 * 50 * Params: 51 * arrowPosition = The position of arrows on the line. 52 * 53 * Returns: 54 * This item to aid method chaining. 55 * 56 * See_Also: 57 * $(LINK2 ../../canvas.html#CanvasLineArrow, tkd.widget.canvas.CanvasLineArrow) 58 */ 59 public auto setArrowPosition(this T)(string arrowPosition) 60 { 61 this._arrowPosition = arrowPosition; 62 63 if (this._parent && this._arrowPosition.length) 64 { 65 this._tk.eval("%s itemconfigure %s -arrow {%s}", this._parent.id, this.id, this._arrowPosition); 66 } 67 68 return cast(T) this; 69 } 70 71 /** 72 * Get the arrow shape. 73 * 74 * Returns: 75 * The arrow shape. 76 */ 77 public uint[3] getArrowShape() 78 { 79 if (this._parent) 80 { 81 this._tk.eval("%s itemcget %s -arrowshape", this._parent.id, this.id); 82 this._arrowShape = this._tk.getResult!(string).map!(to!(uint)).array; 83 } 84 85 return this._arrowShape; 86 } 87 88 /** 89 * This option indicates how to draw arrowheads. The shape argument must be 90 * a list with three elements, each specifying a distance. The first 91 * element of the list gives the distance along the line from the neck of 92 * the arrowhead to its tip. The second element gives the distance along 93 * the line from the trailing points of the arrowhead to the tip, and the 94 * third element gives the distance from the outside edge of the line to 95 * the trailing points. 96 * 97 * Params: 98 * arrowshape = The arrow shape. 99 * 100 * Returns: 101 * This item to aid method chaining. 102 */ 103 public auto setArrowShape(this T)(uint[3] arrowshape) 104 { 105 this._arrowShape = arrowshape; 106 107 if (this._parent && this._arrowShape[].all!("a > 0")) 108 { 109 this._tk.eval("%s itemconfigure %s -arrowshape [list %s]", this._parent.id, this.id, this._arrowShape[].map!(to!(string)).join(" ")); 110 } 111 112 return cast(T) this; 113 } 114 115 /** 116 * Get the cap style. 117 * 118 * Returns: 119 * The cap style. 120 */ 121 public string getCapStyle() 122 { 123 if (this._parent) 124 { 125 this._tk.eval("%s itemcget %s -capstyle", this._parent.id, this.id); 126 this._capStyle = this._tk.getResult!(string); 127 } 128 129 return this._capStyle; 130 } 131 132 /** 133 * Specifies the ways in which caps are to be drawn at the endpoints of the 134 * line. When arrowheads are drawn the cap style is ignored. 135 * 136 * Params: 137 * capStyle = The cap style. 138 * 139 * Returns: 140 * This item to aid method chaining. 141 * 142 * See_Also: 143 * $(LINK2 ../../canvas.html#CanvasLineCapStyle, tkd.widget.canvas.CanvasLineCapStyle) 144 */ 145 public auto setCapStyle(this T)(string capStyle) 146 { 147 this._capStyle = capStyle; 148 149 if (this._parent && this._capStyle.length) 150 { 151 this._tk.eval("%s itemconfigure %s -capstyle {%s}", this._parent.id, this.id, this._capStyle); 152 } 153 154 return cast(T) this; 155 } 156 }