1 module ui.Control;
2 
3 public import ui.Core;
4 
5 class Control {
6     package uiControl *         _control;
7     package Control             _parent;
8     package Control[]           _children;
9 
10     protected this(uiControl *other) {
11         _control = other;
12     }
13 
14     uintptr_t handle() {
15         return uiControlHandle(_control);
16     }
17 
18     Control parent() {
19         return _parent;
20     }
21 
22     Control setParent(Control parent) {
23         if (_parent) {
24             import std.algorithm: remove;
25             _parent._children.remove!(e => e is this);
26         }
27         _parent = parent;
28         if (_parent) {
29             _parent._children ~= this;
30             uiControlSetParent(_control, parent._control);
31         } else {
32             uiControlSetParent(_control, null);
33         }
34         return this;
35     }
36 
37     bool topLevel() {
38         return cast(bool) uiControlToplevel(_control);
39     }
40 
41     bool visible() {
42         return cast(bool) uiControlVisible(_control);
43     }
44 
45     Control show() {
46         uiControlShow(_control);
47         return this;
48     }
49 
50     Control hide() {
51         uiControlHide(_control);
52         return this;
53     }
54 
55     bool enabled() {
56         return cast(bool) uiControlEnabled(_control);
57     }
58 
59     Control enable() {
60         uiControlEnable(_control);
61         return this;
62     }
63 
64     Control disable() {
65         uiControlDisable(_control);
66         return this;
67     }
68 
69     Control verifySetParent(Control other) {
70         // TODO: what is the meaning?
71         uiControlVerifySetParent(_control, other._control);
72         return this;
73     }
74 
75     bool enabledToUser() {
76         return cast(bool) uiControlEnabledToUser(_control);
77     }
78 }