From 9ee5512d2d5540bbf3c691d62479860a5754e7af Mon Sep 17 00:00:00 2001 From: Gary Willoughby Date: Sun, 5 May 2019 20:58:54 +0100 Subject: [PATCH] Added setFont overload to tkd.widget.common.font. --- docs/tkd/widget/common/font.html | 21 ++++++++++++++---- source/example/example.d | 2 ++ source/tkd/widget/common/font.d | 38 +++++++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/docs/tkd/widget/common/font.html b/docs/tkd/widget/common/font.html index 949dce2..8e6b159 100644 --- a/docs/tkd/widget/common/font.html +++ b/docs/tkd/widget/common/font.html @@ -246,15 +246,28 @@

tkd.widget.common.font

Font module.

License

MIT. See LICENSE for full details.

template Font()

-

These are common commands that apply to all widgets that have them injected. -

Example

widget.setFont("PragmataPro", 10, FontStyle.bold, FontStyle.italic);
-
-

auto setFont(this T)(string font, int size, FontStyle[] styles...); +

These are common commands that apply to all widgets that have them injected.

auto setFont(this T)(string font, int size, FontStyle[] styles...);

Set the font and style for the widget.

Parameters

string fontThe name of the font like 'Arial' or 'arial'.
int sizeThe size of the font like '12'.
FontStyle[] stylesThe different font styles.

Return Value

This widget to aid method chaining. +

Example

widget.setFont("PragmataPro", 10, FontStyle.bold, FontStyle.italic);
+
+

See Also

tkd.element.fontstyle for font styles.

+

auto setFont(this T)(string fontInfo); +

+

Set the font and style for the widget via a simple string. + This method is exists to set the font using the output of the font dialog. +

Parameters

string fontInfoThe output of the file dialog.

Return Value

This widget to aid method chaining. + +

Example

auto dialog = new FontDialog("Choose a font")
+    .setCommand(delegate(CommandArgs args){
+        widget.setFont(args.dialog.font);
+    })
+    .show();
+
+

See Also

tkd.window.dialog.fontdialog for how to recieve output.

diff --git a/source/example/example.d b/source/example/example.d index ec740a0..8f634d1 100644 --- a/source/example/example.d +++ b/source/example/example.d @@ -37,6 +37,7 @@ class Application : TkdApplication { auto dialog = new FontDialog("Choose a font") .setCommand(delegate(CommandArgs args){ + this._fontEntry.setFont(args.dialog.font); this._fontEntry.setValue(args.dialog.font); }) .show(); @@ -53,6 +54,7 @@ class Application : TkdApplication auto dialog = new ColorDialog("Choose a color") .setInitialColor(Color.beige) .show(); + this._colorEntry.setForegroundColor(dialog.getResult()); this._colorEntry.setValue(dialog.getResult()); } diff --git a/source/tkd/widget/common/font.d b/source/tkd/widget/common/font.d index 011cf95..b7f0e44 100644 --- a/source/tkd/widget/common/font.d +++ b/source/tkd/widget/common/font.d @@ -8,11 +8,6 @@ module tkd.widget.common.font; /** * These are common commands that apply to all widgets that have them injected. -* - * Example: - * --- - * widget.setFont("PragmataPro", 10, FontStyle.bold, FontStyle.italic); - * --- */ mixin template Font() { @@ -31,6 +26,11 @@ mixin template Font() * Returns: * This widget to aid method chaining. * + * Example: + * --- + * widget.setFont("PragmataPro", 10, FontStyle.bold, FontStyle.italic); + * --- + * * See_Also: * $(LINK2 ../../element/fontstyle.html, tkd.element.fontstyle) for font styles. */ @@ -40,4 +40,32 @@ mixin template Font() return cast(T) this; } + + /** + * Set the font and style for the widget via a simple string. + * This method is exists to set the font using the output of the font dialog. + * + * Params: + * fontInfo = The output of the file dialog. + * + * Returns: + * This widget to aid method chaining. + * + * Example: + * --- + * auto dialog = new FontDialog("Choose a font") + * .setCommand(delegate(CommandArgs args){ + * widget.setFont(args.dialog.font); + * }) + * .show(); + * --- + * See_Also: + * $(LINK2 ../../window/dialog/fontdialog.html, tkd.window.dialog.fontdialog) for how to recieve output. + */ + public auto setFont(this T)(string fontInfo) + { + this._tk.eval("%s configure -font {%s}", this.id, fontInfo); + + return cast(T) this; + } }