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.root;
8 import w4d.parser.colorset,
9        w4d.style.color,
10        w4d.task.window,
11        w4d.widget.base,
12        w4d.widget.panel;
13 import g4d.glfw.cursor;
14 import gl3n.linalg;
15 
16 /// A widget to be placed root of all widgets.
17 class RootWidget : PanelWidget
18 {
19     ///
20     override @property const(Cursor) cursor ()
21     {
22         auto popup = _context.popup;
23         return popup? popup.cursor: super.cursor;
24     }
25 
26     ///
27     this ()
28     {
29         super();
30         _context = new WindowContext;
31 
32         parseColorSetsFromFile!"colorset/root.yaml"( style );
33     }
34 
35     ///
36     override @property bool needLayout ()
37     {
38         auto popup = _context.popup;
39         return (popup && popup.needLayout) || super.needLayout;
40     }
41     ///
42     override void layout ( vec2i size )
43     {
44         super.layout( size );
45 
46         auto popup = _context.popup;
47         if ( popup ) {
48             popup.layout( style.clientLeftTop, style.box.clientSize );
49         }
50     }
51 
52     ///
53     override @property bool needRedraw ()
54     {
55         auto popup = _context.popup;
56         return (popup && popup.needRedraw) || super.needRedraw;
57     }
58     protected void drawPopup ( Window w )
59     {
60         auto popup = _context.popup;
61         if ( !popup ) return;
62 
63         popup.draw( w );
64     }
65     ///
66     override void draw ( Window w, in ColorSet parent )
67     {
68         super.draw( w, parent );
69         drawPopup( w );
70     }
71 }