1 module formoshlep.window; 2 3 import dlangui; 4 5 class FormoshlepWindow : Window 6 { 7 private dstring caption; 8 9 debug 10 enum PRETTY_HTML_FORMAT = true; 11 else 12 enum PRETTY_HTML_FORMAT = false; 13 14 this(dstring caption) 15 { 16 this.caption = caption; 17 windowOrContentResizeMode = WindowOrContentResizeMode.shrinkWidgets; 18 super(); 19 20 //~ BT.open(caption.to!string); 21 22 // set background color: 23 { 24 //~ BT.bkcolor(backgroundColor); 25 //~ BT.clear(); 26 //~ BT.refresh(); 27 } 28 } 29 30 ~this() 31 { 32 close(); 33 } 34 35 import vibe.http.server: HTTPServerResponse; 36 37 package void genHttpServerResponse(ref HTTPServerResponse res) 38 { 39 res.writeBody 40 ( 41 PRETTY_HTML_FORMAT 42 ? toHtml.toPrettyString(false) 43 : toHtml.toString(false), 44 "text/html; charset=UTF-8" 45 ); 46 } 47 48 import dhtags.tags.tag: HtmlFragment, HtmlString; 49 50 private HtmlFragment toHtml() 51 { 52 import dhtags; 53 import std.conv: to; 54 55 assert(mainWidget !is null); 56 57 return 58 html 59 ( 60 head 61 ( 62 tags.title 63 ( 64 windowCaption().to!string 65 ), 66 tags.style(type="text/css") 67 ( 68 ".w100 {width: 100%}" 69 ) 70 ), 71 72 body_ 73 ( 74 tags.form(enctype="multipart/form-data", action=".", method="post") 75 ( 76 mainWidgetToHtml() 77 ) 78 ) 79 ); 80 } 81 82 private HtmlFragment mainWidgetToHtml() 83 { 84 import formoshlep.widget; 85 86 return mainWidget.toHtml; 87 } 88 89 override: 90 91 void close() 92 { 93 assert(false, __FUNCTION__~" isn't implemented"); 94 } 95 96 /// Displays window at the first time 97 void show() {} 98 99 dstring windowCaption() const @property 100 { 101 return caption; 102 } 103 104 void windowCaption(dstring caption) @property 105 { 106 this.caption = caption; 107 } 108 109 void windowIcon(DrawBufRef icon) @property 110 { 111 assert(false, __FUNCTION__~" isn't implemented"); 112 } 113 114 void invalidate() {} 115 }