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