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 }