1 /**
2  * Widget module.
3  *
4  * License:
5  *     MIT. See LICENSE for full details.
6  */
7 module tkd.widget.scale;
8 
9 /**
10  * Imports.
11  */
12 import std..string;
13 import tkd.element.uielement;
14 import tkd.widget.common.command;
15 import tkd.widget.common.length;
16 import tkd.widget.common.range;
17 import tkd.widget.common.value;
18 import tkd.widget.orientation;
19 import tkd.widget.widget;
20 
21 /**
22  * A scale widget is typically used to control the numeric value that varies 
23  * uniformly over some range. A scale displays a slider that can be moved along 
24  * over a trough, with the relative position of the slider over the trough 
25  * indicating the value.
26  *
27  * Example:
28  * ---
29  * auto scale = new Scale()
30  * 	.setCommand(delegate(CommandArgs arg){ ... })
31  * 	.setFromValue(0.0)
32  * 	.setToValue(100.0)
33  * 	.pack();
34  * ---
35  *
36  * Common_Commands:
37  *     These are injected common commands that can also be used with this widget.
38  *     $(P
39  *         $(LINK2 ./common/command.html, Command) $(BR)
40  *         $(LINK2 ./common/length.html, Length) $(BR)
41  *         $(LINK2 ./common/range.html, Range) $(BR)
42  *         $(LINK2 ./common/value.html, Value) $(BR)
43  *     )
44  *
45  * Additional_Events:
46  *     Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method.
47  *     $(P
48  *         <<PrevWindow>>,
49  *         <Alt-Key>,
50  *         <B1-Motion>,
51  *         <B2-Motion>,
52  *         <B3-Motion>,
53  *         <Button-1>,
54  *         <Button-2>,
55  *         <Button-3>,
56  *         <ButtonRelease-1>,
57  *         <ButtonRelease-2>,
58  *         <ButtonRelease-3>,
59  *         <Control-Key-Down>,
60  *         <Control-Key-Left>,
61  *         <Control-Key-Right>,
62  *         <Control-Key-Up>,
63  *         <Key-Down>,
64  *         <Key-End>,
65  *         <Key-F10>,
66  *         <Key-Home>,
67  *         <Key-Left>,
68  *         <Key-Right>,
69  *         <Key-Tab>,
70  *         <Key-Up>,
71  *     )
72  *
73  * See_Also:
74  *     $(LINK2 ./widget.html, tkd.widget.widget)
75  */
76 class Scale : Widget
77 {
78 	/**
79 	 * The name of the variable that contains the widget's value.
80 	 */
81 	private string _valueVariable;
82 
83 	/**
84 	 * Construct the widget.
85 	 *
86 	 * Params:
87 	 *     parent = The parent of this widget.
88 	 *     orientation = The orientation of the widget.
89 	 *
90 	 * See_Also:
91 	 *     $(LINK2 ../element/uielement.html, tkd.element.UiElement) $(BR)
92 	 *     $(LINK2 ./orientation.html, tkd.widget.orientation) for orientations.
93 	 */
94 	public this(UiElement parent, string orientation = Orientation.horizontal)
95 	{
96 		super(parent);
97 		this._elementId     = "scale";
98 		this._valueVariable = format("variable-%s", this.generateHash(this.id));
99 
100 		this._tk.eval("ttk::scale %s -orient %s -variable %s", this.id, orientation, this._valueVariable);
101 	}
102 
103 	/**
104 	 * Construct the widget.
105 	 *
106 	 * Params:
107 	 *     orientation = The orientation of the widget.
108 	 *
109 	 * See_Also:
110 	 *     $(LINK2 ./orientation.html, tkd.widget.orientation) for orientations.
111 	 */
112 	public this(string orientation = Orientation.horizontal)
113 	{
114 		this(null, orientation);
115 	}
116 
117 	/**
118 	 * Mixin common commands.
119 	 */
120 	mixin Command;
121 	mixin Length;
122 	mixin Range;
123 	mixin Value!(this._valueVariable, double);
124 }