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 }