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