1 /**
2 * Font module.
3 *
4 * License:
5 *     MIT. See LICENSE for full details.
6 */
7 module tkd.widget.common.font;
8 
9 /**
10 * These are common commands that apply to all widgets that have them injected.
11 */
12 mixin template Font()
13 {
14 	import std.array : join;
15 	import std.conv : to;
16 	import tkd.element.fontstyle;
17 
18 	/**
19 	 * Set the font and style for the widget.
20 	 *
21 	 * Params:
22 	 *     font   = The name of the font like 'Arial' or 'arial'.
23 	 *     size   = The size of the font like '12'.
24 	 *     styles = The different font styles.
25 	 *
26 	 * Returns:
27 	 *     This widget to aid method chaining.
28 	 *
29 	 * Example:
30 	 * ---
31 	 * widget.setFont("PragmataPro", 10, FontStyle.bold, FontStyle.italic);
32 	 * ---
33 	 *
34 	 * See_Also:
35 	 *     $(LINK2 ../../element/fontstyle.html, tkd.element.fontstyle) for font styles.
36 	 */
37 	public auto setFont(this T)(string font, int size, FontStyle[] styles...)
38 	{
39 		this._tk.eval("%s configure -font {{%s} %s %s}", this.id, font, size, styles.to!(string[]).join(" "));
40 
41 		return cast(T) this;
42 	}
43 
44 	/**
45 	 * Set the font and style for the widget via a simple string.
46 	 * This method is exists to set the font using the output of the font dialog.
47 	 *
48 	 * Params:
49 	 *     fontInfo = The output of the file dialog.
50 	 *
51 	 * Returns:
52 	 *     This widget to aid method chaining.
53 	 *
54 	 * Example:
55 	 * ---
56 	 * auto dialog = new FontDialog("Choose a font")
57 	 *     .setCommand(delegate(CommandArgs args){
58 	 *         widget.setFont(args.dialog.font);
59 	 *     })
60 	 *     .show();
61 	 * ---
62 	 * See_Also:
63 	 *     $(LINK2 ../../window/dialog/fontdialog.html, tkd.window.dialog.fontdialog) for how to recieve output.
64 	 */
65 	public auto setFont(this T)(string fontInfo)
66 	{
67 		this._tk.eval("%s configure -font {%s}", this.id, fontInfo);
68 
69 		return cast(T) this;
70 	}
71 }