├── .gitignore ├── source ├── example │ ├── example.gif │ ├── media │ │ ├── disk.png │ │ ├── film.png │ │ ├── help.png │ │ ├── page.png │ │ ├── cancel.png │ │ ├── comment.png │ │ ├── error.png │ │ ├── folder.png │ │ ├── images.png │ │ ├── style.png │ │ ├── tkicon.png │ │ ├── computer.png │ │ ├── thumbnail.gif │ │ ├── thumbnail.png │ │ ├── color_swatch.png │ │ ├── folder_page.png │ │ ├── layout_content.png │ │ ├── shape_ungroup.png │ │ ├── application_double.png │ │ ├── chart_organisation.png │ │ ├── page_white_acrobat.png │ │ └── application_tile_horizontal.png │ └── screenshots.psd └── tkd │ ├── interpreter │ ├── package.d │ ├── tk.d │ └── logger.d │ ├── widget │ ├── menu │ │ ├── package.d │ │ └── menubar.d │ ├── orientation.d │ ├── alignment.d │ ├── keyboardfocus.d │ ├── textwrapmode.d │ ├── reliefstyle.d │ ├── common │ │ ├── invoke.d │ │ ├── length.d │ │ ├── default_.d │ │ ├── border.d │ │ ├── relief.d │ │ ├── width.d │ │ ├── padding.d │ │ ├── exportselection.d │ │ ├── height.d │ │ ├── underline.d │ │ ├── cursor.d │ │ ├── show.d │ │ ├── justify.d │ │ ├── delete_.d │ │ ├── orient.d │ │ ├── boundingbox.d │ │ ├── range.d │ │ ├── wraplength.d │ │ ├── anchor.d │ │ ├── yscrollcommand.d │ │ ├── xscrollcommand.d │ │ ├── text.d │ │ ├── selection.d │ │ ├── index.d │ │ ├── canvas │ │ │ ├── anchor.d │ │ │ ├── state.d │ │ │ ├── imagespecific.d │ │ │ ├── widgetspecific.d │ │ │ ├── bind.d │ │ │ ├── fillcolor.d │ │ │ ├── outlinecolor.d │ │ │ ├── linespecific.d │ │ │ ├── outlinewidth.d │ │ │ ├── arcspecific.d │ │ │ ├── vertex.d │ │ │ └── outlinedash.d │ │ ├── data.d │ │ ├── value.d │ │ ├── command.d │ │ ├── color.d │ │ ├── postcommand.d │ │ ├── font.d │ │ ├── insert.d │ │ ├── yview.d │ │ └── xview.d │ ├── anchorposition.d │ ├── state.d │ ├── package.d │ ├── sizegrip.d │ ├── style.d │ ├── separator.d │ ├── label.d │ ├── frame.d │ ├── menubutton.d │ ├── labelframe.d │ ├── scale.d │ ├── textwidget.d │ ├── button.d │ ├── radiobutton.d │ ├── checkbutton.d │ ├── entry.d │ └── progressbar.d │ ├── window │ ├── package.d │ ├── dialog │ │ ├── package.d │ │ ├── dialog.d │ │ ├── colordialog.d │ │ ├── directorydialog.d │ │ ├── savefiledialog.d │ │ ├── openfiledialog.d │ │ ├── filedialog.d │ │ └── fontdialog.d │ └── theme.d │ ├── image │ ├── imageformat.d │ ├── package.d │ ├── imageposition.d │ ├── png.d │ └── gif.d │ └── element │ ├── package.d │ ├── fontstyle.d │ ├── elementclass.d │ └── cursor.d ├── gen-docs.sh ├── package.json ├── LICENSE └── docs └── tkd ├── theme.html └── element ├── cursor.html └── fontstyle.html /.gitignore: -------------------------------------------------------------------------------- 1 | .dub/* 2 | build/* 3 | debug.log 4 | __main.html 5 | package.html 6 | dub.selections.json 7 | -------------------------------------------------------------------------------- /source/example/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/example.gif -------------------------------------------------------------------------------- /source/example/media/disk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/disk.png -------------------------------------------------------------------------------- /source/example/media/film.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/film.png -------------------------------------------------------------------------------- /source/example/media/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/help.png -------------------------------------------------------------------------------- /source/example/media/page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/page.png -------------------------------------------------------------------------------- /source/example/media/cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/cancel.png -------------------------------------------------------------------------------- /source/example/media/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/comment.png -------------------------------------------------------------------------------- /source/example/media/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/error.png -------------------------------------------------------------------------------- /source/example/media/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/folder.png -------------------------------------------------------------------------------- /source/example/media/images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/images.png -------------------------------------------------------------------------------- /source/example/media/style.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/style.png -------------------------------------------------------------------------------- /source/example/media/tkicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/tkicon.png -------------------------------------------------------------------------------- /source/example/screenshots.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/screenshots.psd -------------------------------------------------------------------------------- /source/example/media/computer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/computer.png -------------------------------------------------------------------------------- /source/example/media/thumbnail.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/thumbnail.gif -------------------------------------------------------------------------------- /source/example/media/thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/thumbnail.png -------------------------------------------------------------------------------- /source/example/media/color_swatch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/color_swatch.png -------------------------------------------------------------------------------- /source/example/media/folder_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/folder_page.png -------------------------------------------------------------------------------- /source/example/media/layout_content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/layout_content.png -------------------------------------------------------------------------------- /source/example/media/shape_ungroup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/shape_ungroup.png -------------------------------------------------------------------------------- /source/example/media/application_double.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/application_double.png -------------------------------------------------------------------------------- /source/example/media/chart_organisation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/chart_organisation.png -------------------------------------------------------------------------------- /source/example/media/page_white_acrobat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/page_white_acrobat.png -------------------------------------------------------------------------------- /source/example/media/application_tile_horizontal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomad-software/tkd/HEAD/source/example/media/application_tile_horizontal.png -------------------------------------------------------------------------------- /gen-docs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | cd source; 4 | 5 | rdmd --force -Dd../docs -de -op -w -main -I. -I/media/Data/Projects/D/x11/source -I/media/Data/Projects/D/tcltk/source -L-ltcl -L-ltk tkd/tkdapplication.d; 6 | -------------------------------------------------------------------------------- /source/tkd/interpreter/package.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Interpreter module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.interpreter; 8 | 9 | public import tkd.interpreter.tcl; 10 | public import tkd.interpreter.tk; 11 | -------------------------------------------------------------------------------- /source/tkd/widget/menu/package.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Menu module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.menu; 8 | 9 | public import tkd.widget.menu.menu; 10 | public import tkd.widget.menu.menubar; 11 | -------------------------------------------------------------------------------- /source/tkd/window/package.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Window module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.window; 8 | 9 | public import tkd.window.dialog; 10 | public import tkd.window.theme; 11 | public import tkd.window.window; 12 | -------------------------------------------------------------------------------- /source/tkd/image/imageformat.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Image module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.image.imageformat; 8 | 9 | /** 10 | * The supported formats. 11 | */ 12 | enum ImageFormat : string 13 | { 14 | gif = "gif", /// Gif format. 15 | png = "png", /// Png format. 16 | } 17 | -------------------------------------------------------------------------------- /source/tkd/image/package.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Image module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.image; 8 | 9 | public import tkd.image.gif; 10 | public import tkd.image.image; 11 | public import tkd.image.imageformat; 12 | public import tkd.image.imageposition; 13 | public import tkd.image.png; 14 | -------------------------------------------------------------------------------- /source/tkd/element/package.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Element module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.element; 8 | 9 | public import tkd.element.color; 10 | public import tkd.element.cursor; 11 | public import tkd.element.elementclass; 12 | public import tkd.element.fontstyle; 13 | public import tkd.element.uielement; 14 | -------------------------------------------------------------------------------- /source/tkd/element/fontstyle.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Element module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.element.fontstyle; 8 | 9 | /** 10 | * Font style options. 11 | */ 12 | enum FontStyle : string 13 | { 14 | normal = "normal", 15 | bold = "bold", 16 | roman = "roman", 17 | italic = "italic", 18 | underline = "underline", 19 | overstrike = "overstrike", 20 | } 21 | -------------------------------------------------------------------------------- /source/tkd/widget/orientation.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.orientation; 8 | 9 | /** 10 | * Orientation of particular widgets. 11 | */ 12 | enum Orientation : string 13 | { 14 | horizontal = "horizontal", /// Set the widget orientation to horizontal. 15 | vertical = "vertical", /// Set the widget orientation to vertical. 16 | } 17 | -------------------------------------------------------------------------------- /source/tkd/widget/alignment.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.alignment; 8 | 9 | /** 10 | * Alignment values of widgets. 11 | */ 12 | enum Alignment : string 13 | { 14 | left = "left", /// Set text alignment to the left. 15 | right = "right", /// Set text alignment to the right. 16 | center = "center", /// Set text alignment to centered. 17 | } 18 | -------------------------------------------------------------------------------- /source/tkd/widget/keyboardfocus.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.keyboardfocus; 8 | 9 | /** 10 | * Keyboard values values of widgets. 11 | */ 12 | enum KeyboardFocus : string 13 | { 14 | normal = "ttk::takefocus", /// Default focus setting. 15 | enable = "1", /// Enable widget focus. 16 | disable = "0", /// Disable widget focus. 17 | } 18 | -------------------------------------------------------------------------------- /source/tkd/widget/textwrapmode.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.textwrapmode; 8 | 9 | /** 10 | * The wrap mode of the text widget. 11 | */ 12 | enum TextWrapMode : string 13 | { 14 | none = "none", /// No wrapping takes place. 15 | character = "char", /// The text is wrapped with the breaks mid word. 16 | word = "word", /// The text is wrapped broken on words. 17 | } 18 | -------------------------------------------------------------------------------- /source/tkd/window/dialog/package.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Dialog module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.window.dialog; 8 | 9 | public import tkd.window.dialog.colordialog; 10 | public import tkd.window.dialog.directorydialog; 11 | public import tkd.window.dialog.fontdialog; 12 | public import tkd.window.dialog.messagedialog; 13 | public import tkd.window.dialog.openfiledialog; 14 | public import tkd.window.dialog.savefiledialog; 15 | -------------------------------------------------------------------------------- /source/tkd/widget/reliefstyle.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.reliefstyle; 8 | 9 | /** 10 | * Standard style values of widgets. 11 | */ 12 | enum ReliefStyle : string 13 | { 14 | flat = "flat", /// Flat relief style. 15 | groove = "groove", /// Groove relief style. 16 | raised = "raised", /// Raised relief style. 17 | ridge = "ridge", /// Ridge relief style. 18 | solid = "solid", /// Solid relief style. 19 | sunken = "sunken", /// Sunken relief style. 20 | } 21 | -------------------------------------------------------------------------------- /source/tkd/widget/common/invoke.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Invoke module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.invoke; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Invoke() 13 | { 14 | /** 15 | * Invoke the command associated with the widget. 16 | * 17 | * Returns: 18 | * This widget to aid method chaining. 19 | */ 20 | public auto invokeCommand(this T)() 21 | { 22 | this._tk.eval("%s invoke", this.id); 23 | 24 | return cast(T) this; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /source/tkd/widget/common/length.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Length module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.length; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Length() 13 | { 14 | /** 15 | * Set the length of the widget. 16 | * 17 | * Params: 18 | * length = The length of the widget in pixels. 19 | */ 20 | public auto setLength(this T)(int length) 21 | { 22 | this._tk.eval("%s configure -length %s", this.id, length); 23 | 24 | return cast(T) this; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /source/tkd/widget/common/default_.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Default module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.default_; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Default_() 13 | { 14 | /** 15 | * Make the widget the default one on the interface. 16 | * 17 | * Returns: 18 | * This widget to aid method chaining. 19 | */ 20 | public auto setDefault(this T)() 21 | { 22 | this._tk.eval("%s configure -default active", this.id); 23 | 24 | return cast(T) this; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /source/tkd/widget/common/border.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Border module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.border; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Border() 13 | { 14 | /** 15 | * Set the border width of the widget. 16 | * 17 | * Params: 18 | * width = The desired border width. 19 | * 20 | * Returns: 21 | * This widget to aid method chaining. 22 | */ 23 | public auto setBorderWidth(this T)(int width) 24 | { 25 | this._tk.eval("%s configure -borderwidth %s", this.id, width); 26 | 27 | return cast(T) this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /source/tkd/widget/common/relief.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Relief module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.relief; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Relief() 13 | { 14 | /** 15 | * Set the relief type of the widget. 16 | * 17 | * Params: 18 | * relief = The relief type of the widget. 19 | * 20 | * Returns: 21 | * This widget to aid method chaining. 22 | */ 23 | public auto setRelief(this T)(string relief) 24 | { 25 | this._tk.eval("%s configure -relief %s", this.id, relief); 26 | 27 | return cast(T) this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /source/tkd/widget/common/width.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Width module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.width; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Width() 13 | { 14 | /** 15 | * Set the width of the widget if the geometry manager allows. 16 | * 17 | * Params: 18 | * width = The desired widget width. 19 | * 20 | * Returns: 21 | * This widget to aid method chaining. 22 | */ 23 | public auto setWidth(this T)(int width) 24 | { 25 | this._tk.eval("%s configure -width %s", this.id, width); 26 | 27 | return cast(T) this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /source/tkd/widget/common/padding.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Padding module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.padding; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Padding() 13 | { 14 | /** 15 | * Set the amount of padding within the widget. 16 | * 17 | * Params: 18 | * padding = The desired widget padding. 19 | * 20 | * Returns: 21 | * This widget to aid method chaining. 22 | */ 23 | public auto setPadding(this T)(int padding) 24 | { 25 | this._tk.eval("%s configure -padding %s", this.id, padding); 26 | 27 | return cast(T) this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /source/tkd/widget/common/exportselection.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Export selection module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.exportselection; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template ExportSelection() 13 | { 14 | /** 15 | * Disable the selection export. This is only applicable to X based 16 | * operating systems. 17 | * 18 | * Returns: 19 | * This widget to aid method chaining. 20 | */ 21 | public auto disableExportSelection(this T)() 22 | { 23 | this._tk.eval("%s configure -exportselection 0", this.id); 24 | 25 | return cast(T) this; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /source/tkd/widget/common/height.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Height module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.height; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Height() 13 | { 14 | /** 15 | * Set the height of the widget if the geometry manager allows. 16 | * 17 | * Params: 18 | * height = The desired widget height. 19 | * 20 | * Returns: 21 | * This widget to aid method chaining. 22 | */ 23 | public auto setHeight(this T)(int height) 24 | { 25 | this._tk.eval("%s configure -height %s", this.id, height); 26 | 27 | return cast(T) this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /source/tkd/widget/common/underline.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Underline module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.underline; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Underline() 13 | { 14 | /** 15 | * Underline one of the characters in the widget text. 16 | * 17 | * Params: 18 | * index = The index of the character to underline. 19 | * 20 | * Returns: 21 | * This widget to aid method chaining. 22 | */ 23 | public auto underlineChar(this T)(int index) 24 | { 25 | this._tk.eval("%s configure -underline %s", this.id, index); 26 | 27 | return cast(T) this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /source/tkd/widget/common/cursor.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Cursor module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.cursor; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Cursor() 13 | { 14 | /** 15 | * Set the text cursor just after the character index passed. 16 | * 17 | * Params: 18 | * charIndex = The index of the character after the cursor. 19 | * 20 | * Returns: 21 | * This widget to aid method chaining. 22 | */ 23 | public auto setCursorPosition(this T)(int charIndex) 24 | { 25 | this._tk.eval("%s icursor %s", this.id, charIndex); 26 | 27 | return cast(T) this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /source/tkd/widget/anchorposition.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.anchorposition; 8 | 9 | /** 10 | * Anchor positions of widgets. 11 | */ 12 | enum AnchorPosition : string 13 | { 14 | north = "n", /// Anchor to the North. 15 | northEast = "ne", /// Anchor to the North East. 16 | east = "e", /// Anchor to the East. 17 | southEast = "se", /// Anchor to the South East. 18 | south = "s", /// Anchor to the South. 19 | southWest = "sw", /// Anchor to the South West. 20 | west = "w", /// Anchor to the West. 21 | northWest = "nw", /// Anchor to the North West. 22 | center = "center", /// Anchor centered. 23 | } 24 | -------------------------------------------------------------------------------- /source/tkd/widget/common/show.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Show module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.show; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Show() 13 | { 14 | /** 15 | * Substitute all characters in the text for the passed character. 16 | * This is useful for password entries. 17 | * 18 | * Params: 19 | * character = The character to use as a substitute. 20 | * 21 | * Returns: 22 | * This widget to aid method chaining. 23 | */ 24 | public auto showCharsAs(this T)(char character) 25 | { 26 | this._tk.eval("%s configure -show %s", this.id, character); 27 | 28 | return cast(T) this; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /source/tkd/widget/common/justify.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Justify module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.justify; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Justify() 13 | { 14 | /** 15 | * Set the alignment of the widget text. 16 | * 17 | * Params: 18 | * alignment = The alignment of the text. 19 | * 20 | * Returns: 21 | * This widget to aid method chaining. 22 | * 23 | * See_Also: 24 | * $(LINK2 ../alignment.html, tkd.widget.alignment) 25 | */ 26 | public auto setTextAlignment(this T)(string alignment) 27 | { 28 | this._tk.eval("%s configure -justify %s", this.id, alignment); 29 | 30 | return cast(T) this; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /source/tkd/image/imageposition.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Image module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.image.imageposition; 8 | 9 | /** 10 | * Position of image relative to the text. 11 | */ 12 | enum ImagePosition : string 13 | { 14 | text = "text", /// Only show text. 15 | image = "image", /// Only show image. This is not available for menus, use 'none' instead. 16 | center = "center", /// Center the text on the image. 17 | top = "top", /// Position the image above the text. 18 | bottom = "bottom", /// Position the image below the text. 19 | left = "left", /// Position the image to the left of the text. 20 | right = "right", /// Position the image to the right of the text. 21 | none = "none", /// Only show image and no text. 22 | } 23 | -------------------------------------------------------------------------------- /source/tkd/widget/common/delete_.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Delete module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.delete_; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Delete_() 13 | { 14 | /** 15 | * Delete the text. 16 | * 17 | * Params: 18 | * startCharIndex = The index where the deletion starts. 19 | * endCharIndex = The index where the deletion ends. 20 | * 21 | * Returns: 22 | * This widget to aid method chaining. 23 | */ 24 | public auto deleteText(this T)(int startCharIndex = 0, int endCharIndex = int.max) 25 | { 26 | this._tk.eval("%s delete %s %s", this.id, startCharIndex, endCharIndex); 27 | 28 | return cast(T) this; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /source/tkd/widget/common/orient.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Orient module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.orient; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Orient() 13 | { 14 | /** 15 | * Set the orientation of the widget. 16 | * 17 | * Params: 18 | * orientation = The orientation of the widget. 19 | * 20 | * Returns: 21 | * This widget to aid method chaining. 22 | * 23 | * See_Also: 24 | * $(LINK2 ../orientation.html, tkd.widget.orientation) for orientations. 25 | */ 26 | public auto setOrientation(this T)(string orientation) 27 | { 28 | this._tk.eval("%s configure -orient %s", this.id, orientation); 29 | 30 | return cast(T) this; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tkd", 3 | "description": "GUI toolkit for the D programming language based on Tcl/Tk", 4 | "homepage": "https://github.com/nomad-software/tkd", 5 | "authors": ["Gary Willoughby"], 6 | "copyright": "Copyright (c) 2014 Gary Willoughby", 7 | "license": "MIT", 8 | "dependencies": { 9 | "tcltk": ">=8.6.5" 10 | }, 11 | "configurations": [ 12 | { 13 | "name": "library", 14 | "targetType": "library", 15 | "targetPath": "build", 16 | "excludedSourceFiles": ["source/example/*"] 17 | }, 18 | { 19 | "name": "example", 20 | "targetType": "executable", 21 | "mainSourceFile": "source/example/example.d", 22 | "lflags-windows": ["/subsystem:windows"], 23 | "stringImportPaths": ["source/example/media"], 24 | "targetName": "example", 25 | "targetPath": "build/example" 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /source/tkd/widget/common/boundingbox.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Bounding Box module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.boundingbox; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template BoundingBox() 13 | { 14 | import std.algorithm; 15 | import std.array; 16 | import std.conv; 17 | 18 | /** 19 | * Get the bounding box of a character in the text. 20 | * 21 | * Params: 22 | * charIndex = The index of the character to get the bounding box of. 23 | * 24 | * Returns: 25 | * An int array representing the bounding box in pixels. 26 | */ 27 | public int[] getCharBoundingBox(int charIndex) 28 | { 29 | this._tk.eval("%s bbox %s", this.id, charIndex); 30 | return this._tk.getResult!(string).split().map!(to!(int)).array; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /source/tkd/window/theme.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Window module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.window.theme; 8 | 9 | /** 10 | * Standard themes. 11 | */ 12 | enum Theme : string 13 | { 14 | alt = "alt", /// The alternate theme. 15 | classic = "classic", /// The classic theme. 16 | default_ = "default", /// The default theme. 17 | clam = "clam", /// The Clam theme. 18 | } 19 | 20 | /** 21 | * Mac OSX only themes. 22 | */ 23 | version (OSX) 24 | { 25 | enum MacOSXTheme : string 26 | { 27 | aqua = "aqua", /// Native theme of Mac OSX. 28 | } 29 | } 30 | 31 | /** 32 | * Windows only themes. 33 | */ 34 | version (Windows) 35 | { 36 | enum WindowsTheme : string 37 | { 38 | winnative = "winnative", /// The native theme of Windows. 39 | xpnative = "xpnative", /// The native theme of Window XP. 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /source/tkd/widget/state.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.state; 8 | 9 | /** 10 | * State values of widgets. 11 | */ 12 | enum State : string 13 | { 14 | normal = "normal", /// Normal state. 15 | active = "active", /// Active state. 16 | disabled = "disabled", /// Disabled state. 17 | focus = "focus", /// Focused state. 18 | pressed = "pressed", /// Pressed state. 19 | selected = "selected", /// Selected state. 20 | background = "background", /// Background state. 21 | readonly = "readonly", /// Readonly state. 22 | alternate = "alternate", /// Alternate state. 23 | invalid = "invalid", /// Invalid state. 24 | hover = "hover", /// Hover state. 25 | hidden = "hidden", /// Hidden state. Only applies to canvas widgets. 26 | } 27 | -------------------------------------------------------------------------------- /source/tkd/widget/common/range.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Range module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.range; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Range() 13 | { 14 | /** 15 | * Set the 'from' value of the range. 16 | * 17 | * Params: 18 | * value = The 'from' value of the range. 19 | */ 20 | public auto setFromValue(this T)(double value) 21 | { 22 | this._tk.eval("%s configure -from %s", this.id, value); 23 | 24 | return cast(T) this; 25 | } 26 | 27 | /** 28 | * Set the 'to' value of the range. 29 | * 30 | * Params: 31 | * value = The 'to' value of the range. 32 | */ 33 | public auto setToValue(this T)(double value) 34 | { 35 | this._tk.eval("%s configure -to %s", this.id, value); 36 | 37 | return cast(T) this; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /source/tkd/widget/common/wraplength.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Wrap Length module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.wraplength; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template WrapLength() 13 | { 14 | /** 15 | * Specifies the maximum line length (in pixels). If this option is less 16 | * than or equal to zero, then automatic wrapping is not performed; 17 | * otherwise the text is split into lines such that no line is longer than 18 | * the specified value. 19 | * 20 | * Params: 21 | * pixels = The maximum width in pixels. 22 | * 23 | * Returns: 24 | * This widget to aid method chaining. 25 | */ 26 | public auto setWrapLength(this T)(int pixels) 27 | { 28 | this._tk.eval("%s configure -wraplength %s", this.id, pixels); 29 | 30 | return cast(T) this; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /source/tkd/widget/common/anchor.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Anchor module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.anchor; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | * 12 | * Params: 13 | * anchorCommand = The widget command that handles the anchor. 14 | */ 15 | mixin template Anchor(string anchorCommand = "-anchor") 16 | { 17 | /** 18 | * Specifies how text in the widget is positioned relative to the inner margins. 19 | * 20 | * Params: 21 | * position = The position of the anchor. 22 | * 23 | * Returns: 24 | * This widget to aid method chaining. 25 | * 26 | * See_Also: 27 | * $(LINK2 ../anchorposition.html, tkd.widget.anchorposition) $(BR) 28 | */ 29 | public auto setTextAnchor(this T)(string position) 30 | { 31 | this._tk.eval("%s configure " ~ anchorCommand ~ " %s", this.id, position); 32 | 33 | return cast(T) this; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /source/tkd/widget/common/yscrollcommand.d: -------------------------------------------------------------------------------- 1 | /** 2 | * YScroll Command module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.yscrollcommand; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import tkd.widget.scrollbar; 13 | 14 | /** 15 | * If implemented this widget has a text display that is scrollable vertically. 16 | */ 17 | interface IYScrollable(T) 18 | { 19 | /** 20 | * Attach a vertical scrollbar. 21 | * 22 | * Params: 23 | * scrollbar = The scrollbar to attach. 24 | */ 25 | public T attachYScrollBar(YScrollBar scrollbar); 26 | } 27 | 28 | /** 29 | * These are common commands that apply to all widgets that have them injected. 30 | */ 31 | mixin template YScrollCommand(T) 32 | { 33 | import tkd.widget.scrollbar; 34 | 35 | /** 36 | * Attach a vertical scrollbar. 37 | * 38 | * Params: 39 | * scrollbar = The scrollbar to attach. 40 | */ 41 | public T attachYScrollBar(YScrollBar scrollbar) 42 | { 43 | this._tk.eval("%s configure -yscrollcommand [list %s set]", this.id, scrollbar.id); 44 | 45 | return this; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Gary Willoughby 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /source/tkd/widget/common/xscrollcommand.d: -------------------------------------------------------------------------------- 1 | /** 2 | * XScroll Command module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.xscrollcommand; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import tkd.widget.scrollbar; 13 | 14 | /** 15 | * If implemented this widget has a text display that is scrollable horizontally. 16 | */ 17 | interface IXScrollable(T) 18 | { 19 | /** 20 | * Attach a horizontal scrollbar. 21 | * 22 | * Params: 23 | * scrollbar = The scrollbar to attach. 24 | * 25 | * Returns: 26 | * This widget to aid method chaining. 27 | */ 28 | public T attachXScrollBar(XScrollBar scrollbar); 29 | } 30 | 31 | /** 32 | * These are common commands that apply to all widgets that have them injected. 33 | */ 34 | mixin template XScrollCommand(T) 35 | { 36 | import tkd.widget.scrollbar; 37 | 38 | /** 39 | * Attach a horizontal scrollbar. 40 | * 41 | * Params: 42 | * scrollbar = The scrollbar to attach. 43 | */ 44 | public T attachXScrollBar(XScrollBar scrollbar) 45 | { 46 | this._tk.eval("%s configure -xscrollcommand [list %s set]", this.id, scrollbar.id); 47 | 48 | return this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /source/tkd/widget/common/text.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Text module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.text; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Text() 13 | { 14 | import std.conv; 15 | 16 | /** 17 | * Get the widget text. 18 | * 19 | * Returns: 20 | * The widget text 21 | */ 22 | public string getText() 23 | { 24 | this._tk.eval("%s cget -text", this.id); 25 | return this._tk.getResult!(string); 26 | } 27 | 28 | /** 29 | * Get the index where the insert cursor is. 30 | * 31 | * Params: 32 | * text = The widget text to set. 33 | * 34 | * Returns: 35 | * This widget to aid method chaining. 36 | */ 37 | public auto setText(this T)(string text) 38 | { 39 | // String concatenation is used to build the script here instead of 40 | // using format specifiers to enable supporting input which includes 41 | // Tcl/Tk reserved characters and elements that could be construed as 42 | // format specifiers. 43 | string script = std.conv.text(this.id, ` configure -text `, `"`, this._tk.escape(text), `"`); 44 | this._tk.eval(script); 45 | 46 | return cast(T) this; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /source/tkd/widget/common/selection.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Selection module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.selection; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Selection() 13 | { 14 | /** 15 | * Clear the text selection. 16 | * 17 | * Returns: 18 | * This widget to aid method chaining. 19 | */ 20 | public auto deselectText(this T)() 21 | { 22 | this._tk.eval("%s selection clear", this.id); 23 | 24 | return cast(T) this; 25 | } 26 | 27 | /** 28 | * Check if any text selected. 29 | */ 30 | public bool isTextSelected() 31 | { 32 | this._tk.eval("%s selection present", this.id); 33 | return this._tk.getResult!(int) == 1; 34 | } 35 | 36 | /** 37 | * Select the text. 38 | * 39 | * Params: 40 | * startCharIndex = The index where the selection starts. 41 | * endCharIndex = The index where the selection ends. 42 | * 43 | * Returns: 44 | * This widget to aid method chaining. 45 | */ 46 | public auto selectText(this T)(int startCharIndex = 0, int endCharIndex = int.max) 47 | { 48 | this._tk.eval("%s selection range %s %s", this.id, startCharIndex, endCharIndex); 49 | 50 | return cast(T) this; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /source/tkd/widget/common/index.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Index module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.index; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Index() 13 | { 14 | /** 15 | * Get the length of the text. 16 | * 17 | * Returns: 18 | * The length of the text. 19 | */ 20 | public int getTextLength() 21 | { 22 | this._tk.eval("%s index end", this.id); 23 | return this._tk.getResult!(int); 24 | } 25 | 26 | /** 27 | * Get the index where the insert cursor is. 28 | * 29 | * Returns: 30 | * An int of the index where the insert cursor is. 31 | */ 32 | public int getCursorIndex() 33 | { 34 | this._tk.eval("%s index insert", this.id); 35 | return this._tk.getResult!(int); 36 | } 37 | 38 | /** 39 | * Get the start and end indexes of the text selection if there is one. 40 | * 41 | * Returns: 42 | * An array holding the start and end indexes of a text selection. 43 | */ 44 | public int[] getSelectedTextIndices() 45 | { 46 | int[] result; 47 | 48 | this._tk.eval("%s index sel.first", this.id); 49 | result ~= this._tk.getResult!(int); 50 | 51 | this._tk.eval("%s index sel.last", this.id); 52 | result ~= this._tk.getResult!(int); 53 | 54 | return result; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/anchor.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Anchor module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.canvas.anchor; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Anchor() 13 | { 14 | /** 15 | * The anchor position. 16 | */ 17 | private string _anchor; 18 | 19 | /** 20 | * Get the anchor. 21 | * 22 | * Returns: 23 | * The anchor of the item. 24 | */ 25 | public string getAnchor() 26 | { 27 | if (this._parent) 28 | { 29 | this._tk.eval("%s itemcget %s -anchor", this._parent.id, this.id); 30 | this._anchor = this._tk.getResult!(string); 31 | } 32 | 33 | return this._anchor; 34 | } 35 | 36 | /** 37 | * Set the anchor position. 38 | * 39 | * Params: 40 | * anchor = The anchor position of the text. 41 | * 42 | * Returns: 43 | * This widget to aid method chaining. 44 | * 45 | * See_Also: 46 | * $(LINK2 ../../anchorposition.html, tkd.widget.anchorposition) $(BR) 47 | */ 48 | public auto setAnchor(this T)(string anchor) 49 | { 50 | this._anchor = anchor; 51 | 52 | if (this._parent && this._anchor.length) 53 | { 54 | this._tk.eval("%s itemconfigure %s -anchor {%s}", this._parent.id, this.id, this._anchor); 55 | } 56 | 57 | return cast(T) this; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/state.d: -------------------------------------------------------------------------------- 1 | /** 2 | * State module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.canvas.state; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template State() 13 | { 14 | /** 15 | * The state of the item. 16 | */ 17 | private string _state; 18 | 19 | /** 20 | * Get the state of this item. 21 | * 22 | * Returns: 23 | * The state of this item. 24 | */ 25 | public string getState() 26 | { 27 | if (this._parent) 28 | { 29 | this._tk.eval("%s itemcget %s -state", this._parent.id, this.id); 30 | this._state = this._tk.getResult!(string); 31 | } 32 | 33 | return this._state; 34 | } 35 | 36 | /** 37 | * Set the item state. The only valid states are normal, disabled or 38 | * hidden. 39 | * 40 | * Params: 41 | * state = The state to set. 42 | * 43 | * Returns: 44 | * This item to aid method chaining. 45 | * 46 | * See_Also: 47 | * $(LINK2 ./state.html, tkd.widget.state) $(BR) 48 | */ 49 | public auto setState(this T)(string state) 50 | { 51 | this._state = state; 52 | 53 | if (this._parent && this._state.length) 54 | { 55 | this._tk.eval("%s itemconfigure %s -state {%s}", this._parent.id, this.id, this._state); 56 | } 57 | 58 | return cast(T) this; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /source/tkd/widget/common/data.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Values module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.data; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Data() 13 | { 14 | import std.array; 15 | import std.conv; 16 | import std.string; 17 | 18 | /** 19 | * Get the data values of the widget. 20 | * 21 | * Returns: 22 | * An array of data values. 23 | */ 24 | public string[] getData() 25 | { 26 | this._tk.eval("%s cget -values", this.id); 27 | return this._tk.getResult!(string).replace("\"", "").split(); 28 | } 29 | 30 | /** 31 | * Set data values of the widget. 32 | * 33 | * Params: 34 | * values = The data values. 35 | * 36 | * Returns: 37 | * This widget to aid method chaining. 38 | */ 39 | public auto setData(this T)(string[] values) 40 | { 41 | string data = format(`[list "%s"]`, this._tk.escape(values).join(`" "`)); 42 | 43 | // String concatenation is used to build the script here instead of 44 | // using format specifiers to enable supporting input which includes 45 | // Tcl/Tk reserved characters and elements that could be construed as 46 | // format specifiers. 47 | string script = std.conv.text(this.id, ` configure -values `, data); 48 | this._tk.eval(script); 49 | 50 | return cast(T) this; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /source/tkd/widget/package.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget; 8 | 9 | public import tkd.element.element : CommandArgs; 10 | public import tkd.widget.alignment; 11 | public import tkd.widget.anchorposition; 12 | public import tkd.widget.button; 13 | public import tkd.widget.canvas; 14 | public import tkd.widget.checkbutton; 15 | public import tkd.widget.combobox; 16 | public import tkd.widget.entry; 17 | public import tkd.widget.frame; 18 | public import tkd.widget.keyboardfocus; 19 | public import tkd.widget.label; 20 | public import tkd.widget.labelframe; 21 | public import tkd.widget.menu; 22 | public import tkd.widget.menubutton; 23 | public import tkd.widget.notebook; 24 | public import tkd.widget.orientation; 25 | public import tkd.widget.panedwindow; 26 | public import tkd.widget.progressbar; 27 | public import tkd.widget.radiobutton; 28 | public import tkd.widget.reliefstyle; 29 | public import tkd.widget.scale; 30 | public import tkd.widget.scrollbar; 31 | public import tkd.widget.separator; 32 | public import tkd.widget.sizegrip; 33 | public import tkd.widget.spinbox; 34 | public import tkd.widget.state; 35 | public import tkd.widget.style; 36 | public import tkd.widget.text; 37 | public import tkd.widget.textwrapmode; 38 | public import tkd.widget.treeview; 39 | public import tkd.widget.widget : GeometrySide, GeometryFill, GeometryBorderMode; 40 | -------------------------------------------------------------------------------- /source/tkd/element/elementclass.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Element module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.element.elementclass; 8 | 9 | /** 10 | * Class values of widgets. 11 | */ 12 | enum ElementClass : string 13 | { 14 | button = "TButton", /// Button widget class. 15 | canvas = "Canvas", /// Canvas widget class. 16 | checkButton = "TCheckbutton", /// CheckButton widget class. 17 | comboBox = "TCombobox", /// ComboBox widget class. 18 | entry = "TEntry", /// Entry widget class. 19 | frame = "TFrame", /// Frame widget class. 20 | label = "TLabel", /// Label widget class. 21 | labelFrame = "TLabelframe", /// LabelFrame widget class. 22 | menuButton = "TMenubutton", /// MenuButton widget class. 23 | noteBook = "TNotebook", /// NoteBook widget class. 24 | panedWindow = "TPanedwindow", /// PanedWindow widget class. 25 | progressBar = "TProgressbar", /// ProgressBar widget class. 26 | radioButton = "TRadiobutton", /// RadioButton widget class. 27 | scale = "TScale", /// Scale widget class. 28 | scrollBar = "TScrollbar", /// ScrollBar widget class. 29 | separator = "TSeparator", /// Separator widget class. 30 | sizeGrip = "TSizegrip", /// SizeGrip widget class. 31 | spinBox = "TSpinbox", /// SpinBox widget class. 32 | text = "Text", /// Text widget class. 33 | treeView = "Treeview", /// Treeview widget class. 34 | } 35 | -------------------------------------------------------------------------------- /source/tkd/widget/common/value.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Value module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.value; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | * 12 | * Params: 13 | * valueVariable = The name of the variable that holds the widget's value. 14 | * V = The type of the variable to set. 15 | */ 16 | mixin template Value(alias valueVariable, V) 17 | { 18 | import std.conv; 19 | 20 | /** 21 | * Get the value of the widget. 22 | * 23 | * Params: 24 | * T = The type of the value to return. 25 | * 26 | * Returns: 27 | * The value of the widget. 28 | */ 29 | public T getValue(T = V)() 30 | { 31 | return this._tk.getVariable(valueVariable).to!(T); 32 | } 33 | 34 | /** 35 | * Set the string value of the widget. 36 | * 37 | * Params: 38 | * value = The new widget value. 39 | * 40 | * Returns: 41 | * This widget to aid method chaining. 42 | */ 43 | public auto setValue(this T)(V value) 44 | { 45 | this._tk.setVariable(valueVariable, value); 46 | 47 | return cast(T) this; 48 | } 49 | 50 | /** 51 | * Destroy this widget. 52 | * 53 | * Caveats: 54 | * Once a widget is destroyed it can no longer be referenced in your 55 | * code or a segmentation fault will occur and potentially crash your 56 | * program. 57 | */ 58 | override public void destroy() 59 | { 60 | this._tk.deleteVariable(valueVariable); 61 | super.destroy(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /source/tkd/widget/sizegrip.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.sizegrip; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.string; 13 | import tkd.element.uielement; 14 | import tkd.widget.widget; 15 | 16 | /** 17 | * A sizegrip widget (also known as a grow box) allows the user to resize the 18 | * containing toplevel window by pressing and dragging the grip. 19 | * 20 | * Example: 21 | * --- 22 | * auto sizeGrip = new SizeGrip() 23 | * .pack(0, 0, GeometrySide.bottom, GeometryFill.none, AnchorPosition.southEast); 24 | * --- 25 | * 26 | * Additional_Events: 27 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 28 | * $(P 29 | * <<PrevWindow>>, 30 | * <Alt-Key>, 31 | * <B1-Motion>, 32 | * <Button-1>, 33 | * <ButtonRelease-1>, 34 | * <Key-F10>, 35 | * <Key-Tab>, 36 | * ) 37 | * 38 | * See_Also: 39 | * $(LINK2 ./widget.html, tkd.widget.widget) 40 | */ 41 | class SizeGrip : Widget 42 | { 43 | /** 44 | * Construct the widget. 45 | * 46 | * Params: 47 | * parent = The parent of this widget. 48 | * 49 | * See_Also: 50 | * $(LINK2 ../element/uielement.html, tkd.element.UiElement) $(BR) 51 | */ 52 | public this(UiElement parent = null) 53 | { 54 | super(parent); 55 | this._elementId = "sizegrip"; 56 | 57 | this._tk.eval("ttk::sizegrip %s", this.id); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /source/tkd/widget/style.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.style; 8 | 9 | /** 10 | * Standard style values of widgets. 11 | */ 12 | enum Style : string 13 | { 14 | button = "TButton", /// Button widget style. 15 | canvas = "Canvas", /// Canvas widget style. 16 | checkButton = "TCheckbutton", /// CheckButton widget style. 17 | comboBox = "TCombobox", /// ComboBox widget style. 18 | entry = "TEntry", /// Entry widget style. 19 | frame = "TFrame", /// Frame widget style. 20 | label = "TLabel", /// Label widget style. 21 | labelFrame = "TLabelframe", /// LabelFrame widget style. 22 | menuButton = "TMenubutton", /// MenuButton widget style. 23 | noteBook = "TNotebook", /// NoteBook widget style. 24 | panedWindow = "TPanedwindow", /// PanedWindow widget style. 25 | progressBar = "TProgressbar", /// ProgressBar widget style. 26 | radioButton = "TRadiobutton", /// RadioButton widget style. 27 | scale = "TScale", /// Scale widget style. 28 | scrollBar = "TScrollbar", /// ScrollBar widget style. 29 | separator = "TSeparator", /// Separator widget style. 30 | sizeGrip = "TSizegrip", /// SizeGrip widget style. 31 | spinBox = "TSpinbox", /// SpinBox widget style. 32 | text = "Text", /// Text widget style. 33 | treeView = "Treeview", /// Treeview widget style. 34 | 35 | toolbutton = "Toolbutton", /// Toolbutton style. Useful for styling widget for use on a toolbar. 36 | } 37 | -------------------------------------------------------------------------------- /source/tkd/interpreter/tk.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Tk interpreter module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.interpreter.tk; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.conv; 13 | import std.string; 14 | import tcltk.tk; 15 | import tkd.interpreter.tcl; 16 | 17 | /** 18 | * Simple singleton wrapper for the Tk interpreter. 19 | */ 20 | class Tk : Tcl 21 | { 22 | /** 23 | * An instance of this tk interpreter. 24 | */ 25 | private static Tk _instance; 26 | 27 | /* 28 | * Create the interpreter and initialise it. 29 | * 30 | * Throws: 31 | * Exception if Tk interpreter cannot be initialised. 32 | */ 33 | protected this() 34 | { 35 | super(); 36 | 37 | debug (log) this._log.info("Inititalising Tk"); 38 | 39 | if (Tk_Init(this._interpreter) != TCL_OK) 40 | { 41 | string result = Tcl_GetStringResult(this._interpreter).to!(string); 42 | throw new Exception(format("Tk interpreter extension could not be initialised. %s", result)); 43 | } 44 | } 45 | 46 | /** 47 | * Get an instance of this class. 48 | * 49 | * Returns: 50 | * If An instance doesn't exist, one is created and returned. 51 | * If one already exists, that is returned. 52 | */ 53 | public static Tk getInstance() 54 | { 55 | if (Tk._instance is null) 56 | { 57 | Tk._instance = new Tk(); 58 | } 59 | return Tk._instance; 60 | } 61 | 62 | /** 63 | * Run the tk main loop, show the gui and start processing events. 64 | */ 65 | public void run() 66 | { 67 | debug (log) this._log.info("Running Tk main loop"); 68 | Tk_MainLoop(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /source/tkd/image/png.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Image module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.image.png; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.base64; 13 | import std.file; 14 | import tkd.image.image; 15 | import tkd.image.imageformat; 16 | 17 | /** 18 | * Helper class to quickly create a Png format image. 19 | * 20 | * See_Also: 21 | * $(LINK2 ../image/image.html, tkd.image.image) $(BR) 22 | */ 23 | class Png : Image 24 | { 25 | /** 26 | * Construct the image. 27 | * 28 | * Params: 29 | * file = The file name of the image to load. 30 | */ 31 | public this(string file) 32 | { 33 | super(); 34 | 35 | this.setFormat(ImageFormat.png); 36 | 37 | if (file) 38 | { 39 | this.setFile(file); 40 | } 41 | } 42 | 43 | /** 44 | * Set the image alpha. 45 | * 46 | * Params: 47 | * alpha = The alpha of the image. 48 | * 49 | * Returns: 50 | * This image to aid method chaining. 51 | */ 52 | public auto setAlpha(this T)(double alpha) 53 | { 54 | if (alpha < 0f || alpha > 1.0f) 55 | { 56 | alpha = 1.0f; 57 | } 58 | 59 | this._tk.eval("%s configure -format {png -alpha %s}", this.id, alpha); 60 | 61 | return cast(T) this; 62 | } 63 | } 64 | 65 | /** 66 | * Helper class to quickly create an embedded Png format image. 67 | * 68 | * Params: 69 | * file = The file name of the image to embed. 70 | * 71 | * See_Also: 72 | * $(LINK2 ../image/image.html, tkd.image.image) $(BR) 73 | */ 74 | class EmbeddedPng(string file) : Png 75 | { 76 | /** 77 | * Construct the image. 78 | */ 79 | public this() 80 | { 81 | super(null); 82 | 83 | this.embedBase64Data!(file); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /source/tkd/image/gif.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Image module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.image.gif; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.base64; 13 | import std.file; 14 | import tkd.image.image; 15 | import tkd.image.imageformat; 16 | 17 | /** 18 | * Helper class to quickly create an embedded Gif format image. 19 | * 20 | * See_Also: 21 | * $(LINK2 ../image/image.html, tkd.image.image) $(BR) 22 | */ 23 | class Gif : Image 24 | { 25 | /** 26 | * Construct the image. 27 | * 28 | * Params: 29 | * file = The file name of the image to load. 30 | */ 31 | public this(string file) 32 | { 33 | super(); 34 | 35 | this.setFormat(ImageFormat.gif); 36 | 37 | if (file) 38 | { 39 | this.setFile(file); 40 | } 41 | } 42 | 43 | /** 44 | * Select the index if a multi-indexed gif. 45 | * If you select an idex which doesn't exist in the image an error will occur. 46 | * 47 | * Params: 48 | * index = The index to select. 49 | * 50 | * Returns: 51 | * This image to aid method chaining. 52 | */ 53 | public auto setIndex(this T)(int index) 54 | { 55 | this._tk.eval("%s configure -format {gif -index %s}", this.id, index); 56 | 57 | return cast(T) this; 58 | } 59 | } 60 | 61 | /** 62 | * Helper class to quickly create an embedded Gif format image. 63 | * 64 | * Params: 65 | * file = The file name of the image to embed. 66 | * 67 | * See_Also: 68 | * $(LINK2 ../image/image.html, tkd.image.image) $(BR) 69 | */ 70 | class EmbeddedGif(string file) : Gif 71 | { 72 | /** 73 | * Construct the image. 74 | */ 75 | public this() 76 | { 77 | super(null); 78 | 79 | this.embedBase64Data!(file); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /source/tkd/widget/common/command.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Command module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.command; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Command() 13 | { 14 | import tkd.element.element : CommandCallback; 15 | 16 | /** 17 | * Add a command to a widget. 18 | * 19 | * Params: 20 | * callback = The delegate callback to execute when invoking the command. 21 | * 22 | * Returns: 23 | * This widget to aid method chaining. 24 | * 25 | * Callback_Arguments: 26 | * These are the fields within the callback's $(LINK2 27 | * ./element/element.html#CommandArgs, CommandArgs) parameter which 28 | * are populated by this method when the callback is executed. 29 | * $(P 30 | * $(PARAM_TABLE 31 | * $(PARAM_ROW CommandArgs.element, The element that executed the callback.) 32 | * $(PARAM_ROW CommandArgs.callback, The callback which was executed.) 33 | * ) 34 | * ) 35 | * 36 | * See_Also: 37 | * $(LINK2 ../../element/element.html#CommandCallback, tkd.element.element.CommandCallback) 38 | */ 39 | public auto setCommand(this T)(CommandCallback callback) 40 | { 41 | string command = this.createCommand(callback); 42 | this._tk.eval("%s configure -command %s", this.id, command); 43 | 44 | return cast(T) this; 45 | } 46 | 47 | /** 48 | * Remove a previously set command. 49 | * 50 | * Returns: 51 | * This widget to aid method chaining. 52 | */ 53 | public auto removeCommand(this T)() 54 | { 55 | this._tk.deleteCommand(this.getCommandName()); 56 | this._tk.eval("%s configure -command {}", this.id); 57 | 58 | return cast(T) this; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /docs/tkd/theme.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | tkd.theme 10 | 11 | 12 |

tkd.theme

13 | 14 |

TkdApplication module. 15 |

16 |

License

MIT. See LICENSE for full details.

17 |
18 |

enum Theme: string; 19 |

20 |

Standard themes.

21 |
22 |

alt

23 |

The alternate theme.

24 |
25 |
26 |

classic

27 |

The classic theme.

28 |
29 |
30 |

default_

31 |

The default theme.

32 |
33 |
34 |

clam

35 |

The Clam theme.

36 |
37 |
38 |
39 |
40 |
41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /source/tkd/window/dialog/dialog.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Dialog module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.window.dialog.dialog; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.regex; 13 | import tkd.element.element; 14 | import tkd.window.window; 15 | 16 | /** 17 | * Abstract base class for all dialog boxes. 18 | * 19 | * See_Also: 20 | * $(LINK2 ../../element/element.html, tkd.element.element) $(BR) 21 | */ 22 | abstract class Dialog : Element 23 | { 24 | /* 25 | * The parent window of the dialog. 26 | */ 27 | protected Window _parent; 28 | 29 | /* 30 | * The title of the dialog. 31 | */ 32 | protected string _title; 33 | 34 | /* 35 | * The result of the dialog. 36 | */ 37 | protected string[] _results; 38 | 39 | /** 40 | * Construct the dialog. 41 | * 42 | * Params: 43 | * parent = The parent window of the dialog. 44 | * title = The title of the dialog. 45 | */ 46 | this(Window parent, string title) 47 | { 48 | this._elementId = "dialog"; 49 | this._parent = parent; 50 | this._title = title; 51 | } 52 | 53 | /** 54 | * Get the dialog result. This varies on the type of dialog used and will 55 | * reflect the overall result expected of each dialog. 56 | * 57 | * Returns: 58 | * The result of the dialog or an empty string. 59 | */ 60 | public string getResult() 61 | { 62 | return this._results.length ? this._results[0] : ""; 63 | } 64 | 65 | /** 66 | * Remove any leading or trailing braces. 67 | */ 68 | protected void removeBracesFromResults() 69 | { 70 | foreach (ref result; this._results) 71 | { 72 | result = result.replace(regex(r"^\{"), ""); 73 | result = result.replace(regex(r"\}$"), ""); 74 | } 75 | } 76 | 77 | /** 78 | * Show the dialog. 79 | * 80 | * Returns: 81 | * This dialog to aid method chaining. 82 | */ 83 | abstract public auto show(this T)(); 84 | } 85 | -------------------------------------------------------------------------------- /source/tkd/widget/separator.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.separator; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.string; 13 | import tkd.element.uielement; 14 | import tkd.widget.orientation; 15 | import tkd.widget.widget; 16 | 17 | /** 18 | * A separator widget displays a horizontal or vertical separator bar. 19 | * 20 | * Example: 21 | * --- 22 | * auto separator = new Separator() 23 | * .pack(0, 0, GeometrySide.top, GeometryFill.x); 24 | * --- 25 | * 26 | * Additional_Events: 27 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 28 | * $(P 29 | * <<PrevWindow>>, 30 | * <Alt-Key>, 31 | * <Key-F10>, 32 | * <Key-Tab>, 33 | * ) 34 | * 35 | * See_Also: 36 | * $(LINK2 ./widget.html, tkd.widget.widget) 37 | */ 38 | class Separator : Widget 39 | { 40 | /** 41 | * Construct the widget. 42 | * 43 | * Params: 44 | * parent = The parent of this widget. 45 | * orientation = The orientation of the widget. 46 | * 47 | * See_Also: 48 | * $(LINK2 ../element/uielement.html, tkd.element.UiElement) $(BR) 49 | * $(LINK2 ./orientation.html, tkd.widget.orientation) for orientations. 50 | */ 51 | public this(UiElement parent, string orientation = Orientation.horizontal) 52 | { 53 | super(parent); 54 | this._elementId = "separator"; 55 | 56 | this._tk.eval("ttk::separator %s -orient %s", this.id, orientation); 57 | } 58 | 59 | /** 60 | * Construct the widget. 61 | * 62 | * Params: 63 | * orientation = The orientation of the widget. 64 | * 65 | * See_Also: 66 | * $(LINK2 ./orientation.html, tkd.widget.orientation) for orientations. 67 | */ 68 | public this(string orientation = Orientation.horizontal) 69 | { 70 | this(null, orientation); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /source/tkd/widget/common/color.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Color module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.color; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Color() 13 | { 14 | /** 15 | * Set the foreground color of the widget. 16 | * 17 | * Params: 18 | * color = The name of the color, e.g. 'black' or a hex value, e.g. '#000000'. 19 | * 20 | * Returns: 21 | * This widget to aid method chaining. 22 | * 23 | * See_Also: 24 | * $(LINK2 ../../element/color.html, tkd.element.color) for standard defined colors. 25 | */ 26 | public auto setForegroundColor(this T)(string color) 27 | { 28 | this._tk.eval("%s configure -foreground %s", this.id, color); 29 | 30 | return cast(T) this; 31 | } 32 | 33 | /** 34 | * Set the background color of the widget. 35 | * 36 | * Params: 37 | * color = The name of the color, e.g. 'black' or a hex value, e.g. '#000000'. 38 | * 39 | * Returns: 40 | * This widget to aid method chaining. 41 | * 42 | * See_Also: 43 | * $(LINK2 ../../element/color.html, tkd.element.color) for standard defined colors. 44 | */ 45 | public auto setBackgroundColor(this T)(string color) 46 | { 47 | this._tk.eval("%s configure -background %s", this.id, color); 48 | 49 | return cast(T) this; 50 | } 51 | 52 | /** 53 | * Set the insert cursor color of the widget. 54 | * 55 | * Params: 56 | * color = The name of the color, e.g. 'black' or a hex value, e.g. '#000000'. 57 | * 58 | * Returns: 59 | * This widget to aid method chaining. 60 | * 61 | * See_Also: 62 | * $(LINK2 ../../element/color.html, tkd.element.color) for standard defined colors. 63 | */ 64 | public auto setInsertColor(this T)(string color) 65 | { 66 | this._tk.eval("%s configure -insertbackground %s", this.id, color); 67 | 68 | return cast(T) this; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /source/tkd/widget/common/postcommand.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Post command module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.postcommand; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template PostCommand() 13 | { 14 | import std.string; 15 | import tkd.element.element; 16 | 17 | /** 18 | * Add a post command to a widget. This is usually to modify the widget after creation. 19 | * 20 | * Params: 21 | * callback = The delegate callback to execute when invoking the post command. 22 | * 23 | * Returns: 24 | * This widget to aid method chaining. 25 | * 26 | * Callback_Arguments: 27 | * These are the fields within the callback's $(LINK2 28 | * ../../element/element.html#CommandArgs, CommandArgs) parameter which 29 | * are populated by this method when the callback is executed. 30 | * $(P 31 | * $(PARAM_TABLE 32 | * $(PARAM_ROW CommandArgs.element, The element that executed the callback.) 33 | * $(PARAM_ROW CommandArgs.uniqueData, The string 'postcommand'.) 34 | * $(PARAM_ROW CommandArgs.callback, The callback which was executed.) 35 | * ) 36 | * ) 37 | * 38 | * See_Also: 39 | * $(LINK2 ../../element/element.html#CommandCallback, tkd.element.element.CommandCallback) 40 | */ 41 | public auto setPostCommand(this T)(CommandCallback callback) 42 | { 43 | string command = this.createCommand(callback, "postcommand"); 44 | this._tk.eval("%s configure -postcommand %s", this.id, command); 45 | 46 | return cast(T) this; 47 | } 48 | 49 | /** 50 | * Remove a previously set post command. 51 | * 52 | * Returns: 53 | * This widget to aid method chaining. 54 | */ 55 | public auto removePostCommand(this T)() 56 | { 57 | this._tk.deleteCommand(this.getCommandName("postcommand")); 58 | this._tk.eval("%s configure -postcommand {}", this.id); 59 | 60 | return cast(T) this; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /source/tkd/widget/common/font.d: -------------------------------------------------------------------------------- 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 | } 72 | -------------------------------------------------------------------------------- /source/tkd/widget/common/insert.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Insert module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.insert; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Insert() 13 | { 14 | import std.conv; 15 | 16 | /** 17 | * Insert text at an index. 18 | * 19 | * Params: 20 | * text = The text to insert. 21 | * charIndex = The index to insert the text. 22 | * 23 | * Returns: 24 | * This widget to aid method chaining. 25 | */ 26 | public auto insertTextAt(this T)(string text, int charIndex) 27 | { 28 | // String concatenation is used to build the script here instead of 29 | // using format specifiers to enable supporting input which includes 30 | // Tcl/Tk reserved characters and elements that could be construed as 31 | // format specifiers. 32 | string script = std.conv.text(this.id, ` insert `, charIndex, ` "`, this._tk.escape(text), `"`); 33 | this._tk.eval(script); 34 | 35 | return cast(T) this; 36 | } 37 | 38 | /** 39 | * Append text to the end. 40 | * 41 | * Params: 42 | * text = The text to insert. 43 | * 44 | * Returns: 45 | * This widget to aid method chaining. 46 | */ 47 | public auto appendText(this T)(string text) 48 | { 49 | // String concatenation is used to build the script here instead of 50 | // using format specifiers to enable supporting input which includes 51 | // Tcl/Tk reserved characters and elements that could be construed as 52 | // format specifiers. 53 | string script = std.conv.text(this.id, ` insert end `, `"`, this._tk.escape(text), `"`); 54 | this._tk.eval(script); 55 | 56 | return cast(T) this; 57 | } 58 | 59 | /** 60 | * Insert text at the cursor position. 61 | * 62 | * Params: 63 | * text = The text to insert. 64 | * 65 | * Returns: 66 | * This widget to aid method chaining. 67 | * 68 | * See_Also: 69 | * $(LINK2 ./cursor.html, tkd.widget.common.cursor) $(BR) 70 | * $(LINK2 ./index.html, tkd.widget.common.index) $(BR) 71 | */ 72 | public auto insertTextAtCursor(this T)(string text) 73 | { 74 | // String concatenation is used to build the script here instead of 75 | // using format specifiers to enable supporting input which includes 76 | // Tcl/Tk reserved characters and elements that could be construed as 77 | // format specifiers. 78 | string script = std.conv.text(this.id, ` insert insert `, `"`, this._tk.escape(text), `"`); 79 | this._tk.eval(script); 80 | 81 | return cast(T) this; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /source/tkd/widget/label.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.label; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import tkd.element.uielement; 13 | import tkd.widget.common.anchor; 14 | import tkd.widget.common.color; 15 | import tkd.widget.common.font; 16 | import tkd.widget.common.justify; 17 | import tkd.widget.common.padding; 18 | import tkd.widget.common.relief; 19 | import tkd.widget.common.wraplength; 20 | import tkd.widget.textwidget; 21 | 22 | /** 23 | * A label widget displays a textual label and/or image. 24 | * 25 | * Example: 26 | * --- 27 | * auto label = new Label("Text") 28 | * .pack(); 29 | * --- 30 | * 31 | * Common_Commands: 32 | * These are injected common commands that can also be used with this widget. 33 | * $(P 34 | * $(LINK2 ./common/anchor.html, Anchor) $(BR) 35 | * $(LINK2 ./common/color.html, Color) $(BR) 36 | * $(LINK2 ./common/font.html, Font) $(BR) 37 | * $(LINK2 ./common/justify.html, Justify) $(BR) 38 | * $(LINK2 ./common/padding.html, Padding) $(BR) 39 | * $(LINK2 ./common/relief.html, Relief) $(BR) 40 | * $(LINK2 ./common/wraplength.html, WrapLength) $(BR) 41 | * ) 42 | * 43 | * Additional_Events: 44 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 45 | * $(P 46 | * <<Invoke>>, 47 | * <<PrevWindow>>, 48 | * <Key-Tab>, 49 | * <Key-F10>, 50 | * <Alt-Key>, 51 | * ) 52 | * 53 | * See_Also: 54 | * $(LINK2 ./textwidget.html, tkd.widget.textwidget) 55 | */ 56 | class Label : TextWidget 57 | { 58 | /** 59 | * Construct the widget. 60 | * 61 | * Params: 62 | * parent = The parent of this widget. 63 | * text = The text of the label. 64 | * 65 | * See_Also: 66 | * $(LINK2 ../element/uielement.html, tkd.element.uielement) $(BR) 67 | */ 68 | this(UiElement parent, string text) 69 | { 70 | super(parent); 71 | this._elementId = "label"; 72 | 73 | this._tk.eval("ttk::label %s -textvariable %s", this.id, this._textVariable); 74 | 75 | this.setText(text); 76 | } 77 | 78 | /** 79 | * Construct the widget. 80 | * 81 | * Params: 82 | * text = The text of the label. 83 | */ 84 | this(string text) 85 | { 86 | this(null, text); 87 | } 88 | 89 | /** 90 | * Mixin common commands. 91 | */ 92 | mixin Anchor; 93 | mixin Color; 94 | mixin Font; 95 | mixin Justify; 96 | mixin Padding; 97 | mixin Relief; 98 | mixin WrapLength; 99 | } 100 | -------------------------------------------------------------------------------- /source/tkd/window/dialog/colordialog.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Dialog module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.window.dialog.colordialog; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.regex; 13 | import tkd.element.color; 14 | import tkd.window.dialog.dialog; 15 | import tkd.window.window; 16 | 17 | /** 18 | * Pops up a dialog box for the user to select a color. 19 | * 20 | * Example: 21 | * --- 22 | * auto dialog = new ColorDialog("Select a color") 23 | * .setInitialColor(Color.white) 24 | * .show(); 25 | * 26 | * string color = dialog.getResult(); 27 | * --- 28 | * 29 | * Result: 30 | * The web style hex color selected. 31 | * 32 | * See_Also: 33 | * $(LINK2 ./dialog.html, tkd.dialog.dialog) $(BR) 34 | */ 35 | class ColorDialog : Dialog 36 | { 37 | /** 38 | * The initial color to display in the dialog. 39 | */ 40 | private string _inititalColor = Color.white; 41 | 42 | /** 43 | * Construct the dialog. 44 | * 45 | * Params: 46 | * parent = The parent window of the dialog. 47 | * title = The title of the dialog. 48 | */ 49 | this(Window parent, string title = "Color") 50 | { 51 | super(parent, title); 52 | } 53 | 54 | /** 55 | * Construct the dialog. 56 | * 57 | * Params: 58 | * title = The title of the dialog. 59 | */ 60 | this(string title = "Color") 61 | { 62 | this(null, title); 63 | } 64 | 65 | /** 66 | * Set the initial color to display in the dialog. 67 | * Use colors from the preset color $(LINK2 ../../element/color.html, list) or a web style hex color. 68 | * 69 | * Params: 70 | * color = The initial color. 71 | * 72 | * Returns: 73 | * This dialog to aid method chaining. 74 | * 75 | * See_Also: 76 | * $(LINK2 ../../element/color.html, tkd.widget.color) $(BR) 77 | * 78 | * Caveats: 79 | * If the passed color is not recognised the dialog will fail to show. 80 | */ 81 | public auto setInitialColor(this T)(string color) 82 | { 83 | this._inititalColor = color; 84 | 85 | return cast(T) this; 86 | } 87 | 88 | /** 89 | * Show the dialog. 90 | * 91 | * Returns: 92 | * This dialog to aid method chaining. 93 | */ 94 | public auto show(this T)() 95 | { 96 | if (this._parent) 97 | { 98 | this._tk.eval("tk_chooseColor -parent %s -title {%s} -initialcolor {%s}", this._parent.id, this._title, this._inititalColor); 99 | } 100 | else 101 | { 102 | this._tk.eval("tk_chooseColor -title {%s} -initialcolor {%s}", this._title, this._inititalColor); 103 | } 104 | 105 | string result = this._tk.getResult!(string); 106 | 107 | if (match(result, r"^unknown color name").empty) 108 | { 109 | this._results = [result]; 110 | } 111 | 112 | return cast(T) this; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /source/tkd/widget/frame.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.frame; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import tkd.element.uielement; 13 | import tkd.widget.common.border; 14 | import tkd.widget.common.height; 15 | import tkd.widget.common.padding; 16 | import tkd.widget.common.relief; 17 | import tkd.widget.common.width; 18 | import tkd.widget.reliefstyle; 19 | import tkd.widget.widget; 20 | 21 | /** 22 | * A frame widget is a container, used to group other widgets together. 23 | * 24 | * Example: 25 | * --- 26 | * auto frame = new Frame(2, ReliefStyle.groove) 27 | * .pack(0, 10); 28 | * 29 | * // Add a button to the frame. 30 | * auto button = new Button(frame, "Text") 31 | * .pack(); 32 | * --- 33 | * 34 | * Common_Commands: 35 | * These are injected common commands that can also be used with this widget. 36 | * $(P 37 | * $(LINK2 ./common/border.html, Border) $(BR) 38 | * $(LINK2 ./common/height.html, Height) $(BR) 39 | * $(LINK2 ./common/padding.html, Padding) $(BR) 40 | * $(LINK2 ./common/relief.html, Relief) $(BR) 41 | * $(LINK2 ./common/width.html, Width) $(BR) 42 | * ) 43 | * 44 | * Additional_Events: 45 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 46 | * $(P 47 | * <<PrevWindow>>, 48 | * <Alt-Key>, 49 | * <Key-F10>, 50 | * <Key-Tab>, 51 | * ) 52 | * 53 | * See_Also: 54 | * $(LINK2 ./widget.html, tkd.widget.widget) 55 | */ 56 | class Frame : Widget 57 | { 58 | /** 59 | * Construct the widget. 60 | * 61 | * Params: 62 | * parent = The parent of this widget. 63 | * borderWidth = The width of the frame border. 64 | * relief = The relief style of the border. 65 | * 66 | * See_Also: 67 | * $(LINK2 ../element/uielement.html, tkd.element.UiElement) $(BR) 68 | * $(LINK2 ./reliefstyle.html, tkd.widget.reliefstyle) $(BR) 69 | */ 70 | public this(UiElement parent, int borderWidth = 0, string relief = ReliefStyle.flat) 71 | { 72 | super(parent); 73 | this._elementId = "frame"; 74 | 75 | this._tk.eval("ttk::frame %s", this.id); 76 | 77 | this.setBorderWidth(borderWidth); 78 | this.setRelief(relief); 79 | } 80 | 81 | /** 82 | * Construct the widget. 83 | * 84 | * Params: 85 | * borderWidth = The width of the frame border. 86 | * relief = The relief style of the border. 87 | * 88 | * See_Also: 89 | * $(LINK2 ./reliefstyle.html, tkd.widget.reliefstyle) $(BR) 90 | */ 91 | public this(int borderWidth = 0, string relief = ReliefStyle.flat) 92 | { 93 | this(null, borderWidth, relief); 94 | } 95 | 96 | /** 97 | * Mixin common commands. 98 | */ 99 | mixin Border; 100 | mixin Height; 101 | mixin Padding; 102 | mixin Relief; 103 | mixin Width; 104 | } 105 | -------------------------------------------------------------------------------- /source/tkd/widget/common/yview.d: -------------------------------------------------------------------------------- 1 | /** 2 | * YView module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.yview; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template YView() 13 | { 14 | import std.algorithm; 15 | import std.array; 16 | import std.conv; 17 | 18 | /** 19 | * Get floating point values which represent the viewable portion of the 20 | * text. Each element is a real fraction between 0 and 1; together they 21 | * describe the vertical span that is visible in the window. For example, 22 | * if the first element is .2 and the second element is .6, 20% of the 23 | * entry's text is off-screen to the bottom, the middle 40% is visible in the 24 | * window, and 40% of the text is off-screen to the bottom. 25 | * 26 | * Returns: 27 | * An array containing two floating point values. 28 | */ 29 | public double[] getYView() 30 | { 31 | this._tk.eval("%s yview", this.id); 32 | return this._tk.getResult!(string).split().map!(to!(double)).array; 33 | } 34 | 35 | /** 36 | * Adjusts the view in the window so that the position appears at the top 37 | * edge of the window. Position must be a fraction between 0.0 (start of 38 | * the text) and 1.0 (end of the text). 39 | * 40 | * Params: 41 | * position = The character index to scroll to. 42 | * 43 | * Returns: 44 | * This widget to aid method chaining. 45 | */ 46 | public auto setYView(this T)(double position) 47 | { 48 | this._tk.eval("%s yview moveto %s", this.id, position); 49 | 50 | return cast(T) this; 51 | } 52 | 53 | /** 54 | * Adjusts the view in the window so that the character index passed is 55 | * displayed at the top edge of the window. 56 | * 57 | * Params: 58 | * charIndex = The character index to scroll to. 59 | * 60 | * Returns: 61 | * This widget to aid method chaining. 62 | */ 63 | public auto scrollYToChar(this T)(int charIndex) 64 | { 65 | this._tk.eval("%s yview %s", this.id, charIndex); 66 | 67 | return cast(T) this; 68 | } 69 | 70 | /** 71 | * Scroll the text by a specified amount of characters. Positive values 72 | * scroll text to the down, negative values scroll text up. 73 | * 74 | * Params: 75 | * numberOfChars = The number of characters to scroll by. 76 | * 77 | * Returns: 78 | * This widget to aid method chaining. 79 | */ 80 | public auto scrollYChars(this T)(int numberOfChars) 81 | { 82 | this._tk.eval("%s yview scroll %s units", this.id, numberOfChars); 83 | 84 | return cast(T) this; 85 | } 86 | 87 | /** 88 | * Scroll the text by a specified amount of pages. Positive values scroll 89 | * text up, negative values scroll text down. 90 | * 91 | * Params: 92 | * numberOfPages = The number of characters to scroll by. 93 | * 94 | * Returns: 95 | * This widget to aid method chaining. 96 | */ 97 | public auto scrollYPages(this T)(int numberOfPages) 98 | { 99 | this._tk.eval("%s yview scroll %s pages", this.id, numberOfPages); 100 | 101 | return cast(T) this; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /source/tkd/widget/common/xview.d: -------------------------------------------------------------------------------- 1 | /** 2 | * XView module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.xview; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template XView() 13 | { 14 | import std.algorithm; 15 | import std.array; 16 | import std.conv; 17 | 18 | /** 19 | * Get floating point values which represent the viewable portion of the 20 | * text. Each element is a real fraction between 0 and 1; together they 21 | * describe the horizontal span that is visible in the window. For example, 22 | * if the first element is .2 and the second element is .6, 20% of the 23 | * entry's text is off-screen to the left, the middle 40% is visible in the 24 | * window, and 40% of the text is off-screen to the right. 25 | * 26 | * Returns: 27 | * An array containing two floating point values. 28 | */ 29 | public double[] getXView() 30 | { 31 | this._tk.eval("%s xview", this.id); 32 | return this._tk.getResult!(string).split().map!(to!(double)).array; 33 | } 34 | 35 | /** 36 | * Adjusts the view in the window so that the position appears at the left 37 | * edge of the window. Position must be a fraction between 0.0 (start of 38 | * the text) and 1.0 (end of the text). 39 | * 40 | * Params: 41 | * position = The character index to scroll to. 42 | * 43 | * Returns: 44 | * This widget to aid method chaining. 45 | */ 46 | public auto setXView(this T)(double position) 47 | { 48 | this._tk.eval("%s xview moveto %s", this.id, position); 49 | 50 | return cast(T) this; 51 | } 52 | 53 | /** 54 | * Adjusts the view in the window so that the character index passed is 55 | * displayed at the left edge of the window. 56 | * 57 | * Params: 58 | * charIndex = The character index to scroll to. 59 | * 60 | * Returns: 61 | * This widget to aid method chaining. 62 | */ 63 | public auto scrollXToChar(this T)(int charIndex) 64 | { 65 | this._tk.eval("%s xview %s", this.id, charIndex); 66 | 67 | return cast(T) this; 68 | } 69 | 70 | /** 71 | * Scroll the text by a specified amount of characters. Positive values 72 | * scroll text to the left, negative values scroll text to the right. 73 | * 74 | * Params: 75 | * numberOfChars = The number of characters to scroll by. 76 | * 77 | * Returns: 78 | * This widget to aid method chaining. 79 | */ 80 | public auto scrollXChars(this T)(int numberOfChars) 81 | { 82 | this._tk.eval("%s xview scroll %s units", this.id, numberOfChars); 83 | 84 | return cast(T) this; 85 | } 86 | 87 | /** 88 | * Scroll the text by a specified amount of pages. Positive values scroll 89 | * text to the left, negative values scroll text to the right. 90 | * 91 | * Params: 92 | * numberOfPages = The number of characters to scroll by. 93 | * 94 | * Returns: 95 | * This widget to aid method chaining. 96 | */ 97 | public auto scrollXPages(this T)(int numberOfPages) 98 | { 99 | this._tk.eval("%s xview scroll %s pages", this.id, numberOfPages); 100 | 101 | return cast(T) this; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /source/tkd/widget/menu/menubar.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Menu module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.menu.menubar; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import tkd.element.uielement; 13 | import tkd.window.window; 14 | 15 | /** 16 | * A menubar is the bar across the top of a window holding the menu items. 17 | * 18 | * Example: 19 | * --- 20 | * // Add a menu bar to a window. 21 | * auto menuBar = new MenuBar(mainWindow) 22 | * .pack(); 23 | * 24 | * // Add a menu to the menu bar. 25 | * auto menu = new Menu(menuBar, "Menu 1") 26 | * .addEntry("Entry 1", delegate(CommandArgs args){ ... }) 27 | * .addEntry("Entry 2", delegate(CommandArgs args){ ... }) 28 | * .addSeparator() 29 | * .addEntry("Entry 3", delegate(CommandArgs args){ ... }); 30 | * --- 31 | * 32 | * Additional_Events: 33 | * Additional events that can also be bound to using the $(LINK2 ../../element/uielement.html#UiElement.bind, bind) method. 34 | * $(P 35 | * <<MenuSelect>>, 36 | * <<PrevWindow>>, 37 | * <Alt-Key>, 38 | * <Button>, 39 | * <ButtonRelease>, 40 | * <Enter> 41 | * <Key-Down>, 42 | * <Key-Escape>, 43 | * <Key-F10>, 44 | * <Key-Left>, 45 | * <Key-Return>, 46 | * <Key-Right>, 47 | * <Key-Tab>, 48 | * <Key-Up>, 49 | * <Key-space>, 50 | * <Key>, 51 | * <Leave>, 52 | * <Motion>, 53 | * ) 54 | * 55 | * See_Also: 56 | * $(LINK2 ../../element/uielement.html, tkd.element.uielement) 57 | */ 58 | class MenuBar : UiElement 59 | { 60 | /** 61 | * Construct the widget. 62 | * 63 | * Params: 64 | * parent = The parent of this widget. 65 | * 66 | * See_Also: 67 | * $(LINK2 ../../tkdapplication.html#Window, tkd.tkdapplication.Window) 68 | */ 69 | public this(Window parent) 70 | { 71 | super(parent); 72 | 73 | this._elementId = "menubar"; 74 | this._tk.eval("menu %s -tearoff 0", this.id); 75 | this._tk.eval("%s configure -menu %s", parent.id, this.id); 76 | } 77 | 78 | /** 79 | * Disable a child menu. The indexes start at zero for the left-most menu 80 | * and increase as you go right. 81 | * 82 | * Params: 83 | * index = The index of the menu to disable. 84 | * 85 | * Returns: 86 | * This widget to aid method chaining. 87 | */ 88 | public auto disableMenu(this T)(int index) 89 | { 90 | this._tk.eval("%s entryconfigure %s -state disable", this.id, index); 91 | 92 | return cast(T) this; 93 | } 94 | 95 | /** 96 | * Enable a disabled child menu. The indexes start at zero for the 97 | * left-most menu and increase as you go right. 98 | * 99 | * Params: 100 | * index = The index of the menu to enable. 101 | * 102 | * Returns: 103 | * This widget to aid method chaining. 104 | */ 105 | public auto enableMenu(this T)(int index) 106 | { 107 | this._tk.eval("%s entryconfigure %s -state normal", this.id, index); 108 | 109 | return cast(T) this; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/imagespecific.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Image specific module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.canvas.imagespecific; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template ImageSpecific() 13 | { 14 | /** 15 | * The image. 16 | */ 17 | private Image _image; 18 | 19 | /** 20 | * The active image. 21 | */ 22 | private Image _activeImage; 23 | 24 | /** 25 | * The disabled image. 26 | */ 27 | private Image _disabledImage; 28 | 29 | /** 30 | * Get the image. 31 | * 32 | * Returns: 33 | * The image; 34 | */ 35 | public Image getImage() 36 | { 37 | return this._image; 38 | } 39 | 40 | /** 41 | * Set the image. 42 | * 43 | * Params: 44 | * image = The image. 45 | * 46 | * Returns: 47 | * This item to aid method chaining. 48 | * 49 | * See_Also: 50 | * $(LINK2 ../../../image/gif.html, tkd.image.gif) $(BR) 51 | * $(LINK2 ../../../image/image.html, tkd.image.image) $(BR) 52 | * $(LINK2 ../../../image/png.html, tkd.image.png) $(BR) 53 | */ 54 | public auto setImage(this T)(Image image) 55 | { 56 | this._image = image; 57 | 58 | if (this._parent && this._image) 59 | { 60 | this._tk.eval("%s itemconfigure %s -image %s", this._parent.id, this.id, this._image.id); 61 | } 62 | 63 | return cast(T) this; 64 | } 65 | 66 | /** 67 | * Get the active image. 68 | * 69 | * Returns: 70 | * The active image; 71 | */ 72 | public Image getActiveImage() 73 | { 74 | return this._activeImage; 75 | } 76 | 77 | /** 78 | * Set the active image. 79 | * 80 | * Params: 81 | * image = The active image. 82 | * 83 | * Returns: 84 | * This item to aid method chaining. 85 | * 86 | * See_Also: 87 | * $(LINK2 ../../../image/gif.html, tkd.image.gif) $(BR) 88 | * $(LINK2 ../../../image/image.html, tkd.image.image) $(BR) 89 | * $(LINK2 ../../../image/png.html, tkd.image.png) $(BR) 90 | */ 91 | public auto setActiveImage(this T)(Image image) 92 | { 93 | this._activeImage = image; 94 | 95 | if (this._parent && this._activeImage) 96 | { 97 | this._tk.eval("%s itemconfigure %s -activeimage %s", this._parent.id, this.id, this._activeImage.id); 98 | } 99 | 100 | return cast(T) this; 101 | } 102 | 103 | /** 104 | * Get the disabled image. 105 | * 106 | * Returns: 107 | * The disabled image; 108 | */ 109 | public Image getDisabledImage() 110 | { 111 | return this._disabledImage; 112 | } 113 | 114 | /** 115 | * Set the disabled image. 116 | * 117 | * Params: 118 | * image = The disabled image. 119 | * 120 | * Returns: 121 | * This item to aid method chaining. 122 | * 123 | * See_Also: 124 | * $(LINK2 ../../../image/gif.html, tkd.image.gif) $(BR) 125 | * $(LINK2 ../../../image/image.html, tkd.image.image) $(BR) 126 | * $(LINK2 ../../../image/png.html, tkd.image.png) $(BR) 127 | */ 128 | public auto setDisabledImage(this T)(Image image) 129 | { 130 | this._disabledImage = image; 131 | 132 | if (this._parent && this._disabledImage) 133 | { 134 | this._tk.eval("%s itemconfigure %s -disabledimage %s", this._parent.id, this.id, this._disabledImage.id); 135 | } 136 | 137 | return cast(T) this; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /source/tkd/widget/menubutton.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.menubutton; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import tkd.element.uielement; 13 | import tkd.widget.menu.menu; 14 | import tkd.widget.textwidget; 15 | 16 | /** 17 | * A menu button widget displays a textual label and/or image, and displays a 18 | * menu when pressed. 19 | * 20 | * Example: 21 | * --- 22 | * auto menu = new Menu() 23 | * .addEntry("Entry 1", delegate(CommandArgs args){ ... }) 24 | * .addEntry("Entry 2", delegate(CommandArgs args){ ... }); 25 | * 26 | * auto menuButton = new MenuButton("Text", menu) 27 | * .pack(); 28 | * --- 29 | * 30 | * Additional_Events: 31 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 32 | * $(P 33 | * <<Invoke>>, 34 | * <<PrevWindow>>, 35 | * <Alt-Key>, 36 | * <B1-Leave>, 37 | * <Button-1>, 38 | * <ButtonRelease-1>, 39 | * <Enter>, 40 | * <Key-F10>, 41 | * <Key-Tab>, 42 | * <Key-space>, 43 | * <Leave>, 44 | * ) 45 | * 46 | * Styles: 47 | * Menu button widgets support the Toolbutton style in all standard 48 | * themes, which is useful for creating widgets for toolbars. 49 | * 50 | * See_Also: 51 | * $(LINK2 ./textwidget.html, tkd.widget.textwidget) 52 | */ 53 | class MenuButton : TextWidget 54 | { 55 | /** 56 | * Construct the widget. 57 | * 58 | * Params: 59 | * parent = The parent of this widget. 60 | * text = The text of the label. 61 | * menu = The menu that is invoked when this button is pressed. 62 | * direction = Determines where the menu appears in relation to the button. 63 | * 64 | * See_Also: 65 | * $(LINK2 ../element/uielement.html, tkd.element.uielement) $(BR) 66 | * $(LINK2 ./menubutton.html#MenuButtonDirection, tkd.widget.menubutton.MenuButtonDirection) $(BR) 67 | */ 68 | this(UiElement parent, string text, Menu menu, string direction = MenuButtonDirection.below) 69 | { 70 | super(parent); 71 | this._elementId = "menubutton"; 72 | 73 | this._tk.eval("ttk::menubutton %s -textvariable %s -menu %s -direction %s", this.id, this._textVariable, menu.id, direction); 74 | 75 | this.setText(text); 76 | } 77 | 78 | /** 79 | * Construct the widget. 80 | * 81 | * Params: 82 | * text = The text of the label. 83 | * menu = The menu that is invoked when this button is pressed. 84 | * direction = Determines where the menu appears in relation to the button. 85 | * 86 | * See_Also: 87 | * $(LINK2 ./menubutton.html#MenuButtonDirection, tkd.widget.menubutton.MenuButtonDirection) $(BR) 88 | */ 89 | this(string text, Menu menu, string direction = MenuButtonDirection.below) 90 | { 91 | this(null, text, menu, direction); 92 | } 93 | } 94 | 95 | /** 96 | * Placement of a menu relative to a menu button. 97 | */ 98 | enum MenuButtonDirection : string 99 | { 100 | above = "above", /// Above the menu button. 101 | below = "below", /// Below the menu button. 102 | flush = "flush", /// Directly over the menu button. 103 | left = "left", /// Left of the menu button. 104 | right = "right", /// Right of the menu button. 105 | } 106 | -------------------------------------------------------------------------------- /source/tkd/window/dialog/directorydialog.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Dialog module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.window.dialog.directorydialog; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.regex; 13 | import tkd.window.dialog.dialog; 14 | import tkd.window.window; 15 | 16 | /** 17 | * Pops up a dialog box for the user to select a directory. 18 | * 19 | * Example: 20 | * --- 21 | * auto dialog = new DirectoryDialog("Select a directory") 22 | * .setInitialDirectory("~") 23 | * .setDirectoryMustExist(true) 24 | * .show(); 25 | * 26 | * string directory = dialog.getResult(); 27 | * --- 28 | * 29 | * Result: 30 | * The full path of the directory selected. 31 | * 32 | * See_Also: 33 | * $(LINK2 ./dialog.html, tkd.dialog.dialog) $(BR) 34 | */ 35 | class DirectoryDialog : Dialog 36 | { 37 | /** 38 | * The initial directory to start in the dialog. 39 | */ 40 | private string _initialDirectory; 41 | 42 | /** 43 | * Whether or not the choosen directory must exist in the file system. 44 | */ 45 | private bool _directoryMustExist; 46 | 47 | /** 48 | * Construct the dialog. 49 | * 50 | * Params: 51 | * parent = The parent window of the dialog. 52 | * title = The title of the dialog. 53 | */ 54 | this(Window parent, string title = "Directory") 55 | { 56 | super(parent, title); 57 | 58 | // Fix to hide hidden files by default on Posix systems. This also 59 | // enables a checkbutton to show them again within the dialog. 60 | version (Posix) 61 | { 62 | this._tk.eval("catch {tk_getOpenFile foo bar}"); 63 | this._tk.eval("set ::tk::dialog::file::showHiddenVar 0"); 64 | this._tk.eval("set ::tk::dialog::file::showHiddenBtn 1"); 65 | } 66 | } 67 | 68 | /** 69 | * Construct the dialog. 70 | * 71 | * Params: 72 | * title = The title of the dialog. 73 | */ 74 | this(string title = "Directory") 75 | { 76 | this(null, title); 77 | } 78 | 79 | /** 80 | * Set the initial directory in the dialog. 81 | * 82 | * Params: 83 | * directory = The initial directory. 84 | * 85 | * Returns: 86 | * This dialog to aid method chaining. 87 | */ 88 | public auto setInitialDirectory(this T)(string directory) 89 | { 90 | this._initialDirectory = directory; 91 | 92 | return cast(T) this; 93 | } 94 | 95 | /** 96 | * Set if the directory must exist. 97 | * 98 | * Params: 99 | * mustExist = Determins if the directory must exist. 100 | * 101 | * Returns: 102 | * This dialog to aid method chaining. 103 | */ 104 | public auto setDirectoryMustExist(this T)(bool mustExist) 105 | { 106 | this._directoryMustExist = mustExist; 107 | 108 | return cast(T) this; 109 | } 110 | 111 | /** 112 | * Show the dialog. 113 | * 114 | * Returns: 115 | * This dialog to aid method chaining. 116 | */ 117 | public auto show(this T)() 118 | { 119 | if (this._parent) 120 | { 121 | this._tk.eval("tk_chooseDirectory -parent %s -title {%s} -initialdir {%s} -mustexist %s", this._parent.id, this._title, this._initialDirectory, this._directoryMustExist); 122 | } 123 | else 124 | { 125 | this._tk.eval("tk_chooseDirectory -title {%s} -initialdir {%s} -mustexist %s", this._title, this._initialDirectory, this._directoryMustExist); 126 | } 127 | 128 | string result = this._tk.getResult!(string); 129 | 130 | if (match(result, r"^bad window path name").empty) 131 | { 132 | this._results = [result]; 133 | } 134 | 135 | return cast(T) this; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /source/tkd/window/dialog/savefiledialog.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Dialog module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.window.dialog.savefiledialog; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.array; 13 | import std.regex; 14 | import tkd.window.dialog.filedialog; 15 | import tkd.window.window; 16 | 17 | /** 18 | * Pops up a dialog box for the user to save a file. 19 | * 20 | * Example: 21 | * --- 22 | * auto dialog = new SaveFileDialog("Save a file") 23 | * .setConfirmOverwrite(true) 24 | * .setDefaultExtension(".txt") 25 | * .addFileType("{{All files} {*}}") 26 | * .addFileType("{{Text files} {.txt}}") 27 | * .setInitialDirectory("~") 28 | * .setInitialFile("file.txt") 29 | * .show(); 30 | * 31 | * string fileToWrite = dialog.getResult(); 32 | * --- 33 | * 34 | * Result: 35 | * The full path of the file selected. 36 | * 37 | * See_Also: 38 | * $(LINK2 ./filedialog.html, tkd.dialog.filedialog) $(BR) 39 | */ 40 | class SaveFileDialog : FileDialog 41 | { 42 | /* 43 | * Configures how the Save dialog reacts when the selected file already 44 | * exists, and saving would overwrite it. 45 | */ 46 | private bool _confirmOverwrite = true; 47 | 48 | /** 49 | * Construct the dialog. 50 | * 51 | * Params: 52 | * parent = The parent window of the dialog. 53 | * title = The title of the dialog. 54 | */ 55 | this(Window parent, string title = "Save") 56 | { 57 | super(parent, title); 58 | } 59 | 60 | /** 61 | * Construct the dialog. 62 | * 63 | * Params: 64 | * title = The title of the dialog. 65 | */ 66 | this(string title = "Save") 67 | { 68 | this(null, title); 69 | } 70 | 71 | /** 72 | * Configures how the Save dialog reacts when the selected file already 73 | * exists, and saving would overwrite it. A true value requests a 74 | * confirmation dialog be presented to the user. A false value requests 75 | * that the overwrite take place without confirmation. Default value is 76 | * true. 77 | * 78 | * Params: 79 | * confirm = Show a dialog to confirm overwriting any file. 80 | * 81 | * Returns: 82 | * This dialog to aid method chaining. 83 | */ 84 | public auto setConfirmOverwrite(this T)(bool confirm) 85 | { 86 | this._confirmOverwrite = confirm; 87 | 88 | return cast(T) this; 89 | } 90 | 91 | /** 92 | * Show the dialog. 93 | * 94 | * Returns: 95 | * This dialog to aid method chaining. 96 | */ 97 | public auto show(this T)() 98 | { 99 | if (this._parent) 100 | { 101 | // String concatentation is used here to avoid the character escaping done on args. 102 | this._tk.eval("tk_getSaveFile -parent %s -title {%s} -confirmoverwrite %s -defaultextension {%s} -filetypes {" ~ this._fileTypes.join(" ") ~ "} -initialdir {%s} -initialfile {%s} -typevariable %s", this._parent.id, this._title, this._confirmOverwrite, this._defaultExtension, this._initialDirectory, this._initialFile, this._typeVariable); 103 | } 104 | else 105 | { 106 | // String concatentation is used here to avoid the character escaping done on args. 107 | this._tk.eval("tk_getSaveFile -title {%s} -confirmoverwrite %s -defaultextension {%s} -filetypes {" ~ this._fileTypes.join(" ") ~ "} -initialdir {%s} -initialfile {%s} -typevariable %s", this._title, this._confirmOverwrite, this._defaultExtension, this._initialDirectory, this._initialFile, this._typeVariable); 108 | } 109 | 110 | string result = this._tk.getResult!(string); 111 | 112 | if (match(result, r"^bad window path name").empty) 113 | { 114 | this._results = [result]; 115 | } 116 | 117 | return cast(T) this; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /source/tkd/widget/labelframe.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.labelframe; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.conv; 13 | import tkd.element.uielement; 14 | import tkd.widget.common.anchor; 15 | import tkd.widget.common.height; 16 | import tkd.widget.common.padding; 17 | import tkd.widget.common.text; 18 | import tkd.widget.common.underline; 19 | import tkd.widget.common.width; 20 | import tkd.widget.widget; 21 | 22 | /** 23 | * A label frame widget is a container used to group other widgets together. It 24 | * has an optional label, which may be a plain text string or another widget. 25 | * 26 | * Example: 27 | * --- 28 | * auto labelFrame = new LabelFrame("Text") 29 | * .pack(0, 10); 30 | * 31 | * // Add a button to the label frame. 32 | * auto button = new Button(labelFrame, "Text") 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/anchor.html, Anchor) $(BR) 40 | * $(LINK2 ./common/height.html, Height) $(BR) 41 | * $(LINK2 ./common/padding.html, Padding) $(BR) 42 | * $(LINK2 ./common/text.html, Text) $(BR) 43 | * $(LINK2 ./common/underline.html, Underline) $(BR) 44 | * $(LINK2 ./common/width.html, Width) $(BR) 45 | * ) 46 | * 47 | * Additional_Events: 48 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 49 | * $(P 50 | * <<Invoke>>, 51 | * <<PrevWindow>>, 52 | * <Alt-Key>, 53 | * <Key-F10>, 54 | * <Key-Tab>, 55 | * ) 56 | * 57 | * See_Also: 58 | * $(LINK2 ./widget.html, tkd.widget.widget) 59 | */ 60 | class LabelFrame : Widget 61 | { 62 | /** 63 | * Construct the widget. 64 | * 65 | * Params: 66 | * parent = The parent of this widget. 67 | * text = The text of the widget. 68 | * 69 | * See_Also: 70 | * $(LINK2 ../element/uielement.html, tkd.element.UiElement) $(BR) 71 | */ 72 | public this(UiElement parent, string text) 73 | { 74 | super(parent); 75 | this._elementId = "labelframe"; 76 | 77 | // String concatenation is used to build the script here instead of 78 | // using format specifiers to enable supporting input which includes 79 | // Tcl/Tk reserved characters and elements that could be construed as 80 | // format specifiers. 81 | string script = std.conv.text(`ttk::labelframe `, this.id, ` -text `, `"`, this._tk.escape(text), `"`); 82 | this._tk.eval(script); 83 | } 84 | 85 | /** 86 | * Construct the widget. 87 | * 88 | * Params: 89 | * text = The text of the widget. 90 | */ 91 | public this(string text) 92 | { 93 | this(null, text); 94 | } 95 | 96 | /** 97 | * Set a widget to use for the label. The widget must be a child of the 98 | * labelframe widget or one of the labelframe's ancestors, and must belong 99 | * to the same top-level widget as the labelframe. If set, overrides the 100 | * text parameter. 101 | * 102 | * Params: 103 | * widget = The widget to use as the label. 104 | * 105 | * Returns: 106 | * This widget to aid method chaining. 107 | */ 108 | public auto setLabel(this T)(Widget widget) 109 | { 110 | this._tk.eval("%s configure -labelwidget %s", this.id, widget.id); 111 | 112 | return cast(T) this; 113 | } 114 | 115 | /** 116 | * Mixin common commands. 117 | */ 118 | mixin Anchor!("-labelanchor"); 119 | mixin Height; 120 | mixin Padding; 121 | mixin Text; 122 | mixin Underline; 123 | mixin Width; 124 | } 125 | -------------------------------------------------------------------------------- /source/tkd/widget/scale.d: -------------------------------------------------------------------------------- 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 | } 125 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/widgetspecific.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget specific module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.canvas.widgetspecific; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template WidgetSpecific() 13 | { 14 | import std.typecons : Nullable; 15 | 16 | /** 17 | * The widget to use. 18 | */ 19 | private Widget _widget; 20 | 21 | /** 22 | * The widget width. 23 | */ 24 | private Nullable!(int) _width; 25 | 26 | /** 27 | * The widget height. 28 | */ 29 | private Nullable!(int) _height; 30 | 31 | /** 32 | * Get the widget. 33 | * 34 | * Returns: 35 | * The widget. 36 | */ 37 | public Widget getWidget() 38 | { 39 | return this._widget; 40 | } 41 | 42 | /** 43 | * Specifies the widget to associate with this item. The widget specified 44 | * must either be a child of the canvas widget or a child of some ancestor 45 | * of the canvas widget. 46 | * 47 | * Params: 48 | * widget = The widget. 49 | * 50 | * Returns: 51 | * This item to aid method chaining. 52 | */ 53 | public auto setWidget(this T)(Widget widget) 54 | { 55 | this._widget = widget; 56 | 57 | if (this._parent && this._widget) 58 | { 59 | this._tk.eval("%s itemconfigure %s -window %s", this._parent.id, this.id, this._widget.id); 60 | } 61 | 62 | return cast(T) this; 63 | } 64 | 65 | /** 66 | * Get the widget width. 67 | * 68 | * Returns: 69 | * The widget width. 70 | */ 71 | public int getWidth() 72 | { 73 | if (this._parent) 74 | { 75 | this._tk.eval("%s itemcget %s -width", this._parent.id, this.id); 76 | this._width = this._tk.getResult!(int); 77 | } 78 | 79 | return this._width.isNull ? 0 : this._width.get; 80 | } 81 | 82 | /** 83 | * Specifies the width to assign to the item's widget. If this option is 84 | * not specified, or if it is specified as zero, then the widget is given 85 | * whatever width it requests internally. 86 | * 87 | * Params: 88 | * width = The widget width. 89 | * 90 | * Returns: 91 | * This item to aid method chaining. 92 | */ 93 | public auto setWidth(this T, W)(W width) if (is(W == int) || is(W == Nullable!(int))) 94 | { 95 | static if (is(W == Nullable!(int))) 96 | { 97 | if (width.isNull) 98 | { 99 | return cast(T) this; 100 | } 101 | } 102 | 103 | this._width = width; 104 | 105 | if (this._parent) 106 | { 107 | this._tk.eval("%s itemconfigure %s -width %s", this._parent.id, this.id, this._width); 108 | } 109 | 110 | return cast(T) this; 111 | } 112 | 113 | /** 114 | * Get the widget height. 115 | * 116 | * Returns: 117 | * The widget height. 118 | */ 119 | public int getHeight() 120 | { 121 | if (this._parent) 122 | { 123 | this._tk.eval("%s itemcget %s -height", this._parent.id, this.id); 124 | this._height = this._tk.getResult!(int); 125 | } 126 | 127 | return this._height.isNull ? 0 : this._height.get; 128 | } 129 | 130 | /** 131 | * Specifies the height to assign to the item's widget. If this option is 132 | * not specified, or if it is specified as zero, then the widget is given 133 | * whatever height it requests internally. 134 | * 135 | * Params: 136 | * height = The widget height. 137 | * 138 | * Returns: 139 | * This item to aid method chaining. 140 | */ 141 | public auto setHeight(this T, H)(H height) if (is(H == int) || is(H == Nullable!(int))) 142 | { 143 | static if (is(H == Nullable!(int))) 144 | { 145 | if (height.isNull) 146 | { 147 | return cast(T) this; 148 | } 149 | } 150 | 151 | this._height = height; 152 | 153 | if (this._parent) 154 | { 155 | this._tk.eval("%s itemconfigure %s -height %s", this._parent.id, this.id, this._height); 156 | } 157 | 158 | return cast(T) this; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /source/tkd/window/dialog/openfiledialog.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Dialog module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.window.dialog.openfiledialog; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.array; 13 | import std.regex; 14 | import tkd.window.dialog.filedialog; 15 | import tkd.window.window; 16 | 17 | /** 18 | * Pops up a dialog box for the user to open a file. 19 | * 20 | * Example: 21 | * --- 22 | * auto dialog = new OpenFileDialog("Open a file") 23 | * .setMultiSelection(false) 24 | * .setDefaultExtension(".txt") 25 | * .addFileType("{{All files} {*}}") 26 | * .addFileType("{{Text files} {.txt}}") 27 | * .setInitialDirectory("~") 28 | * .setInitialFile("file.txt") 29 | * .show(); 30 | * 31 | * string fileToOpen = dialog.getResult(); 32 | * --- 33 | * 34 | * Result: 35 | * The full path of the file selected. 36 | * 37 | * See_Also: 38 | * $(LINK2 ./filedialog.html, tkd.dialog.filedialog) $(BR) 39 | */ 40 | class OpenFileDialog : FileDialog 41 | { 42 | /* 43 | * Allows the user to choose multiple files from the Open dialog. 44 | */ 45 | protected bool _selectMultiple; 46 | 47 | /** 48 | * Construct the dialog. 49 | * 50 | * Params: 51 | * parent = The parent window of the dialog. 52 | * title = The title of the dialog. 53 | */ 54 | this(Window parent, string title = "Open") 55 | { 56 | super(parent, title); 57 | } 58 | 59 | /** 60 | * Construct the dialog. 61 | * 62 | * Params: 63 | * title = The title of the dialog. 64 | */ 65 | this(string title = "Open") 66 | { 67 | this(null, title); 68 | } 69 | 70 | /** 71 | * Set whether to enable mutli-selection. 72 | * 73 | * Params: 74 | * enable = Enables multi-selections. 75 | * 76 | * Returns: 77 | * This dialog to aid method chaining. 78 | */ 79 | public auto setMultiSelection(this T)(bool enable) 80 | { 81 | this._selectMultiple = enable; 82 | 83 | return cast(T) this; 84 | } 85 | 86 | /** 87 | * Show the dialog. 88 | * 89 | * Returns: 90 | * This dialog to aid method chaining. 91 | */ 92 | public auto show(this T)() 93 | { 94 | if (this._parent) 95 | { 96 | // String concatentation is used here to avoid the character escaping done on args. 97 | this._tk.eval("tk_getOpenFile -parent %s -title {%s} -multiple %s -defaultextension {%s} -filetypes {" ~ this._fileTypes.join(" ") ~ "} -initialdir {%s} -initialfile {%s} -typevariable %s", this._parent.id, this._title, this._selectMultiple, this._defaultExtension, this._initialDirectory, this._initialFile, this._typeVariable); 98 | } 99 | else 100 | { 101 | // String concatentation is used here to avoid the character escaping done on args. 102 | this._tk.eval("tk_getOpenFile -title {%s} -multiple %s -defaultextension {%s} -filetypes {" ~ this._fileTypes.join(" ") ~ "} -initialdir {%s} -initialfile {%s} -typevariable %s", this._title, this._selectMultiple, this._defaultExtension, this._initialDirectory, this._initialFile, this._typeVariable); 103 | } 104 | 105 | string result = this._tk.getResult!(string); 106 | 107 | if (match(result, r"^bad window path name").empty) 108 | { 109 | if (this._selectMultiple) 110 | { 111 | auto regexResult = matchAll(result, r"\{.*?\}"); 112 | result = result.replaceAll(regex(r"\{.*?\}"), ""); 113 | this._results ~= result.split(); 114 | 115 | foreach (match; regexResult) 116 | { 117 | this._results ~= match.hit; 118 | } 119 | 120 | this.removeBracesFromResults; 121 | } 122 | else 123 | { 124 | this._results = [result]; 125 | } 126 | } 127 | 128 | return cast(T) this; 129 | } 130 | 131 | /** 132 | * Get multiple dialog results. 133 | * 134 | * Returns: 135 | * The multiple results of the dialog. 136 | */ 137 | public string[] getResults() 138 | { 139 | assert(this._selectMultiple, "You need to set multi-selection on to retrieve more than one result."); 140 | 141 | return this._results; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/bind.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Bind module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.canvas.bind; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Bind() 13 | { 14 | import std.regex : match; 15 | 16 | /** 17 | * The bindings. 18 | */ 19 | private CommandCallback[string] _bindings; 20 | 21 | /** 22 | * Bind a callback to a particular event triggered by this item. 23 | * This command is identical to $(LINK2 24 | * ../../../element/uielement.html#UiElement, UiElement)'s bind method. 25 | * 26 | * If bindings have been created for a canvas widget they are invoked in 27 | * addition to bindings created for the canvas's items. The bindings for 28 | * items will be invoked before any of the bindings for the window as a 29 | * whole. 30 | * 31 | * Params: 32 | * binding = The binding that triggers this event. See below. 33 | * callback = The delegate callback to execute when the event triggers. 34 | * 35 | * Returns: 36 | * This item to aid method chaining. 37 | * 38 | * Bindings: 39 | * The only events for which bindings may be specified are those 40 | * related to the mouse and keyboard (such as Enter, Leave, 41 | * ButtonPress, Motion, and KeyPress) or virtual events. 42 | * 43 | * Callback_Arguments: 44 | * These are the fields within the callback's $(LINK2 45 | * ../../../element/element.html#CommandArgs, CommandArgs) parameter which 46 | * are populated by this method when the callback is executed. 47 | * $(P 48 | * $(PARAM_TABLE 49 | * $(PARAM_ROW CommandArgs.element, The item that executed the callback.) 50 | * $(PARAM_ROW CommandArgs.uniqueData, The binding that was responded to.) 51 | * $(PARAM_ROW CommandArgs.callback, The callback which was executed.) 52 | * $(PARAM_ROW CommandArgs.event.button, The number of any button that was pressed.) 53 | * $(PARAM_ROW CommandArgs.event.keyCode, The key code of any key pressed.) 54 | * $(PARAM_ROW CommandArgs.event.x, The horizontal position of the mouse relative to the widget.) 55 | * $(PARAM_ROW CommandArgs.event.y, The vertical position of the mouse relative to the widget.) 56 | * $(PARAM_ROW CommandArgs.event.wheel, Mouse wheel delta.) 57 | * $(PARAM_ROW CommandArgs.event.key, Key symbol of any key pressed.) 58 | * $(PARAM_ROW CommandArgs.event.screenX, The horizontal position of the mouse relative to the screen.) 59 | * $(PARAM_ROW CommandArgs.event.screenY, The vertical position of the mouse relative to the screen.) 60 | * ) 61 | * ) 62 | * 63 | * See_Also: 64 | * $(LINK2 ../../../element/element.html#CommandCallback, tkd.element.element.CommandCallback) $(BR) 65 | * $(LINK2 ../../../element/uielement.html#UiElement, tkd.element.uielement.UiElement) $(BR) 66 | */ 67 | public auto bind(this T)(string binding, CommandCallback callback) 68 | { 69 | assert(!match(binding, r"^<.*?>$").empty, "Binding must take the form of "); 70 | 71 | this._bindings[binding] = callback; 72 | 73 | if (this._parent) 74 | { 75 | string command = this.createCommand(callback, binding); 76 | this._tk.eval("%s bind %s {%s} {%s %%b %%k %%x %%y %%D %%K %%X %%Y}", this._parent.id, this.id, binding, command); 77 | } 78 | 79 | return cast(T) this; 80 | } 81 | 82 | /** 83 | * Unbind a previous event binding. 84 | * 85 | * Params: 86 | * binding = The binding to remove. 87 | * 88 | * Returns: 89 | * This item to aid method chaining. 90 | */ 91 | public auto unbind(this T)(string binding) 92 | { 93 | this._bindings.remove(binding); 94 | 95 | if (this._parent) 96 | { 97 | this._tk.deleteCommand(this.getCommandName(binding)); 98 | this._tk.eval("%s bind %s {%s} {}", this._parent.id, this.id, binding); 99 | } 100 | 101 | return cast(T) this; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/fillcolor.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Fill color module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.canvas.fillcolor; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template FillColor() 13 | { 14 | /** 15 | * The fill color. 16 | */ 17 | private string _fillColor; 18 | 19 | /** 20 | * The active fill color. 21 | */ 22 | private string _activeFillColor; 23 | 24 | /** 25 | * The disabled fill color. 26 | */ 27 | private string _disabledFillColor; 28 | 29 | /** 30 | * Get the fill color. 31 | * 32 | * Returns: 33 | * The fill color; 34 | */ 35 | public string getFillColor() 36 | { 37 | if (this._parent) 38 | { 39 | this._tk.eval("%s itemcget %s -fill", this._parent.id, this.id); 40 | this._fillColor = this._tk.getResult!(string); 41 | } 42 | 43 | return this._fillColor; 44 | } 45 | 46 | /** 47 | * Set the fill color. 48 | * Use colors from the preset color $(LINK2 ../../../element/color.html, list) or a web style hex color. 49 | * 50 | * Params: 51 | * color = The fill color. 52 | * 53 | * Returns: 54 | * This widget to aid method chaining. 55 | * 56 | * See_Also: 57 | * $(LINK2 ../../../element/color.html, tkd.widget.color) $(BR) 58 | */ 59 | public auto setFillColor(this T)(string color) 60 | { 61 | this._fillColor = color; 62 | 63 | if (this._parent && this._fillColor.length) 64 | { 65 | this._tk.eval("%s itemconfigure %s -fill {%s}", this._parent.id, this.id, this._fillColor); 66 | } 67 | 68 | return cast(T) this; 69 | } 70 | 71 | /** 72 | * Get the active fill color. 73 | * An item's active state is triggered when the mouse rolls over the item. 74 | * 75 | * Returns: 76 | * The active fill color; 77 | */ 78 | public string getActiveFillColor() 79 | { 80 | if (this._parent) 81 | { 82 | this._tk.eval("%s itemcget %s -activefill", this._parent.id, this.id); 83 | this._activeFillColor = this._tk.getResult!(string); 84 | } 85 | 86 | return this._activeFillColor; 87 | } 88 | 89 | /** 90 | * Set the active fill color. 91 | * An item's active state is triggered when the mouse rolls over the item. 92 | * Use colors from the preset color $(LINK2 ../../../element/color.html, list) or a web style hex color. 93 | * 94 | * Params: 95 | * color = The fill color. 96 | * 97 | * Returns: 98 | * This widget to aid method chaining. 99 | * 100 | * See_Also: 101 | * $(LINK2 ../../../element/color.html, tkd.widget.color) $(BR) 102 | */ 103 | public auto setActiveFillColor(this T)(string color) 104 | { 105 | this._activeFillColor = color; 106 | 107 | if (this._parent && this._activeFillColor.length) 108 | { 109 | this._tk.eval("%s itemconfigure %s -activefill {%s}", this._parent.id, this.id, this._activeFillColor); 110 | } 111 | 112 | return cast(T) this; 113 | } 114 | 115 | /** 116 | * Get the disabled fill color. 117 | * 118 | * Returns: 119 | * The disabled fill color; 120 | */ 121 | public string getDisabledFillColor() 122 | { 123 | if (this._parent) 124 | { 125 | this._tk.eval("%s itemcget %s -disabledfill", this._parent.id, this.id); 126 | this._disabledFillColor = this._tk.getResult!(string); 127 | } 128 | 129 | return this._disabledFillColor; 130 | } 131 | 132 | /** 133 | * Set the disabled fill color. 134 | * Use colors from the preset color $(LINK2 ../../../element/color.html, list) or a web style hex color. 135 | * 136 | * Params: 137 | * color = The fill color. 138 | * 139 | * Returns: 140 | * This widget to aid method chaining. 141 | * 142 | * See_Also: 143 | * $(LINK2 ../../../element/color.html, tkd.widget.color) $(BR) 144 | */ 145 | public auto setDisabledFillColor(this T)(string color) 146 | { 147 | this._disabledFillColor = color; 148 | 149 | if (this._parent && this._disabledFillColor.length) 150 | { 151 | this._tk.eval("%s itemconfigure %s -disabledfill {%s}", this._parent.id, this.id, this._disabledFillColor); 152 | } 153 | 154 | return cast(T) this; 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /source/tkd/interpreter/logger.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Logger module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.interpreter.logger; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.datetime; 13 | import std.process; 14 | import std.stdio; 15 | import std.string; 16 | 17 | /** 18 | * A simple class to provide logging support. 19 | */ 20 | class Logger 21 | { 22 | /** 23 | * Level of importance of the text to write to the logger. 24 | */ 25 | private enum Level 26 | { 27 | /** 28 | * The eval level is for evaluated commands. 29 | */ 30 | eval, 31 | 32 | /** 33 | * The information level used for info messages. 34 | */ 35 | information, 36 | 37 | /** 38 | * The warning level used for warning messages. 39 | */ 40 | warning, 41 | 42 | /** 43 | * The error level used for error messages. 44 | */ 45 | error, 46 | } 47 | 48 | /** 49 | * The open log file. 50 | */ 51 | private File _log; 52 | 53 | /** 54 | * Constructor. 55 | * 56 | * If a log file is not passed, log instead to stdout. 57 | * 58 | * Params: 59 | * logFile = The log file for logging. 60 | */ 61 | final public this(string logFile = null) nothrow 62 | { 63 | try 64 | { 65 | if (logFile is null) 66 | { 67 | this._log = stdout; 68 | } 69 | else 70 | { 71 | this._log = File(logFile, "w"); 72 | } 73 | } 74 | catch (Exception ex) 75 | { 76 | assert(false, ex.msg); 77 | } 78 | } 79 | 80 | /** 81 | * Get the current timestamp for the log. 82 | * 83 | * Returns: 84 | * The current timestamp. 85 | */ 86 | final private string getTimestamp() nothrow 87 | { 88 | try 89 | { 90 | auto time = Clock.currTime(); 91 | return format("%d/%02d/%02d %d:%02d:%02d", time.year, time.month, time.day, time.hour, time.minute, time.second); 92 | } 93 | catch (Exception ex) 94 | { 95 | assert(false, ex.msg); 96 | } 97 | } 98 | 99 | /** 100 | * Write text to the log. 101 | * 102 | * Params: 103 | * text = The text to write to the log. 104 | * level = The level of the text. 105 | */ 106 | final private void log(A...)(Level level, string text, A args) nothrow 107 | { 108 | string levelText; 109 | 110 | switch(level) 111 | { 112 | case Level.eval: 113 | levelText = "EVAL"; 114 | break; 115 | 116 | case Level.warning: 117 | levelText = "WARN"; 118 | break; 119 | 120 | case Level.error: 121 | levelText = "ERROR"; 122 | break; 123 | 124 | default: 125 | levelText = "INFO"; 126 | break; 127 | } 128 | 129 | try 130 | { 131 | static if (A.length) 132 | { 133 | text = format(text, args); 134 | } 135 | 136 | this._log.writefln("%s %s: %s", this.getTimestamp(), levelText, text); 137 | this._log.flush(); 138 | } 139 | catch (Exception ex) 140 | { 141 | assert(false, ex.msg); 142 | } 143 | } 144 | 145 | /** 146 | * Write eval text to the log. 147 | * 148 | * Params: 149 | * text = The format of the text to write to the log. 150 | * args = The arguments that the format defines (if any). 151 | */ 152 | final public void eval(A...)(string text, A args) nothrow 153 | { 154 | this.log(Level.eval, text, args); 155 | } 156 | 157 | /** 158 | * Write info text to the log. 159 | * 160 | * Params: 161 | * text = The format of the text to write to the log. 162 | * args = The arguments that the format defines (if any). 163 | */ 164 | final public void info(A...)(string text, A args) nothrow 165 | { 166 | this.log(Level.information, text, args); 167 | } 168 | 169 | /** 170 | * Write warning text to the log. 171 | * 172 | * Params: 173 | * text = The format of the text to write to the log. 174 | * args = The arguments that the format defines (if any). 175 | */ 176 | final public void warning(A...)(string text, A args) nothrow 177 | { 178 | this.log(Level.warning, text, args); 179 | } 180 | 181 | /** 182 | * Write error text to the log. 183 | * 184 | * Params: 185 | * text = The format of the text to write to the log. 186 | * args = The arguments that the format defines (if any). 187 | */ 188 | final public void error(A...)(string text, A args) nothrow 189 | { 190 | this.log(Level.error, text, args); 191 | } 192 | 193 | } 194 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/outlinecolor.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Outline color module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.canvas.outlinecolor; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template OutlineColor() 13 | { 14 | /** 15 | * The outline color. 16 | */ 17 | private string _outlineColor; 18 | 19 | /** 20 | * The active outline color. 21 | */ 22 | private string _activeOutlineColor; 23 | 24 | /** 25 | * The disabled outline color. 26 | */ 27 | private string _disabledOutlineColor; 28 | 29 | /** 30 | * Get the outline color. 31 | * 32 | * Returns: 33 | * The outline color; 34 | */ 35 | public string getOutlineColor() 36 | { 37 | if (this._parent) 38 | { 39 | this._tk.eval("%s itemcget %s -outline", this._parent.id, this.id); 40 | this._outlineColor = this._tk.getResult!(string); 41 | } 42 | 43 | return this._outlineColor; 44 | } 45 | 46 | /** 47 | * Set the outline color. 48 | * Use colors from the preset color $(LINK2 ../../../element/color.html, list) or a web style hex color. 49 | * 50 | * Params: 51 | * color = The outline color. 52 | * 53 | * Returns: 54 | * This widget to aid method chaining. 55 | * 56 | * See_Also: 57 | * $(LINK2 ../../../element/color.html, tkd.widget.color) $(BR) 58 | */ 59 | public auto setOutlineColor(this T)(string color) 60 | { 61 | this._outlineColor = color; 62 | 63 | if (this._parent && this._outlineColor.length) 64 | { 65 | this._tk.eval("%s itemconfigure %s -outline {%s}", this._parent.id, this.id, this._outlineColor); 66 | } 67 | 68 | return cast(T) this; 69 | } 70 | 71 | /** 72 | * Get the active outline color. 73 | * An item's active state is triggered when the mouse rolls over the item. 74 | * 75 | * Returns: 76 | * The active outline color; 77 | */ 78 | public string getActiveOutlineColor() 79 | { 80 | if (this._parent) 81 | { 82 | this._tk.eval("%s itemcget %s -activeoutline", this._parent.id, this.id); 83 | this._activeOutlineColor = this._tk.getResult!(string); 84 | } 85 | 86 | return this._activeOutlineColor; 87 | } 88 | 89 | /** 90 | * Set the active outline color. 91 | * An item's active state is triggered when the mouse rolls over the item. 92 | * Use colors from the preset color $(LINK2 ../../../element/color.html, list) or a web style hex color. 93 | * 94 | * Params: 95 | * color = The outline color. 96 | * 97 | * Returns: 98 | * This widget to aid method chaining. 99 | * 100 | * See_Also: 101 | * $(LINK2 ../../../element/color.html, tkd.widget.color) $(BR) 102 | */ 103 | public auto setActiveOutlineColor(this T)(string color) 104 | { 105 | this._activeOutlineColor = color; 106 | 107 | if (this._parent && this._activeOutlineColor.length) 108 | { 109 | this._tk.eval("%s itemconfigure %s -activeoutline {%s}", this._parent.id, this.id, this._activeOutlineColor); 110 | } 111 | 112 | return cast(T) this; 113 | } 114 | 115 | /** 116 | * Get the disabled outline color. 117 | * 118 | * Returns: 119 | * The disabled outline color; 120 | */ 121 | public string getDisabledOutlineColor() 122 | { 123 | if (this._parent) 124 | { 125 | this._tk.eval("%s itemcget %s -disabledoutline", this._parent.id, this.id); 126 | this._disabledOutlineColor = this._tk.getResult!(string); 127 | } 128 | 129 | return this._disabledOutlineColor; 130 | } 131 | 132 | /** 133 | * Set the disabled outline color. 134 | * Use colors from the preset color $(LINK2 ../../../element/color.html, list) or a web style hex color. 135 | * 136 | * Params: 137 | * color = The outline color. 138 | * 139 | * Returns: 140 | * This widget to aid method chaining. 141 | * 142 | * See_Also: 143 | * $(LINK2 ../../../element/color.html, tkd.widget.color) $(BR) 144 | */ 145 | public auto setDisabledOutlineColor(this T)(string color) 146 | { 147 | this._disabledOutlineColor = color; 148 | 149 | if (this._parent && this._disabledOutlineColor.length) 150 | { 151 | this._tk.eval("%s itemconfigure %s -disabledoutline {%s}", this._parent.id, this.id, this._disabledOutlineColor); 152 | } 153 | 154 | return cast(T) this; 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/linespecific.d: -------------------------------------------------------------------------------- 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 | } 157 | -------------------------------------------------------------------------------- /source/tkd/widget/textwidget.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.textwidget; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.string; 13 | import tkd.element.uielement; 14 | import tkd.image.image; 15 | import tkd.image.imageposition; 16 | import tkd.widget.common.underline; 17 | import tkd.widget.widget; 18 | 19 | /** 20 | * The text widget base class. 21 | * 22 | * Common_Commands: 23 | * These are injected common commands that can also be used with this widget. 24 | * $(P 25 | * $(LINK2 ./common/underline.html, Underline) $(BR) 26 | * ) 27 | * 28 | * See_Also: 29 | * $(LINK2 ./widget.html, tkd.widget.widget) 30 | */ 31 | abstract class TextWidget : Widget 32 | { 33 | /* 34 | * The name of the text variable that contains the widget's text. 35 | */ 36 | protected string _textVariable; 37 | 38 | /* 39 | * The image of this widget. 40 | */ 41 | protected Image _image; 42 | 43 | /** 44 | * Construct the widget. 45 | * 46 | * Params: 47 | * parent = An optional parent of this widget. 48 | * 49 | * See_Also: 50 | * $(LINK2 ../element/uielement.html, tkd.element.uielement) 51 | */ 52 | public this(UiElement parent = null) 53 | { 54 | super(parent); 55 | 56 | this._elementId = "textwidget"; 57 | this._textVariable = format("variable-%s", this.generateHash(this.id)); 58 | } 59 | 60 | /** 61 | * Set the widget text. 62 | * 63 | * Params: 64 | * text = The widget text. 65 | * 66 | * Returns: 67 | * This widget to aid method chaining. 68 | */ 69 | public auto setText(this T)(string text) 70 | { 71 | this._tk.setVariable(this._textVariable, text); 72 | 73 | return cast(T) this; 74 | } 75 | 76 | /** 77 | * Get the widget text. 78 | * 79 | * Returns: 80 | * A string containing the widget text. 81 | */ 82 | public string getText() 83 | { 84 | return this._tk.getVariable(this._textVariable); 85 | } 86 | 87 | /** 88 | * Set the image for this widget. 89 | * 90 | * Params: 91 | * image = The image to set on the widget. 92 | * imagePosition = The position of the image relative to the text. 93 | * 94 | * Returns: 95 | * This widget to aid method chaining. 96 | * 97 | * See_Also: 98 | * $(LINK2 ../image/image.html, tkd.image.image) $(BR) 99 | * $(LINK2 ../image/png.html, tkd.image.png) $(BR) 100 | * $(LINK2 ../image/gif.html, tkd.image.gif) $(BR) 101 | * $(LINK2 ../image/imageposition.html, tkd.image.imageposition) $(BR) 102 | */ 103 | public auto setImage(this T)(Image image, string imagePosition = ImagePosition.image) 104 | { 105 | this._image = image; 106 | 107 | this._tk.eval("%s configure -image %s", this.id, this._image.id); 108 | this.setImagePosition(imagePosition); 109 | 110 | return cast(T) this; 111 | } 112 | 113 | /** 114 | * Change the position of the image in relation to the text. 115 | * 116 | * Params: 117 | * imagePosition = The position of the image relative to the text. 118 | * 119 | * Returns: 120 | * This widget to aid method chaining. 121 | * 122 | * See_Also: 123 | * $(LINK2 ../image/imageposition.html, tkd.image.imageposition) 124 | */ 125 | public auto setImagePosition(this T)(string imagePosition) 126 | { 127 | this._tk.eval("%s configure -compound %s", this.id, imagePosition); 128 | 129 | return cast(T) this; 130 | } 131 | 132 | /** 133 | * Set the text character width. 134 | * 135 | * Params: 136 | * characterWidth = The width of characters to set the label to. 137 | * 138 | * Returns: 139 | * This widget to aid method chaining. 140 | */ 141 | public auto setTextCharacterWidth(this T)(int characterWidth) 142 | { 143 | this._tk.eval("%s configure -width %s", this.id, characterWidth); 144 | 145 | return cast(T) this; 146 | } 147 | 148 | /** 149 | * Destroy this widget. 150 | * 151 | * Caveats: 152 | * Once a widget is destroyed it can no longer be referenced in your 153 | * code or a segmentation fault will occur and potentially crash your 154 | * program. 155 | */ 156 | override public void destroy() 157 | { 158 | this._tk.deleteVariable(this._textVariable); 159 | super.destroy(); 160 | } 161 | 162 | /** 163 | * Mixin common commands. 164 | */ 165 | mixin Underline; 166 | } 167 | -------------------------------------------------------------------------------- /source/tkd/window/dialog/filedialog.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Dialog module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.window.dialog.filedialog; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.regex; 13 | import std.string; 14 | import tkd.window.dialog.dialog; 15 | import tkd.window.window; 16 | 17 | /** 18 | * Pops up a dialog box for the user to select a color. 19 | * 20 | * See_Also: 21 | * $(LINK2 ./dialog.html, tkd.dialog.dialog) $(BR) 22 | */ 23 | abstract class FileDialog : Dialog 24 | { 25 | /* 26 | * The default extension for the file. 27 | */ 28 | protected string _defaultExtension; 29 | 30 | /* 31 | * A list of allowed file types. 32 | */ 33 | protected string[] _fileTypes; 34 | 35 | /* 36 | * The initial directory to start in the dialog. 37 | */ 38 | protected string _initialDirectory; 39 | 40 | /* 41 | * The initial file to use in the dialog. 42 | */ 43 | protected string _initialFile; 44 | 45 | /* 46 | * A variable to hold the state of the selected file type. 47 | */ 48 | protected string _typeVariable; 49 | 50 | /** 51 | * Construct the dialog. 52 | * 53 | * Params: 54 | * parent = The parent window of the dialog. 55 | * title = The title of the dialog. 56 | */ 57 | this(Window parent, string title) 58 | { 59 | this._typeVariable = format("variable-%s", this.generateHash("%s%s", this._elementId, this.id)); 60 | super(parent, title); 61 | 62 | // Fix to hide hidden files by default on Posix systems. This also 63 | // enables a checkbutton to show them again within the dialog. 64 | version (Posix) 65 | { 66 | this._tk.eval("catch {tk_getOpenFile foo bar}"); 67 | this._tk.eval("set ::tk::dialog::file::showHiddenVar 0"); 68 | this._tk.eval("set ::tk::dialog::file::showHiddenBtn 1"); 69 | } 70 | } 71 | 72 | /** 73 | * Construct the dialog. 74 | * 75 | * Params: 76 | * title = The title of the dialog. 77 | */ 78 | this(string title) 79 | { 80 | this(null, title); 81 | } 82 | 83 | /** 84 | * Set the default extension. 85 | * 86 | * Params: 87 | * extension = The default extension. 88 | * 89 | * Returns: 90 | * This dialog to aid method chaining. 91 | */ 92 | public auto setDefaultExtension(this T)(string extension) 93 | { 94 | this._defaultExtension = extension; 95 | 96 | return cast(T) this; 97 | } 98 | 99 | /** 100 | * Add an allowed file type. If a filetype combobox exists in the file 101 | * dialog on the particular platform, this adds entries to it. When the 102 | * user choose a filetype in the combobox, only the files of that type are 103 | * listed. If no types are added or if the filetypes combobox is not 104 | * supported by the particular platform then all files are listed 105 | * regardless of their types. 106 | * 107 | * Filetypes must be added in the correct format, i.e. all fields are 108 | * enclosed within curly braces and separated by a space. Extensions must 109 | * contain a dot. The format is described below in which the carats 110 | * indicate essential required space. 111 | * ---- 112 | * {{Description} {.ext1 .ext2 .ext3 ...}} 113 | * ^ ^ ^ ^ 114 | * ---- 115 | * 116 | * Params: 117 | * fileType = The file type to add. 118 | * 119 | * Returns: 120 | * This dialog to aid method chaining. 121 | */ 122 | public auto addFileType(this T)(string fileType) 123 | { 124 | assert(!std.regex.match(fileType, r"^\{\{.*?\} \{.*?\}\}$").empty, 125 | "File type must take the form of '{{Description} {.ext1 .ext2 .ext3 ...}}'. Braces and spaces are important!"); 126 | 127 | this._fileTypes ~= fileType; 128 | 129 | return cast(T) this; 130 | } 131 | 132 | /** 133 | * Set the initial directory in the dialog. 134 | * 135 | * Params: 136 | * directory = The initial directory. 137 | * 138 | * Returns: 139 | * This dialog to aid method chaining. 140 | */ 141 | public auto setInitialDirectory(this T)(string directory) 142 | { 143 | this._initialDirectory = directory; 144 | 145 | return cast(T) this; 146 | } 147 | 148 | /** 149 | * Set the initial file in the dialog. 150 | * 151 | * Params: 152 | * file = The initial file. 153 | * 154 | * Returns: 155 | * This dialog to aid method chaining. 156 | */ 157 | public auto setInitialFile(this T)(string file) 158 | { 159 | this._initialFile = file; 160 | 161 | return cast(T) this; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/outlinewidth.d: -------------------------------------------------------------------------------- 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 | } 175 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/arcspecific.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Arc specific module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.canvas.arcspecific; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template ArcSpecific() 13 | { 14 | import std.typecons : Nullable; 15 | 16 | /** 17 | * The style of the arc. 18 | */ 19 | private string _style; 20 | 21 | /** 22 | * The extent of the arc. 23 | */ 24 | private int _extent; 25 | 26 | /** 27 | * The start angle of the arc. 28 | */ 29 | private Nullable!(double) _startAngle; 30 | 31 | /** 32 | * Get the style of the arc. 33 | * 34 | * Returns: 35 | * The style of the arc; 36 | */ 37 | public string getStyle() 38 | { 39 | if (this._parent) 40 | { 41 | this._tk.eval("%s itemcget %s -style", this._parent.id, this.id); 42 | this._style = this._tk.getResult!(string); 43 | } 44 | 45 | return this._style; 46 | } 47 | 48 | /** 49 | * Specifies how to draw the arc. If type is pie (the default) then the 50 | * arc's region is defined by a section of the oval's perimeter plus two 51 | * line segments, one between the center of the oval and each end of the 52 | * perimeter section. If type is chord then the arc's region is defined by 53 | * a section of the oval's perimeter plus a single line segment connecting 54 | * the two end points of the perimeter section. If type is arc then the 55 | * arc's region consists of a section of the perimeter alone. In this last 56 | * case the fill color is ignored. 57 | * 58 | * Params: 59 | * style = The style of the arc. 60 | * 61 | * Returns: 62 | * This item to aid method chaining. 63 | * 64 | * See_Also: 65 | * $(LINK2 ../../canvas.html#CanvasArcStyle, tkd.widget.canvas.CanvasArcStyle) 66 | */ 67 | public auto setStyle(this T)(string style) 68 | { 69 | this._style = style; 70 | 71 | if (this._parent && this._style.length) 72 | { 73 | this._tk.eval("%s itemconfigure %s -style {%s}", this._parent.id, this.id, this._style); 74 | } 75 | 76 | return cast(T) this; 77 | } 78 | 79 | /** 80 | * Get the extent of the arc. 81 | * 82 | * Returns: 83 | * The extent of the arc; 84 | */ 85 | public int getExtent() 86 | { 87 | if (this._parent) 88 | { 89 | this._tk.eval("%s itemcget %s -extent", this._parent.id, this.id); 90 | this._extent = this._tk.getResult!(int); 91 | } 92 | 93 | return this._extent; 94 | } 95 | 96 | /** 97 | * Specifies the size of the angular range occupied by the arc. The arc's 98 | * range extends for degrees counter-clockwise from the starting angle. 99 | * Degrees may be negative. If it is greater than 360 or less than -360, 100 | * then degrees modulo 360 is used as the extent. 101 | * 102 | * Params: 103 | * extent = The extent of the arc. 104 | * 105 | * Returns: 106 | * This item to aid method chaining. 107 | */ 108 | public auto setExtent(this T)(int extent) 109 | { 110 | this._extent = extent; 111 | 112 | if (this._parent && this._extent > 0) 113 | { 114 | this._tk.eval("%s itemconfigure %s -extent %s", this._parent.id, this.id, this._extent); 115 | } 116 | 117 | return cast(T) this; 118 | } 119 | 120 | /** 121 | * Get the start angle of the arc. 122 | * 123 | * Returns: 124 | * The start angle of the arc; 125 | */ 126 | public double getStartAngle() 127 | { 128 | if (this._parent) 129 | { 130 | this._tk.eval("%s itemcget %s -start", this._parent.id, this.id); 131 | this._startAngle = this._tk.getResult!(double); 132 | } 133 | 134 | return this._startAngle.isNull ? 0.0 : this._startAngle.get; 135 | } 136 | 137 | /** 138 | * Specifies the beginning of the angular range occupied by the arc. 139 | * Degrees is given in units of degrees measured counter-clockwise from the 140 | * 3-o'clock position; it may be either positive or negative. 141 | * 142 | * Params: 143 | * startAngle = The start angle of the arc. 144 | * 145 | * Returns: 146 | * This item to aid method chaining. 147 | */ 148 | public auto setStartAngle(this T, A)(A startAngle) if (is(A == double) || is(A == Nullable!(double))) 149 | { 150 | static if (is(A == Nullable!(double))) 151 | { 152 | if (startAngle.isNull) 153 | { 154 | return cast(T) this; 155 | } 156 | } 157 | 158 | this._startAngle = startAngle; 159 | 160 | if (this._parent) 161 | { 162 | this._tk.eval("%s itemconfigure %s -start %s", this._parent.id, this.id, this._startAngle); 163 | } 164 | 165 | return cast(T) this; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/vertex.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Vertex module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.canvas.vertex; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template Vertex() 13 | { 14 | /** 15 | * The style of the joins. 16 | */ 17 | private string _joinStyle; 18 | 19 | /** 20 | * The smoothing method used for the line. 21 | */ 22 | private string _smoothMethod; 23 | 24 | /** 25 | * Defines how many splines to use for smoothing. 26 | */ 27 | private int _splineSteps; 28 | 29 | /** 30 | * Get the join style. 31 | * 32 | * Returns: 33 | * The join style. 34 | */ 35 | public string getJoinStyle() 36 | { 37 | if (this._parent) 38 | { 39 | this._tk.eval("%s itemcget %s -joinstyle", this._parent.id, this.id); 40 | this._joinStyle = this._tk.getResult!(string); 41 | } 42 | 43 | return this._joinStyle; 44 | } 45 | 46 | /** 47 | * Specifies the ways in which joints are to be drawn at the vertices of 48 | * the line. If this option is not specified then it defaults to round. If 49 | * the line only contains two points then this option is irrelevant. 50 | * 51 | * Params: 52 | * joinStyle = The join style. 53 | * 54 | * Returns: 55 | * This item to aid method chaining. 56 | * 57 | * See_Also: 58 | * $(LINK2 ../../canvas.html#CanvasLineJoinStyle, tkd.widget.canvas.CanvasLineJoinStyle) 59 | */ 60 | public auto setJoinStyle(this T)(string joinStyle) 61 | { 62 | this._joinStyle = joinStyle; 63 | 64 | if (this._parent && this._joinStyle.length) 65 | { 66 | this._tk.eval("%s itemconfigure %s -joinstyle {%s}", this._parent.id, this.id, this._joinStyle); 67 | } 68 | 69 | return cast(T) this; 70 | } 71 | 72 | /** 73 | * Get the smooth method. 74 | * 75 | * Returns: 76 | * The smooth method. 77 | */ 78 | public string getSmoothMethod() 79 | { 80 | if (this._parent) 81 | { 82 | this._tk.eval("%s itemcget %s -smooth", this._parent.id, this.id); 83 | this._smoothMethod = this._tk.getResult!(string); 84 | } 85 | 86 | return this._smoothMethod; 87 | } 88 | 89 | /** 90 | * If the smoothing method is bezier, this indicates that the line should 91 | * be drawn as a curve, rendered as a set of quadratic splines: one spline 92 | * is drawn for the first and second line segments, one for the second and 93 | * third, and so on. Straight-line segments can be generated within a curve 94 | * by duplicating the end-points of the desired line segment. If the 95 | * smoothing method is raw, this indicates that the line should also be 96 | * drawn as a curve but where the list of coordinates is such that the 97 | * first coordinate pair (and every third coordinate pair thereafter) is a 98 | * knot point on a cubic bezier curve, and the other coordinates are 99 | * control points on the cubic bezier curve. Straight line segments can be 100 | * generated within a curve by making control points equal to their 101 | * neighbouring knot points. If the last point is a control point and not a 102 | * knot point, the point is repeated (one or two times) so that it also 103 | * becomes a knot point. 104 | * 105 | * Params: 106 | * smoothMethod = The smooth method. 107 | * 108 | * Returns: 109 | * This item to aid method chaining. 110 | * 111 | * See_Also: 112 | * $(LINK2 ../../canvas.html#CanvasLineSmoothMethod, tkd.widget.canvas.CanvasLineSmoothMethod) 113 | */ 114 | public auto setSmoothMethod(this T)(string smoothMethod) 115 | { 116 | this._smoothMethod = smoothMethod; 117 | 118 | if (this._parent && this._smoothMethod.length) 119 | { 120 | this._tk.eval("%s itemconfigure %s -smooth {%s}", this._parent.id, this.id, this._smoothMethod); 121 | } 122 | 123 | return cast(T) this; 124 | } 125 | 126 | /** 127 | * Get smooth method spline steps. 128 | * 129 | * Returns: 130 | * The smooth method spline steps. 131 | */ 132 | public int getSmoothSplineSteps() 133 | { 134 | if (this._parent) 135 | { 136 | this._tk.eval("%s itemcget %s -splinesteps", this._parent.id, this.id); 137 | this._splineSteps = this._tk.getResult!(int); 138 | } 139 | 140 | return this._splineSteps; 141 | } 142 | 143 | /** 144 | * Specifies the degree of smoothness desired for curves: each spline will 145 | * be approximated with number line segments. 146 | * 147 | * Params: 148 | * splineSteps = The smooth method spline steps. 149 | * 150 | * Returns: 151 | * This item to aid method chaining. 152 | */ 153 | public auto setSmoothSplineSteps(this T)(int splineSteps) 154 | { 155 | this._splineSteps = splineSteps; 156 | 157 | if (this._parent && this._splineSteps > 0) 158 | { 159 | this._tk.eval("%s itemconfigure %s -splinesteps %s", this._parent.id, this.id, this._splineSteps); 160 | } 161 | 162 | return cast(T) this; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /source/tkd/element/cursor.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Element module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.element.cursor; 8 | 9 | /** 10 | * Cross-platform cursor values. 11 | */ 12 | enum Cursor : string 13 | { 14 | normal = "", 15 | xCursor = "X_cursor", 16 | arrow = "arrow", 17 | basedArrowDown = "based_arrow_down", 18 | basedArrowUp = "based_arrow_up", 19 | boat = "boat", 20 | bogosity = "bogosity", 21 | bottomLeftCorner = "bottom_left_corner", 22 | bottomRightCorner = "bottom_right_corner", 23 | bottomSide = "bottom_side", 24 | bottomTee = "bottom_tee", 25 | boxSpiral = "box_spiral", 26 | centerPtr = "center_ptr", 27 | circle = "circle", 28 | clock = "clock", 29 | coffeeMug = "coffee_mug", 30 | cross = "cross", 31 | crossReverse = "cross_reverse", 32 | crosshair = "crosshair", 33 | diamondCross = "diamond_cross", 34 | dot = "dot", 35 | dotbox = "dotbox", 36 | doubleArrow = "double_arrow", 37 | draftLarge = "draft_large", 38 | draftSmall = "draft_small", 39 | drapedBox = "draped_box", 40 | exchange = "exchange", 41 | fleur = "fleur", 42 | gobbler = "gobbler", 43 | gumby = "gumby", 44 | hand1 = "hand1", 45 | hand2 = "hand2", 46 | heart = "heart", 47 | icon = "icon", 48 | ironCross = "iron_cross", 49 | leftPtr = "left_ptr", 50 | leftSide = "left_side", 51 | leftTee = "left_tee", 52 | leftbutton = "leftbutton", 53 | llAngle = "ll_angle", 54 | lrAngle = "lr_angle", 55 | man = "man", 56 | middlebutton = "middlebutton", 57 | mouse = "mouse", 58 | pencil = "pencil", 59 | pirate = "pirate", 60 | plus = "plus", 61 | questionArrow = "question_arrow", 62 | rightPtr = "right_ptr", 63 | rightSide = "right_side", 64 | rightTee = "right_tee", 65 | rightbutton = "rightbutton", 66 | rtlLogo = "rtl_logo", 67 | sailboat = "sailboat", 68 | sbDownArrow = "sb_down_arrow", 69 | sbHorizontalDoubleArrow = "sb_h_double_arrow", 70 | sbLeftArrow = "sb_left_arrow", 71 | sbRightArrow = "sb_right_arrow", 72 | sbUpArrow = "sb_up_arrow", 73 | sbVerticalDoubleArrow = "sb_v_double_arrow", 74 | shuttle = "shuttle", 75 | sizing = "sizing", 76 | spider = "spider", 77 | spraycan = "spraycan", 78 | star = "star", 79 | target = "target", 80 | tcross = "tcross", 81 | topLeftArrow = "top_left_arrow", 82 | topLeftCorner = "top_left_corner", 83 | topRightCorner = "top_right_corner", 84 | topSide = "top_side", 85 | topTee = "top_tee", 86 | trek = "trek", 87 | ulAngle = "ul_angle", 88 | umbrella = "umbrella", 89 | urAngle = "ur_angle", 90 | watch = "watch", 91 | xterm = "xterm", 92 | } 93 | 94 | /** 95 | * Windows only cursor values. 96 | */ 97 | version (Windows) 98 | { 99 | enum WindowsCursor : string 100 | { 101 | no = "no", 102 | starting = "starting", 103 | size = "size", 104 | sizeNeSw = "size_ne_sw", 105 | sizeNs = "size_ns", 106 | sizeNwSe = "size_nw_se", 107 | sizeWe = "size_we", 108 | upArrow = "uparrow", 109 | wait = "wait", 110 | } 111 | } 112 | 113 | /** 114 | * MacOSX only cursor values. 115 | */ 116 | version (OSX) 117 | { 118 | enum MacOSXCursor : string 119 | { 120 | copyArrow = "copyarrow", 121 | aliasArrow = "aliasarrow", 122 | contextualMenuArrow = "contextualmenuarrow", 123 | text = "text", 124 | crosshair = "cross", 125 | closedHand = "closedhand", 126 | openHand = "openhand", 127 | pointingHand = "pointinghand", 128 | resizeLeft = "resizeleft", 129 | resizeRight = "resizeright", 130 | resizeLeftRight = "resizeleftright", 131 | resizeUp = "resizeup", 132 | resizeDown = "resizedown", 133 | resizeUpDown = "resizeupdown", 134 | none = "none", 135 | notAllowed = "notallowed", 136 | poof = "poof", 137 | countingUpHand = "countinguphand", 138 | countingDownHand = "countingdownhand", 139 | countingUpAndDownHand = "countingupanddownhand", 140 | spinning = "spinning", 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /source/tkd/window/dialog/fontdialog.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Dialog module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.window.dialog.fontdialog; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import tkd.window.dialog.dialog; 13 | import tkd.element.element; 14 | import tkd.window.window; 15 | 16 | /** 17 | * The font dialog allows users to choose a font installed on the system. It 18 | * uses the native platform font selection dialog where available, or a dialog 19 | * implemented in Tcl/Tk otherwise. Unlike most of the other dialogs, the 20 | * fontchooser does not return an immediate result because on some platforms 21 | * (Mac OSX) the standard font dialog is modeless while on others (Windows) it 22 | * is modal. To accommodate this difference, all user interaction with the 23 | * dialog will be communicated to the caller via commands or virtual events. 24 | * 25 | * Example: 26 | * --- 27 | * auto dialog = new FontDialog("Select a font") 28 | * .setCommand(delegate(CommandArgs args){ 29 | * string font = args.dialog.font; 30 | * }) 31 | * .show(); 32 | * --- 33 | * 34 | * Additional_Events: 35 | * Additional events that can also be bound to using the $(LINK2 ../../element/uielement.html#UiElement.bind, bind) method. 36 | * $(P 37 | * <<TkFontchooserFontChanged>>, 38 | * <<TkFontchooserVisibility>>, 39 | * ) 40 | * 41 | * Result: 42 | * The result is empty as all interaction takes place via callbacks. 43 | * 44 | * See_Also: 45 | * $(LINK2 ./dialog.html, tkd.dialog.dialog) $(BR) 46 | */ 47 | class FontDialog : Dialog 48 | { 49 | /** 50 | * The name of the callback to execute when a new font is choosen. 51 | */ 52 | private string _command; 53 | 54 | /** 55 | * Construct the dialog. 56 | * 57 | * Params: 58 | * parent = The parent window of the dialog. 59 | * title = The title of the dialog. 60 | */ 61 | this(Window parent, string title = "Font") 62 | { 63 | super(parent, title); 64 | } 65 | 66 | /** 67 | * Construct the dialog. 68 | * 69 | * Params: 70 | * title = The title of the dialog. 71 | */ 72 | this(string title = "Font") 73 | { 74 | this(null, title); 75 | } 76 | 77 | /** 78 | * Set the callback to execute when a new font is choosen. When the 79 | * callback is executed information about the choosen font is stored as a 80 | * string in the CommandArgs.Dialog struct. 81 | * 82 | * Params: 83 | * callback = The delegate callback to execute when invoking the command. 84 | * 85 | * Returns: 86 | * This dialog to aid method chaining. 87 | * 88 | * Callback_Arguments: 89 | * These are the fields within the callback's $(LINK2 90 | * ../../element/element.html#CommandArgs, CommandArgs) parameter which 91 | * are populated by this method when the callback is executed. 92 | * $(P 93 | * $(PARAM_TABLE 94 | * $(PARAM_ROW CommandArgs.element, The element that executed the callback.) 95 | * $(PARAM_ROW CommandArgs.callback, The callback which was executed.) 96 | * $(PARAM_ROW CommandArgs.dialog.font, Font information populated from dialog interaction.) 97 | * ) 98 | * ) 99 | * 100 | * See_Also: 101 | * $(LINK2 ../../element/element.html#CommandArgs, tkd.element.element.CommandArgs) $(BR) 102 | * $(LINK2 ../../element/element.html#CommandCallback, tkd.element.element.CommandCallback) $(BR) 103 | */ 104 | public auto setCommand(this T)(CommandCallback callback) 105 | { 106 | this._command = this.createCommand(callback); 107 | this.configureDialog(); 108 | 109 | return cast(T) this; 110 | } 111 | 112 | /** 113 | * Remove a previously set command. 114 | * 115 | * Returns: 116 | * This dialog to aid method chaining. 117 | */ 118 | public auto removeCommand(this T)() 119 | { 120 | this._command = ""; 121 | this._tk.deleteCommand(this.getCommandName()); 122 | this.configureDialog(); 123 | 124 | return cast(T) this; 125 | } 126 | 127 | /** 128 | * Configure the dialog with the various properties. 129 | */ 130 | private void configureDialog() 131 | { 132 | if (this._parent) 133 | { 134 | this._tk.eval("tk fontchooser configure -parent %s -title {%s} -command {%s}", this._parent.id, this._title, this._command); 135 | } 136 | else 137 | { 138 | this._tk.eval("tk fontchooser configure -title {%s} -command {%s}", this._title, this._command); 139 | } 140 | } 141 | 142 | /** 143 | * Show the dialog. 144 | * 145 | * Returns: 146 | * This dialog to aid method chaining. 147 | */ 148 | public auto show(this T)() 149 | { 150 | this._tk.eval("tk fontchooser show"); 151 | 152 | return cast(T) this; 153 | } 154 | 155 | /** 156 | * Hide the dialog. 157 | * 158 | * Returns: 159 | * This dialog to aid method chaining. 160 | */ 161 | public auto hide(this T)() 162 | { 163 | this._tk.eval("tk fontchooser hide"); 164 | 165 | return cast(T) this; 166 | } 167 | 168 | /** 169 | * Check if the dialog is visible. 170 | * 171 | * Returns: 172 | * This dialog to aid method chaining. 173 | */ 174 | public bool isVisible() 175 | { 176 | this._tk.eval("tk fontchooser configure -visible"); 177 | 178 | return this._tk.getResult!(int) == 1; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /source/tkd/widget/button.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.button; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import tkd.element.uielement; 13 | import tkd.image.image; 14 | import tkd.image.imageposition; 15 | import tkd.widget.common.command; 16 | import tkd.widget.common.default_; 17 | import tkd.widget.common.invoke; 18 | import tkd.widget.textwidget; 19 | 20 | /** 21 | * A button widget displays a textual label and/or image, and evaluates a 22 | * command when pressed. 23 | * 24 | * Example: 25 | * --- 26 | * auto button = new Button(new Png!("image.png"), "Text") 27 | * .setCommand(delegate(CommandArgs arg){ ... }) 28 | * .pack(); 29 | * --- 30 | * 31 | * Common_Commands: 32 | * These are injected common commands that can also be used with this widget. 33 | * $(P 34 | * $(LINK2 ./common/command.html, Command) $(BR) 35 | * $(LINK2 ./common/default_.html, Default) $(BR) 36 | * $(LINK2 ./common/invoke.html, Invoke) $(BR) 37 | * ) 38 | * 39 | * Additional_Events: 40 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 41 | * $(P 42 | * <<Invoke>>, 43 | * <<PrevWindow>>, 44 | * <Alt-Key>, 45 | * <B1-Enter>, 46 | * <B1-Leave>, 47 | * <Button-1>, 48 | * <ButtonRelease-1>, 49 | * <Enter>, 50 | * <Key-F10>, 51 | * <Key-Tab>, 52 | * <Key-space>, 53 | * <Leave>, 54 | * ) 55 | * 56 | * Styles: 57 | * Button widgets support the Toolbutton style in all standard themes, 58 | * which is useful for creating widgets for toolbars. 59 | * 60 | * See_Also: 61 | * $(LINK2 ./textwidget.html, tkd.widget.textwidget) 62 | */ 63 | class Button : TextWidget 64 | { 65 | /** 66 | * Construct the widget. 67 | * 68 | * Params: 69 | * parent = The parent of this widget. 70 | * text = The text of the button. 71 | * image = The button image. 72 | * imagePosition = The position of the image in relation to the text. 73 | * 74 | * See_Also: 75 | * $(LINK2 ../element/uielement.html, tkd.element.uielement) $(BR) 76 | * $(LINK2 ../image/image.html, tkd.image.image) $(BR) 77 | * $(LINK2 ../image/png.html, tkd.image.png) $(BR) 78 | * $(LINK2 ../image/gif.html, tkd.image.gif) $(BR) 79 | * $(LINK2 ../image/imageposition.html, tkd.image.imageposition) $(BR) 80 | */ 81 | this(UiElement parent, string text, Image image = null, string imagePosition = ImagePosition.top) 82 | { 83 | super(parent); 84 | this._elementId = "button"; 85 | 86 | this._tk.eval("ttk::button %s -textvariable %s", this.id, this._textVariable); 87 | 88 | this.setText(text); 89 | 90 | if (image !is null) 91 | { 92 | this.setImage(image, imagePosition); 93 | } 94 | } 95 | 96 | /** 97 | * Construct the widget. 98 | * 99 | * Params: 100 | * parent = The parent of this widget. 101 | * image = The button image. 102 | * text = The text of the button. 103 | * imagePosition = The position of the image in relation to the text. 104 | * 105 | * See_Also: 106 | * $(LINK2 ../element/uielement.html, tkd.element.uielement) $(BR) 107 | * $(LINK2 ../image/image.html, tkd.image.image) $(BR) 108 | * $(LINK2 ../image/png.html, tkd.image.png) $(BR) 109 | * $(LINK2 ../image/gif.html, tkd.image.gif) $(BR) 110 | * $(LINK2 ../image/imageposition.html, tkd.image.imageposition) $(BR) 111 | */ 112 | this(UiElement parent, Image image, string text = null, string imagePosition = ImagePosition.image) 113 | { 114 | this(parent, text, image, imagePosition); 115 | } 116 | 117 | /** 118 | * Construct the widget. 119 | * 120 | * Params: 121 | * text = The text of the button. 122 | * image = The button image. 123 | * imagePosition = The position of the image in relation to the text. 124 | * 125 | * See_Also: 126 | * $(LINK2 ../image/image.html, tkd.image.image) $(BR) 127 | * $(LINK2 ../image/png.html, tkd.image.png) $(BR) 128 | * $(LINK2 ../image/gif.html, tkd.image.gif) $(BR) 129 | * $(LINK2 ../image/imageposition.html, tkd.image.imageposition) $(BR) 130 | */ 131 | this(string text, Image image = null, string imagePosition = ImagePosition.top) 132 | { 133 | this(null, text, image, imagePosition); 134 | } 135 | 136 | /** 137 | * Construct the widget. 138 | * 139 | * Params: 140 | * image = The button image. 141 | * text = The text of the button. 142 | * imagePosition = The position of the image in relation to the text. 143 | * 144 | * See_Also: 145 | * $(LINK2 ../image/image.html, tkd.image.image) $(BR) 146 | * $(LINK2 ../image/png.html, tkd.image.png) $(BR) 147 | * $(LINK2 ../image/gif.html, tkd.image.gif) $(BR) 148 | * $(LINK2 ../image/imageposition.html, tkd.image.imageposition) $(BR) 149 | */ 150 | this(Image image, string text = null, string imagePosition = ImagePosition.image) 151 | { 152 | this(null, text, image, imagePosition); 153 | } 154 | 155 | /** 156 | * Mixin common commands. 157 | */ 158 | mixin Command; 159 | mixin Default_; 160 | mixin Invoke; 161 | } 162 | -------------------------------------------------------------------------------- /source/tkd/widget/radiobutton.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.radiobutton; 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.invoke; 16 | import tkd.widget.common.value; 17 | import tkd.widget.textwidget; 18 | 19 | /** 20 | * Radio button widgets are used in groups to show or change a set of 21 | * mutually-exclusive options. Radio buttons have an associated selected value; 22 | * when a radio button is selected, it sets the associated value. 23 | * 24 | * To create a group of radio button that work properly in unison, all radio 25 | * button widgets within the group must share the same immediate parent 26 | * (usually a frame) and all must have individual selected values set. 27 | * 28 | * Example: 29 | * --- 30 | * // The radio button group parent. 31 | * auto frame = new Frame() 32 | * .pack(); 33 | * 34 | * auto option1 = new RadioButton(frame, "Foo") 35 | * .setSelectedValue("foo") 36 | * .select() 37 | * .pack(); 38 | * 39 | * auto option2 = new RadioButton(frame, "Bar") 40 | * .setSelectedValue("bar") 41 | * .pack(); 42 | * --- 43 | * 44 | * Common_Commands: 45 | * These are injected common commands that can also be used with this widget. 46 | * $(P 47 | * $(LINK2 ./common/command.html, Command) $(BR) 48 | * $(LINK2 ./common/invoke.html, Invoke) $(BR) 49 | * $(LINK2 ./common/value.html, Value) $(BR) 50 | * ) 51 | * 52 | * Additional_Events: 53 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 54 | * $(P 55 | * <<Invoke>>, 56 | * <<PrevWindow>>, 57 | * <Alt-Key>, 58 | * <B1-Enter>, 59 | * <B1-Leave>, 60 | * <Button-1>, 61 | * <ButtonRelease-1>, 62 | * <Enter>, 63 | * <Key-Down>, 64 | * <Key-F10>, 65 | * <Key-Tab>, 66 | * <Key-Up>, 67 | * <Key-space>, 68 | * <Leave>, 69 | * ) 70 | * 71 | * States: 72 | * This widget does not respond to user input if the disabled state is set. 73 | * The widget sets the selected state whenever the value to set to the 74 | * selected value, and clears it otherwise. This widget sets the alternate 75 | * state whenever value is unset. (The alternate state may be used to 76 | * indicate a "tri-state" or "indeterminate" selection.) 77 | * 78 | * Styles: 79 | * Radio button widgets support the Toolbutton style in all standard 80 | * themes, which is useful for creating widgets for toolbars. 81 | * 82 | * See_Also: 83 | * $(LINK2 ./textwidget.html, tkd.widget.textwidget) $(BR) 84 | */ 85 | class RadioButton : TextWidget 86 | { 87 | /** 88 | * The name of the variable that contains the widget's value. 89 | */ 90 | private string _valueVariable; 91 | 92 | /** 93 | * The value of the radio button if it's selected. 94 | * The default is '1'. 95 | */ 96 | private string _selectedValue = "1"; 97 | 98 | /** 99 | * Construct the widget. 100 | * 101 | * Params: 102 | * parent = The parent of this widget. 103 | * text = The text of the button. 104 | * 105 | * See_Also: 106 | * $(LINK2 ../element/uielement.html, tkd.element.uielement) $(BR) 107 | */ 108 | this(UiElement parent, string text) 109 | { 110 | super(parent); 111 | this._elementId = "radiobutton"; 112 | 113 | if (parent is null) 114 | { 115 | this._valueVariable = format("variable-%s", this.generateHash(this._elementId)); 116 | } 117 | else 118 | { 119 | this._valueVariable = format("variable-%s", this.generateHash("%s%s", this._elementId, parent.id)); 120 | } 121 | 122 | this._tk.eval("ttk::radiobutton %s -textvariable %s -variable %s", this.id, this._textVariable, this._valueVariable); 123 | 124 | this.setText(text); 125 | } 126 | 127 | /** 128 | * Construct the widget. 129 | * 130 | * Params: 131 | * text = The text of the button. 132 | */ 133 | this(string text) 134 | { 135 | this(null, text); 136 | } 137 | 138 | /** 139 | * Get the value of the selected state. 140 | * 141 | * Returns: 142 | * A string contain the value of the selected state. 143 | */ 144 | public string getSelectedValue() 145 | { 146 | return this._selectedValue; 147 | } 148 | 149 | /** 150 | * Set the value of the selected state. 151 | * 152 | * Params: 153 | * value = The value of the widget for the selected state. 154 | * 155 | * Returns: 156 | * This widget to aid method chaining. 157 | */ 158 | public auto setSelectedValue(this T)(string value) 159 | { 160 | this._selectedValue = value; 161 | this._tk.eval("%s configure -value %s", this.id, this._selectedValue); 162 | 163 | return cast(T) this; 164 | } 165 | 166 | /** 167 | * Select the radio button and execute the command if bound. 168 | */ 169 | public auto select(this T)() 170 | { 171 | this._tk.setVariable(this._valueVariable, this._selectedValue); 172 | 173 | return cast(T) this; 174 | } 175 | 176 | /** 177 | * Mixin common commands. 178 | */ 179 | mixin Command; 180 | mixin Invoke; 181 | mixin Value!(this._valueVariable, string); 182 | } 183 | -------------------------------------------------------------------------------- /source/tkd/widget/common/canvas/outlinedash.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Outline dash module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.common.canvas.outlinedash; 8 | 9 | /** 10 | * These are common commands that apply to all widgets that have them injected. 11 | */ 12 | mixin template OutlineDash() 13 | { 14 | import std.algorithm; 15 | import std.array; 16 | import std.conv; 17 | 18 | /** 19 | * The dash pattern. 20 | */ 21 | private int[] _outlineDash; 22 | 23 | /** 24 | * The active dash pattern. 25 | */ 26 | private int[] _activeOutlineDash; 27 | 28 | /** 29 | * The disabled dash pattern. 30 | */ 31 | private int[] _disabledOutlineDash; 32 | 33 | /** 34 | * The dash offset. 35 | */ 36 | private int _outlineDashOffset; 37 | 38 | /** 39 | * Get the dash pattern. 40 | * 41 | * Returns: 42 | * The dash pattern of the item. 43 | */ 44 | public int[] getOutlineDash() 45 | { 46 | if (this._parent) 47 | { 48 | this._tk.eval("%s itemcget %s -dash", this._parent.id, this.id); 49 | this._outlineDash = this._tk.getResult!(string).split().map!(to!(int)).array; 50 | } 51 | 52 | return this._outlineDash; 53 | } 54 | 55 | /** 56 | * Set the dash pattern of the outline. Each element represents the number 57 | * of pixels of a line segment. Only the odd segments are drawn using the 58 | * outline color. The other segments are drawn transparent. 59 | * 60 | * Params: 61 | * dash = The dash pattern. 62 | * 63 | * Returns: 64 | * This widget to aid method chaining. 65 | */ 66 | public auto setOutlineDash(this T)(int[] dash) 67 | { 68 | this._outlineDash = dash; 69 | 70 | if (this._parent && this._outlineDash.length) 71 | { 72 | this._tk.eval("%s itemconfigure %s -dash [list %s]", this._parent.id, this.id, this._outlineDash.map!(to!(string)).join(" ")); 73 | } 74 | 75 | return cast(T) this; 76 | } 77 | 78 | /** 79 | * Get the active dash pattern. 80 | * An item's active state is triggered when the mouse rolls over the item. 81 | * 82 | * Returns: 83 | * The active dash pattern of the item. 84 | */ 85 | public int[] getActiveOutlineDash() 86 | { 87 | if (this._parent) 88 | { 89 | this._tk.eval("%s itemcget %s -activedash", this._parent.id, this.id); 90 | this._activeOutlineDash = this._tk.getResult!(string).split().map!(to!(int)).array; 91 | } 92 | 93 | return this._activeOutlineDash; 94 | } 95 | 96 | /** 97 | * Set the active dash pattern of the outline. Each element represents the 98 | * number of pixels of a line segment. Only the odd segments are drawn 99 | * using the outline color. The other segments are drawn transparent. An 100 | * item's active state is triggered when the mouse rolls over the item. 101 | * 102 | * Params: 103 | * dash = The active dash pattern. 104 | * 105 | * Returns: 106 | * This widget to aid method chaining. 107 | */ 108 | public auto setActiveOutlineDash(this T)(int[] dash) 109 | { 110 | this._activeOutlineDash = dash; 111 | 112 | if (this._parent && this._activeOutlineDash.length) 113 | { 114 | this._tk.eval("%s itemconfigure %s -activedash [list %s]", this._parent.id, this.id, this._activeOutlineDash.map!(to!(string)).join(" ")); 115 | } 116 | 117 | return cast(T) this; 118 | } 119 | 120 | /** 121 | * Get the disabled dash pattern. 122 | * 123 | * Returns: 124 | * The disabled dash pattern of the item. 125 | */ 126 | public int[] getDisabledOutlineDash() 127 | { 128 | if (this._parent) 129 | { 130 | this._tk.eval("%s itemcget %s -disableddash", this._parent.id, this.id); 131 | this._disabledOutlineDash = this._tk.getResult!(string).split().map!(to!(int)).array; 132 | } 133 | 134 | return this._disabledOutlineDash; 135 | } 136 | 137 | /** 138 | * Set the disabled dash pattern of the outline. Each element represents the 139 | * number of pixels of a line segment. Only the odd segments are drawn 140 | * using the outline color. The other segments are drawn transparent. 141 | * 142 | * Params: 143 | * dash = The disabled dash pattern. 144 | * 145 | * Returns: 146 | * This widget to aid method chaining. 147 | */ 148 | public auto setDisabledOutlineDash(this T)(int[] dash) 149 | { 150 | this._disabledOutlineDash = dash; 151 | 152 | if (this._parent && this._disabledOutlineDash.length) 153 | { 154 | this._tk.eval("%s itemconfigure %s -disableddash [list %s]", this._parent.id, this.id, this._disabledOutlineDash.map!(to!(string)).join(" ")); 155 | } 156 | 157 | return cast(T) this; 158 | } 159 | 160 | /** 161 | * Get the dash offset. 162 | * 163 | * Returns: 164 | * The dash offset. 165 | */ 166 | public int getOutlineDashOffset() 167 | { 168 | if (this._parent) 169 | { 170 | this._tk.eval("%s itemcget %s -dashoffset", this._parent.id, this.id); 171 | this._outlineDashOffset = this._tk.getResult!(int); 172 | } 173 | 174 | return this._outlineDashOffset; 175 | } 176 | 177 | /** 178 | * Set the dash offset. 179 | * 180 | * Params: 181 | * offset = The dash offset. 182 | * 183 | * Returns: 184 | * This widget to aid method chaining. 185 | */ 186 | public auto setOutlineDashOffset(this T)(int offset) 187 | { 188 | this._outlineDashOffset = offset; 189 | 190 | if (this._parent && this._outlineDashOffset > 0) 191 | { 192 | this._tk.eval("%s itemconfigure %s -dashoffset %s", this._parent.id, this.id, this._outlineDashOffset); 193 | } 194 | 195 | return cast(T) this; 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /docs/tkd/element/cursor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 243 | tkd.element.cursor 244 | 245 | 246 |

tkd.element.cursor

247 |

Element module. 248 |

License

MIT. See LICENSE for full details.

enum Cursor: string; 249 |

250 |

Cross-platform cursor values.

251 |
252 | 253 | -------------------------------------------------------------------------------- /docs/tkd/element/fontstyle.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 243 | tkd.element.fontstyle 244 | 245 | 246 |

tkd.element.fontstyle

247 |

Element module. 248 |

License

MIT. See LICENSE for full details.

enum FontStyle: string; 249 |

250 |

Font style options.

251 |
252 | 253 | -------------------------------------------------------------------------------- /source/tkd/widget/checkbutton.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.checkbutton; 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.invoke; 16 | import tkd.widget.common.value; 17 | import tkd.widget.textwidget; 18 | 19 | /** 20 | * A checkbutton widget is used to show or change a setting. It has two states, 21 | * selected and deselected. The state of the checkbutton may be linked to a 22 | * value. 23 | * 24 | * Example: 25 | * --- 26 | * auto checkButton = new CheckButton("Text") 27 | * .setCommand(delegate(CommandArgs arg){ ... }) 28 | * .check() 29 | * .pack(); 30 | * --- 31 | * 32 | * Common_Commands: 33 | * These are injected common commands that can also be used with this widget. 34 | * $(P 35 | * $(LINK2 ./common/command.html, Command) $(BR) 36 | * $(LINK2 ./common/invoke.html, Invoke) $(BR) 37 | * $(LINK2 ./common/value.html, Value) $(BR) 38 | * ) 39 | * 40 | * Additional_Events: 41 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 42 | * $(P 43 | * <<Invoke>>, 44 | * <<PrevWindow>>, 45 | * <Alt-Key>, 46 | * <B1-Enter>, 47 | * <B1-Leave>, 48 | * <Button-1>, 49 | * <ButtonRelease-1>, 50 | * <Enter>, 51 | * <Key-F10>, 52 | * <Key-Tab>, 53 | * <Key-space>, 54 | * <Leave>, 55 | * ) 56 | * 57 | * States: 58 | * This widget does not respond to user input if the disabled state is set. 59 | * The widget sets the selected state whenever the value is set to the 60 | * widget's on-value, and clears it otherwise. The widget sets the 61 | * alternate state whenever the value is unset. (The alternate state may be 62 | * used to indicate a "tri-state" or "indeterminate" selection.) 63 | * 64 | * Styles: 65 | * Check button widgets support the Toolbutton style in all standard 66 | * themes, which is useful for creating widgets for toolbars. 67 | * 68 | * See_Also: 69 | * $(LINK2 ./textwidget.html, tkd.widget.textwidget) 70 | */ 71 | class CheckButton : TextWidget 72 | { 73 | /** 74 | * The name of the variable that contains the widget's value. 75 | */ 76 | private string _valueVariable; 77 | 78 | /** 79 | * The value of the checkbutton if it's checked. 80 | * The default is '1'. 81 | */ 82 | private string _onValue = "1"; 83 | 84 | /** 85 | * The value of the checkbutton if it's unchecked. 86 | * The default is '1'. 87 | */ 88 | private string _offValue = "0"; 89 | 90 | /** 91 | * Construct the widget. 92 | * 93 | * Params: 94 | * parent = An optional parent of this widget. 95 | * text = The text of the checkbutton. 96 | * 97 | * See_Also: 98 | * $(LINK2 ../element/uielement.html, tkd.element.uielement) 99 | */ 100 | this(UiElement parent, string text = null) 101 | { 102 | super(parent); 103 | this._elementId = "checkbutton"; 104 | this._valueVariable = format("variable-%s", this.generateHash(this.id)); 105 | 106 | this._tk.eval("ttk::checkbutton %s -textvariable %s -variable %s", this.id, this._textVariable, this._valueVariable); 107 | 108 | this.setText(text); 109 | this.unCheck(); 110 | } 111 | 112 | /** 113 | * Construct the widget. 114 | * 115 | * Params: 116 | * text = The text of the checkbutton. 117 | */ 118 | this(string text = null) 119 | { 120 | this(null, text); 121 | } 122 | 123 | /** 124 | * Check the check button. 125 | * 126 | * Returns: 127 | * This widget to aid method chaining. 128 | */ 129 | public auto check(this T)() 130 | { 131 | this._tk.setVariable(this._valueVariable, this._onValue); 132 | 133 | return cast(T) this; 134 | } 135 | 136 | /** 137 | * Uncheck the check button. 138 | * 139 | * Returns: 140 | * This widget to aid method chaining. 141 | */ 142 | public auto unCheck(this T)() 143 | { 144 | this._tk.setVariable(this._valueVariable, this._offValue); 145 | 146 | return cast(T) this; 147 | } 148 | 149 | /** 150 | * Only half check the check button. This is a kind of halfway state. 151 | * 152 | * Returns: 153 | * This widget to aid method chaining. 154 | */ 155 | public auto halfCheck(this T)() 156 | { 157 | this._tk.setVariable(this._valueVariable, ""); 158 | 159 | return cast(T) this; 160 | } 161 | 162 | /** 163 | * Check if the check button is checked or not. 164 | * 165 | * Returns: 166 | * true if the check button is checked, false if not. 167 | */ 168 | public bool isChecked() 169 | { 170 | return this._tk.getVariable(this._valueVariable) == this._onValue; 171 | } 172 | 173 | /** 174 | * Set the value of the checked state. 175 | * 176 | * Params: 177 | * value = The value of the widget for the checked state. 178 | * 179 | * Returns: 180 | * This widget to aid method chaining. 181 | */ 182 | public auto setOnValue(this T)(string value) 183 | { 184 | this._onValue = value; 185 | this._tk.eval("%s configure -onvalue %s", this.id, this._onValue); 186 | 187 | return cast(T) this; 188 | } 189 | 190 | /** 191 | * Set the value of the unchecked state. 192 | * 193 | * Params: 194 | * value = The value of the widget for the unchecked state. 195 | * 196 | * Returns: 197 | * This widget to aid method chaining. 198 | */ 199 | public auto setOffValue(this T)(string value) 200 | { 201 | this._offValue = value; 202 | this._tk.eval("%s configure -offvalue %s", this.id, this._offValue); 203 | 204 | return cast(T) this; 205 | } 206 | 207 | /** 208 | * Mixin common commands. 209 | */ 210 | mixin Invoke; 211 | mixin Command; 212 | mixin Value!(this._valueVariable, string); 213 | } 214 | -------------------------------------------------------------------------------- /source/tkd/widget/entry.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.entry; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.string; 13 | import tkd.element.uielement; 14 | import tkd.widget.common.boundingbox; 15 | import tkd.widget.common.color; 16 | import tkd.widget.common.cursor; 17 | import tkd.widget.common.delete_; 18 | import tkd.widget.common.exportselection; 19 | import tkd.widget.common.font; 20 | import tkd.widget.common.index; 21 | import tkd.widget.common.insert; 22 | import tkd.widget.common.justify; 23 | import tkd.widget.common.selection; 24 | import tkd.widget.common.show; 25 | import tkd.widget.common.value; 26 | import tkd.widget.common.width; 27 | import tkd.widget.common.xscrollcommand; 28 | import tkd.widget.common.xview; 29 | import tkd.widget.widget; 30 | 31 | /** 32 | * An entry widget displays a one-line text string and allows that string to be 33 | * edited by the user. Entry widgets support horizontal scrolling. 34 | * 35 | * Example: 36 | * --- 37 | * auto entry = new Entry() 38 | * .setValue("Text") 39 | * .pack(); 40 | * --- 41 | * 42 | * Common_Commands: 43 | * These are injected common commands that can also be used with this widget. 44 | * $(P 45 | * $(LINK2 ./common/boundingbox.html, BoundingBox) $(BR) 46 | * $(LINK2 ./common/color.html, Color) $(BR) 47 | * $(LINK2 ./common/cursor.html, Cursor) $(BR) 48 | * $(LINK2 ./common/delete_.html, Delete) $(BR) 49 | * $(LINK2 ./common/exportselection.html, Exportselection) $(BR) 50 | * $(LINK2 ./common/font.html, Font) $(BR) 51 | * $(LINK2 ./common/index.html, Index) $(BR) 52 | * $(LINK2 ./common/insert.html, Insert) $(BR) 53 | * $(LINK2 ./common/justify.html, Justify) $(BR) 54 | * $(LINK2 ./common/selection.html, Selection) $(BR) 55 | * $(LINK2 ./common/show.html, Show) $(BR) 56 | * $(LINK2 ./common/value.html, Value) $(BR) 57 | * $(LINK2 ./common/width.html, Width) $(BR) 58 | * $(LINK2 ./common/xscrollcommand.html, XScrollCommand) $(BR) 59 | * $(LINK2 ./common/xview.html, XView) $(BR) 60 | * ) 61 | * 62 | * Additional_Events: 63 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 64 | * $(P 65 | * <<Clear>>, 66 | * <<Copy>>, 67 | * <<Cut>>, 68 | * <<Paste>>, 69 | * <<PasteSelection>>, 70 | * <<PrevWindow>>, 71 | * <<TraverseIn>>, 72 | * <Alt-Key>, 73 | * <B1-Enter>, 74 | * <B1-Leave>, 75 | * <B1-Motion>, 76 | * <B2-Motion>, 77 | * <Button-1>, 78 | * <Button-2>, 79 | * <ButtonRelease-1>, 80 | * <ButtonRelease-2>, 81 | * <Control-Button-1>, 82 | * <Control-Key-Left>, 83 | * <Control-Key-Right>, 84 | * <Control-Key-a>, 85 | * <Control-Key-b>, 86 | * <Control-Key-backslash>, 87 | * <Control-Key-d>, 88 | * <Control-Key-e>, 89 | * <Control-Key-f>, 90 | * <Control-Key-h>, 91 | * <Control-Key-k>, 92 | * <Control-Key-slash>, 93 | * <Control-Key>, 94 | * <Control-Shift-Key-Left>, 95 | * <Control-Shift-Key-Right>, 96 | * <Double-Button-1>, 97 | * <Key-BackSpace>, 98 | * <Key-Delete>, 99 | * <Key-Down>, 100 | * <Key-End>, 101 | * <Key-Escape>, 102 | * <Key-F10>, 103 | * <Key-Home>, 104 | * <Key-KP_Enter>, 105 | * <Key-Left>, 106 | * <Key-Return>, 107 | * <Key-Right>, 108 | * <Key-Tab>, 109 | * <Key-Up>, 110 | * <Key>, 111 | * <Meta-Key>, 112 | * <Shift-Button-1>, 113 | * <Shift-Key-End>, 114 | * <Shift-Key-Home>, 115 | * <Shift-Key-Left>, 116 | * <Shift-Key-Right>, 117 | * <Triple-Button-1>, 118 | * ) 119 | * 120 | * States: 121 | * In the disabled state, the entry cannot be edited and the text cannot be 122 | * selected. In the readonly state, no insert cursor is displayed and the 123 | * entry cannot be edited. The disabled state is the same as readonly, and 124 | * in addition text cannot be selected. Typically, the text is "grayed-out" 125 | * in the disabled state, and a different background is used in the 126 | * readonly state. 127 | * 128 | * See_Also: 129 | * $(LINK2 ./widget.html, tkd.widget.widget) 130 | */ 131 | class Entry : Widget, IXScrollable!(Entry) 132 | { 133 | /** 134 | * The name of the variable that contains the widget's value. 135 | */ 136 | private string _valueVariable; 137 | 138 | /** 139 | * Construct the widget. 140 | * 141 | * Params: 142 | * parent = The parent of this widget. 143 | * 144 | * See_Also: 145 | * $(LINK2 ../element/uielement.html, tkd.element.uielement) $(BR) 146 | */ 147 | this(UiElement parent = null) 148 | { 149 | super(parent); 150 | this._elementId = "entry"; 151 | this._valueVariable = format("variable-%s", this.generateHash(this.id)); 152 | 153 | this._tk.eval("ttk::entry %s -textvariable %s", this.id, this._valueVariable); 154 | } 155 | 156 | /** 157 | * Mixin common commands. 158 | */ 159 | mixin BoundingBox; 160 | mixin Color; 161 | mixin Cursor; 162 | mixin Delete_; 163 | mixin ExportSelection; 164 | mixin Font; 165 | mixin Index; 166 | mixin Insert; 167 | mixin Justify; 168 | mixin Selection; 169 | mixin Show; 170 | mixin Value!(this._valueVariable, string); 171 | mixin Width; 172 | mixin XScrollCommand!(Entry); 173 | mixin XView; 174 | } 175 | -------------------------------------------------------------------------------- /source/tkd/widget/progressbar.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Widget module. 3 | * 4 | * License: 5 | * MIT. See LICENSE for full details. 6 | */ 7 | module tkd.widget.progressbar; 8 | 9 | /** 10 | * Imports. 11 | */ 12 | import std.string; 13 | import tkd.element.uielement; 14 | import tkd.widget.common.length; 15 | import tkd.widget.common.value; 16 | import tkd.widget.orientation; 17 | import tkd.widget.widget; 18 | 19 | /** 20 | * A progress bar widget shows the status of a long-running operation. They can 21 | * operate in two modes: determinate mode shows the amount completed relative 22 | * to the total amount of work to be done, and indeterminate mode provides an 23 | * animated display to let the user know that something is happening. 24 | * 25 | * Example: 26 | * --- 27 | * auto progressBar = new ProgressBar() 28 | * .setMaxValue(100) 29 | * .setValue(10) 30 | * .pack(); 31 | * --- 32 | * 33 | * Common_Commands: 34 | * These are injected common commands that can also be used with this widget. 35 | * $(P 36 | * $(LINK2 ./common/length.html, Length) $(BR) 37 | * $(LINK2 ./common/value.html, Value) $(BR) 38 | * ) 39 | * 40 | * Additional_Events: 41 | * Additional events that can also be bound to using the $(LINK2 ../element/uielement.html#UiElement.bind, bind) method. 42 | * $(P 43 | * <<PrevWindow>>, 44 | * <Alt-Key>, 45 | * <Key-F10>, 46 | * <Key-Tab>, 47 | * ) 48 | * 49 | * See_Also: 50 | * $(LINK2 ./widget.html, tkd.widget.widget) 51 | */ 52 | class ProgressBar : Widget 53 | { 54 | /** 55 | * The name of the variable that contains the widget's value. 56 | */ 57 | private string _valueVariable; 58 | 59 | /** 60 | * Construct the widget. 61 | * 62 | * Params: 63 | * parent = The parent of this widget. 64 | * orientation = The orientation of the widget. 65 | * 66 | * See_Also: 67 | * $(LINK2 ../element/uielement.html, tkd.element.UiElement) $(BR) 68 | * $(LINK2 ./orientation.html, tkd.widget.orientation) for orientations. 69 | */ 70 | public this(UiElement parent, string orientation = Orientation.horizontal) 71 | { 72 | super(parent); 73 | this._elementId = "progressbar"; 74 | this._valueVariable = format("variable-%s", this.generateHash(this.id)); 75 | 76 | this._tk.eval("ttk::progressbar %s -orient %s -variable %s", this.id, orientation, this._valueVariable); 77 | } 78 | 79 | /** 80 | * Construct the widget. 81 | * 82 | * Params: 83 | * orientation = The orientation of the widget. 84 | * 85 | * See_Also: 86 | * $(LINK2 ./orientation.html, tkd.widget.orientation) for orientations. 87 | */ 88 | public this(string orientation = Orientation.horizontal) 89 | { 90 | this(null, orientation); 91 | } 92 | 93 | /** 94 | * Set the mode of the progress bar. 95 | * 96 | * Params: 97 | * mode = The mode of the progress bar. 98 | * 99 | * Returns: 100 | * This widget to aid method chaining. 101 | * 102 | * See_Also: 103 | * $(LINK2 ./progressbar.html#ProgressBarMode, tkd.widget.progressbar.ProgressBarMode) $(BR) 104 | */ 105 | public auto setMode(this T)(string mode) 106 | { 107 | this._tk.eval("%s configure -mode %s", this.id, mode); 108 | 109 | return cast(T) this; 110 | } 111 | 112 | /** 113 | * Set the maximum value of the progress bar. 114 | * 115 | * Params: 116 | * maximum = The maximum value of the progress bar. 117 | * 118 | * Returns: 119 | * This widget to aid method chaining. 120 | */ 121 | public auto setMaxValue(this T)(double maximum) 122 | { 123 | this._tk.eval("%s configure -maximum %s", this.id, maximum); 124 | 125 | return cast(T) this; 126 | } 127 | 128 | /** 129 | * The widget periodically increments the value of this option whenever the 130 | * value is greater than 0 and, in determinate mode, less than the maximum. 131 | * This option may be used by the current theme to provide additional 132 | * animation effects. 133 | * 134 | * Returns: 135 | * A string containing the phase value. 136 | */ 137 | public string getPhase() 138 | { 139 | this._tk.eval("%s cget -phase", this.id); 140 | return this._tk.getResult!(string); 141 | } 142 | 143 | /** 144 | * Begin autoincrement mode: schedules a recurring timer event that calls 145 | * step every interval. 146 | * 147 | * Params: 148 | * milliseconds = The interval between steps. 149 | * 150 | * Returns: 151 | * This widget to aid method chaining. 152 | * 153 | * See_Also: 154 | * $(LINK2 ./progressbar.html#ProgressBar.stop, tkd.widget.progressbar.stop) $(BR) 155 | */ 156 | public auto start(this T)(int milliseconds = 50) 157 | { 158 | this._tk.eval("%s start %s", this.id, milliseconds); 159 | 160 | return cast(T) this; 161 | } 162 | 163 | /** 164 | * Increments the progress bar by an amount. 165 | * 166 | * Params: 167 | * increment = The amount to increment by. 168 | * 169 | * Returns: 170 | * This widget to aid method chaining. 171 | */ 172 | public auto step(this T)(int increment = 1) 173 | { 174 | this._tk.eval("%s step %s", this.id, increment); 175 | 176 | return cast(T) this; 177 | } 178 | 179 | /** 180 | * Stop autoincrement mode: cancels any recurring timer event initiated by 181 | * the start method. 182 | * 183 | * Returns: 184 | * This widget to aid method chaining. 185 | * 186 | * See_Also: 187 | * $(LINK2 ./progressbar.html#ProgressBar.start, tkd.widget.progressbar.start) $(BR) 188 | */ 189 | public auto stop(this T)() 190 | { 191 | this._tk.eval("%s stop", this.id); 192 | 193 | return cast(T) this; 194 | } 195 | 196 | /** 197 | * Mixin common commands. 198 | */ 199 | mixin Length; 200 | mixin Value!(this._valueVariable, double); 201 | } 202 | 203 | /** 204 | * The mode of a progress bar. 205 | */ 206 | enum ProgressBarMode : string 207 | { 208 | determinate = "determinate", /// Shows the amount completed relative to the total amount of work to be done. 209 | indeterminate = "indeterminate", /// Provides an animated display to let the user know that something is happening. 210 | } 211 | --------------------------------------------------------------------------------