1 module ui.Window; 2 3 import ui.Control; 4 5 import std.typecons: Tuple; 6 7 class Window : Control { 8 protected uiWindow * _window; 9 10 mixin EventListenerMixin!("OnPositionChanged", Window); 11 mixin EventListenerMixin!("OnContentSizeChanged", Window); 12 mixin EventListenerMixin!("OnClosing", Window, int); 13 14 public: 15 this(string title = "", int width = 240, int height = 180, bool hasMenubar = false) { 16 _window = uiNewWindow(title.ptr, width, height, cast(int) hasMenubar); 17 super(cast(uiControl *) _window); 18 19 uiWindowOnPositionChanged(_window, &OnPositionChangedCallback, cast(void*) this); 20 uiWindowOnContentSizeChanged(_window, &OnContentSizeChangedCallback, cast(void*) this); 21 uiWindowOnClosing(_window, &OnClosingCallback, cast(void *) this); 22 } 23 24 string title() { 25 return uiWindowTitle(_window).toString; 26 } 27 28 Window setTitle(string title) { 29 uiWindowSetTitle(_window, title.ptr); 30 return this; 31 } 32 33 auto position() { 34 auto pos = Tuple!(int, "x", int, "y")(); 35 uiWindowPosition(_window, &pos.x, &pos.y); 36 return pos; 37 } 38 39 Window setPosition(int x, int y) { 40 uiWindowSetPosition(_window, x, y); 41 return this; 42 } 43 44 Window center() { 45 uiWindowCenter(_window); 46 return this; 47 } 48 49 auto contentSize() { 50 auto size = Tuple!(int, "width", int, "height")(); 51 uiWindowContentSize(_window, &size.width, &size.height); 52 return size; 53 } 54 55 Window setContentSize(int width, int height) { 56 uiWindowSetContentSize(_window, width, height); 57 return this; 58 } 59 60 bool fullScreen() { 61 return cast(bool) uiWindowFullscreen(_window); 62 } 63 64 Window setFullScreen(bool fullscreen) { 65 uiWindowSetFullscreen(_window, cast(int) fullscreen); 66 return this; 67 } 68 69 bool borderless() { 70 return cast(bool) uiWindowBorderless(_window); 71 } 72 73 Window setBorderless(bool borderless) { 74 uiWindowSetBorderless(_window, cast(int) borderless); 75 return this; 76 } 77 78 Window setChild(Control child) { 79 if (child) { 80 _children ~= child; 81 child._parent = this; 82 uiWindowSetChild(_window, child._control); 83 } else { 84 uiWindowSetChild(_window, null); 85 } 86 return this; 87 } 88 89 bool margined() { 90 return cast(bool) uiWindowMargined(_window); 91 } 92 93 Window setMargined(bool margined) { 94 uiWindowSetMargined(_window, cast(int) margined); 95 return this; 96 } 97 98 string openFile() { 99 return uiOpenFile(_window).toString; 100 } 101 102 string saveFile() { 103 return uiSaveFile(_window).toString; 104 } 105 106 Window msgBox(string title, string discription) { 107 uiMsgBox(_window, title.ptr, discription.ptr); 108 return this; 109 } 110 111 Window msgBoxError(string title, string discription) { 112 uiMsgBoxError(_window, title.ptr, discription.ptr); 113 return this; 114 } 115 }