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.titlebar;
8 
9 /// A template that declares TitleBarWidget.
10 /// (for MdiClientWidget)
11 template TitleBar ()
12 {
13     protected class CloseButtonWidget : ButtonWidget
14     {
15         override void handleButtonPress ()
16         {
17             close();
18             super.handleButtonPress();
19         }
20         this ()
21         {
22             super();
23             style.box.paddings    = Rect(0.mm);
24             style.box.size.width  = 4.mm;
25             style.box.size.height = 4.mm;
26             setLayout!( GravityLayout, HorizontalLineupPlacer )( vec2(1,0) );
27         }
28     }
29 
30     protected class TitleBarWidget : PanelWidget
31     {
32         TextWidget        _title;
33         CloseButtonWidget _close;
34 
35         protected vec2 _cursorOffset;
36 
37         override bool handleMouseMove ( vec2 pos )
38         {
39             if ( super.handleMouseMove( pos ) ) return true;
40 
41             if ( isTracked ) {
42                 pos -= _host.style.clientLeftTop;
43                 move( pos - _cursorOffset );
44                 return true;
45             }
46             return false;
47         }
48 
49         override bool handleMouseButton ( MouseButton btn, bool status, vec2 pos )
50         {
51             if ( super.handleMouseButton(btn,status,pos) ) return true;
52 
53             if ( btn == MouseButton.Left && status ) {
54                 _cursorOffset = pos - style.translate;
55                 return true;
56             }
57             return false;
58         }
59 
60         this ()
61         {
62             super();
63 
64             style.box.size.width = Scalar.Auto;
65             setLayout!( FillLayout, HorizontalSplitPlacer );
66 
67             _title = new TextWidget;
68             addChild( _title );
69 
70             _close = new CloseButtonWidget;
71             addChild( _close );
72         }
73 
74         override @property bool trackable () { return true; }
75     }
76 }