1 // Written in the D programming language. 2 3 /** 4 5 This module implements window frame widget. 6 7 8 Synopsis: 9 10 ---- 11 import dlangui.widgets.docks; 12 ---- 13 14 15 Copyright: Vadim Lopatin, 2015 16 License: Boost License 1.0 17 Authors: Vadim Lopatin, coolreader.org@gmail.com 18 */ 19 module dlangui.widgets.winframe; 20 21 import dlangui.widgets.layouts; 22 import dlangui.widgets.controls; 23 24 /// window frame with caption widget 25 class WindowFrame : VerticalLayout { 26 27 protected Widget _bodyWidget; 28 @property Widget bodyWidget() { return _bodyWidget; } 29 @property void bodyWidget(Widget widget) { 30 _bodyLayout.replaceChild(widget, _bodyWidget); 31 _bodyWidget = widget; 32 _bodyWidget.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); 33 _bodyWidget.parent = this; 34 requestLayout(); 35 } 36 37 protected HorizontalLayout _captionLayout; 38 protected TextWidget _caption; 39 protected ImageButton _closeButton; 40 protected bool _showCloseButton; 41 protected HorizontalLayout _bodyLayout; 42 43 @property TextWidget caption() { return _caption; } 44 45 this(string ID, bool showCloseButton = true) { 46 super(ID); 47 _showCloseButton = showCloseButton; 48 initialize(); 49 } 50 51 Signal!OnClickHandler closeButtonClick; 52 protected bool onCloseButtonClick(Widget source) { 53 if (closeButtonClick.assigned) 54 closeButtonClick(source); 55 return true; 56 } 57 58 protected void initialize() { 59 60 styleId = STYLE_DOCK_WINDOW; 61 62 _captionLayout = new HorizontalLayout("DOCK_WINDOW_CAPTION_PANEL"); 63 _captionLayout.layoutWidth(FILL_PARENT).layoutHeight(WRAP_CONTENT); 64 _captionLayout.styleId = STYLE_DOCK_WINDOW_CAPTION; 65 66 _caption = new TextWidget("DOCK_WINDOW_CAPTION"); 67 _caption.styleId = STYLE_DOCK_WINDOW_CAPTION_LABEL; 68 69 _closeButton = new ImageButton("DOCK_WINDOW_CAPTION_CLOSE_BUTTON"); 70 _closeButton.styleId = STYLE_BUTTON_TRANSPARENT; 71 _closeButton.drawableId = "close"; 72 _closeButton.trackHover = true; 73 _closeButton.click = &onCloseButtonClick; 74 if (!_showCloseButton) 75 _closeButton.visibility = Visibility.Gone; 76 77 _captionLayout.addChild(_caption); 78 _captionLayout.addChild(_closeButton); 79 80 _bodyLayout = new HorizontalLayout(); 81 _bodyLayout.styleId = STYLE_DOCK_WINDOW_BODY; 82 83 _bodyWidget = createBodyWidget(); 84 _bodyLayout.addChild(_bodyWidget); 85 _bodyWidget.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); 86 //_bodyWidget.styleId = STYLE_DOCK_WINDOW_BODY; 87 88 addChild(_captionLayout); 89 addChild(_bodyLayout); 90 } 91 92 protected Widget createBodyWidget() { 93 return new Widget("DOCK_WINDOW_BODY"); 94 } 95 }