1 // Written in the D programming language. 2 /++ 3 + Authors: KanzakiKino 4 + Copyright: KanzakiKino 2018 5 + License: LGPL-3.0 6 ++/ 7 module w4d.widget.mdi.client; 8 import w4d.layout.gravity, 9 w4d.layout.lineup, 10 w4d.layout.split, 11 w4d.parser.colorset, 12 w4d.style.rect, 13 w4d.style.scalar, 14 w4d.task.window, 15 w4d.widget.mdi.host, 16 w4d.widget.mdi.titlebar, 17 w4d.widget.mdi.window, 18 w4d.widget.base, 19 w4d.widget.button, 20 w4d.widget.panel, 21 w4d.widget.text, 22 w4d.exception; 23 import g4d.ft.font, 24 g4d.glfw.cursor; 25 import gl3n.linalg; 26 import std.algorithm; 27 28 /// A client widget for MDI. 29 class MdiClientWidget : PanelWidget, MdiClient 30 { 31 mixin TitleBar; 32 33 protected MdiHostWidget _host; 34 35 protected TitleBarWidget _titlebar; 36 37 protected PanelWidget _contents; 38 /// Contents widget. 39 @property contents () { return _contents; } 40 41 /// 42 this () 43 { 44 super(); 45 46 _host = null; 47 48 _titlebar = new TitleBarWidget; 49 addChild( _titlebar ); 50 51 _contents = new PanelWidget; 52 _contents.style.box.size.width = Scalar.Auto; 53 _contents.style.box.size.height = Scalar.Auto; 54 addChild( _contents ); 55 56 _maxSize = vec2(int.max,int.max); 57 _minSize = vec2(0,0); 58 59 _pos = vec2(0,0); 60 _size = vec2(320,240); 61 62 parseColorSetsFromFile!"colorset/mdiclient.yaml"( style ); 63 style.box.paddings = Rect(1.mm); 64 style.box.borderWidth = Rect(1.pixel); 65 setLayout!VerticalSplitLayout; 66 } 67 68 mixin WindowOperations; 69 70 /// 71 @property Widget widget () 72 { 73 return cast(Widget) this; 74 } 75 /// 76 void setHost ( MdiHostWidget host ) 77 { 78 _host = host; 79 } 80 81 /// Changes title text. 82 void loadText ( dstring v, FontFace face = null ) 83 { 84 _titlebar._title.loadText( v, face ); 85 } 86 87 /// 88 override void requestLayout () 89 { 90 super.requestLayout(); 91 requestRedraw(); 92 } 93 /// 94 override vec2 layout ( vec2 basept, vec2 size ) 95 { 96 _size.x = _size.x.clamp( minSize.x, min( maxSize.x, size.x ) ); 97 _size.y = _size.y.clamp( minSize.y, min( maxSize.y, size.y ) ); 98 99 _pos.x = _pos.x.clamp( 0, size.x-_size.x ); 100 _pos.y = _pos.y.clamp( 0, size.y-_size.y ); 101 102 return super.layout( basept+_pos, _size ); 103 } 104 105 /// 106 override @property bool trackable () { return true; } 107 }