egra: new "hotlabel" widget; removed built-in title from single-line editor
[iv.d.git] / egra / test.d
blob1076535e936901f25a469634ba8bc9e442933df9
1 /* E-Mail Client
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module test /*is aliced*/;
19 import arsd.simpledisplay;
21 import iv.cmdcon;
22 import iv.cmdcongl;
23 import iv.strex;
24 import iv.utfutil;
25 import iv.vfs.io;
26 import iv.vfs.util;
28 import iv.egra;
31 // ////////////////////////////////////////////////////////////////////////// //
32 static immutable string TestStyle = `
33 MainPaneWindow {
34 grouplist-divline: white;
35 grouplist-back: #222;
37 threadlist-divline: white;
38 threadlist-back: #222;
41 TitlerWindow {
42 frame: white;
43 title-back: @frame;
44 title-text: black;
46 back: rgb(0, 92, 0);
47 text: #7f0;
52 // ////////////////////////////////////////////////////////////////////////// //
53 //__gshared int lastWinWidth, lastWinHeight;
56 // ////////////////////////////////////////////////////////////////////////// //
57 public class TitlerWindow : SubWindow {
58 public:
59 LineEditWidget edtTitle;
60 LineEditWidget fromName;
61 LineEditWidget fromMail;
63 protected:
64 string name;
65 string mail;
66 string folder;
67 string title;
69 bool delegate (const(char)[] name, const(char)[] mail, const(char)[] folder, const(char)[] title) onSelected;
71 override void createWidgets () {
72 new SpacerWidget(2);
74 version(none) {
75 fromName = new LineEditWidget("Name:");
76 fromName.flex = 1;
78 new SpacerWidget(1);
79 fromMail = new LineEditWidget("Mail:");
80 fromMail.flex = 1;
82 new SpacerWidget(1);
83 edtTitle = new LineEditWidget("Title:");
84 edtTitle.flex = 1;
85 } else {
86 (new HBoxWidget).enter{
87 with (new HotLabelWidget("&Name:", LabelWidget.HAlign.Right)) { width = width+2; hsizeId = "editors"; }
88 new SpacerWidget(4);
89 fromName = new LineEditWidget();
90 fromName.flex = 1;
91 }.flex = 1;
93 new SpacerWidget(1);
94 (new HBoxWidget).enter{
95 with (new HotLabelWidget("&Mail:", LabelWidget.HAlign.Right)) { width = width+2; hsizeId = "editors"; }
96 new SpacerWidget(4);
97 fromMail = new LineEditWidget();
98 fromMail.flex = 1;
99 }.flex = 1;
101 new SpacerWidget(1);
102 (new HBoxWidget).enter{
103 with (new HotLabelWidget("&Title:", LabelWidget.HAlign.Right)) { width = width+2; hsizeId = "editors"; }
104 new SpacerWidget(4);
105 edtTitle = new LineEditWidget();
106 edtTitle.flex = 1;
107 }.flex = 1;
110 new SpacerWidget(2);
112 fromName.str = name;
113 fromMail.str = mail;
114 edtTitle.str = title;
117 int twdt = fromName.titwdt;
118 if (twdt < fromMail.titwdt) twdt = fromMail.titwdt;
119 if (twdt < edtTitle.titwdt) twdt = edtTitle.titwdt;
120 fromName.titwdt = twdt;
121 fromMail.titwdt = twdt;
122 edtTitle.titwdt = twdt;
125 relayoutResize();
126 centerWindow();
128 edtTitle.focus();
131 this (string aname, string amail, string afolder, string atitle) {
132 string caption = "Title for "~aname~" <"~amail~">";
133 name = aname;
134 mail = amail;
135 folder = afolder;
136 title = atitle;
137 super(caption);
140 override bool onKeyBubble (KeyEvent event) {
141 if (event.pressed) {
142 if (event == "Escape" /*|| event == "C-Q"*/) { close(); return true; }
143 if (event == "Enter") {
144 if (onSelected !is null) {
145 if (!onSelected(fromName.str, fromMail.str, folder, edtTitle.str)) return true;
147 close();
148 return true;
151 return super.onKeyBubble(event);
156 // ////////////////////////////////////////////////////////////////////////// //
157 public class TagOptionsWindow : SubWindow {
158 LabelWidget optPath; // real path
159 LineEditWidget optMonthes;
160 CheckboxWidget optThreaded;
161 CheckboxWidget optAttaches;
162 string tagname;
164 void delegate (const(char)[] tagname) onUpdated;
166 this (string atagname) {
167 tagname = atagname;
168 string caption = "options for '"~atagname~"'";
169 super(caption);
172 override void createWidgets () {
173 optPath = new LabelWidget("", LabelWidget.HAlign.Center);
174 optPath.flex = 1;
176 version(none) {
177 optMonthes = new LineEditWidget("Monthes:");
178 optMonthes.flex = 1;
179 optMonthes.width = optMonthes.titwdt+64;
180 } else {
181 (new HBoxWidget).enter{
182 with (new HotLabelWidget("&Monthes:", LabelWidget.HAlign.Right)) { width = width+2; /*hsizeId = "editors";*/ }
183 new SpacerWidget(4);
184 optMonthes = new LineEditWidget();
185 //optMonthes.flex = 1;
186 optMonthes.width = gxTextWidthUtf("96669");
187 //new SpringWidget(1);
188 }.flex = 1;
191 optThreaded = new CheckboxWidget("&Threaded");
192 optThreaded.flex = 1;
194 optAttaches = new CheckboxWidget("&Attaches");
195 optAttaches.flex = 1;
197 optMonthes.focus();
199 optPath.text = "booPath";
200 optMonthes.str = "666";
202 optThreaded.enabled = false;
203 optAttaches.enabled = true;
205 optMonthes.killTextOnChar = true;
207 relayoutResize();
208 centerWindow();
211 override bool onKeyBubble (KeyEvent event) {
212 if (event.pressed) {
213 if (event == "Escape" /*|| event == "C-Q"*/) { close(); return true; }
214 if (event == "Enter") {
215 if (onUpdated !is null) onUpdated(tagname);
216 close();
217 return true;
220 return super.onKeyBubble(event);
224 // ////////////////////////////////////////////////////////////////////////// //
225 void initConsole () {
226 // //////////////////////////////////////////////////////////////////// //
227 conRegFunc!(() {
228 import core.memory : GC;
229 conwriteln("starting GC collection...");
230 GC.collect();
231 GC.minimize();
232 conwriteln("GC collection complete.");
233 })("gc_collect", "force GC collection cycle");
236 // //////////////////////////////////////////////////////////////////// //
237 conRegFunc!(() {
238 auto qww = new YesNoWindow("Quit?", "Do you really want to quit?", true);
239 qww.onYes = () { concmd("quit"); };
240 qww.addModal();
241 })("quit_prompt", "quit with prompt");
243 conRegFunc!(() {
244 new TitlerWindow("name", "mail", "folder", "title");
245 })("window_titler", "titler window test");
247 conRegFunc!(() {
248 new TagOptionsWindow("xtag");
249 })("window_tagoptions", "tag options window test");
253 // ////////////////////////////////////////////////////////////////////////// //
254 __gshared MainPaneWindow mainPane;
257 final class MainPaneWindow : SubWindow {
258 ProgressBarWidget pbar;
260 this () {
261 super(null, GxPoint(0, 0), GxSize(screenWidth, screenHeight));
262 mType = Type.OnBottom;
264 pbar = new ProgressBarWidget(rootWidget, "progress bar");
265 pbar.setMinMax(0, 100);
266 pbar.width = clientWidth-64;
267 pbar.current = 50;
268 pbar.posy = clientHeight-pbar.height-8;
269 pbar.posx = (clientWidth-pbar.width)/2;
271 add();
274 // //////////////////////////////////////////////////////////////////// //
275 override void onPaint () {
276 if (closed) return;
278 enum guiGroupListWidth = 128;
279 enum guiThreadListHeight = 520;
281 gxFillRect(0, 0, guiGroupListWidth, screenHeight, getColor("grouplist-back"));
282 gxVLine(guiGroupListWidth, 0, screenHeight, getColor("grouplist-divline"));
284 gxFillRect(guiGroupListWidth+1, 0, screenWidth, guiThreadListHeight, getColor("threadlist-back"));
285 gxHLine(guiGroupListWidth+1, guiThreadListHeight, screenWidth, getColor("threadlist-divline"));
287 version(test_round_rect) {
288 gxClipReset();
289 gxFillRoundedRect(lastMouseX-16, lastMouseY-16, 128, 96, rrad, /*gxSolidWhite*/gxRGBA!(0, 255, 0, 127));
290 //gxDrawRoundedRect(lastMouseX-16, lastMouseY-16, 128, 96, rrad, gxRGBA!(0, 255, 0, 127));
293 drawWidgets();
296 version(test_round_rect) {
297 int rrad = 16;
300 override bool onKeyBubble (KeyEvent event) {
301 if (event.pressed) {
302 version(test_round_rect) {
303 if (event == "Plus") { ++rrad; return true; }
304 if (event == "Minus") { --rrad; return true; }
306 if (event == "C-Q") { concmd("quit_prompt"); return true; }
307 if (event == "1") { concmd("window_titler"); return true; }
308 if (event == "2") { concmd("window_tagoptions"); return true; }
309 if (event == "Minus") { pbar.current = pbar.current-1; return true; }
310 if (event == "Plus") { pbar.current = pbar.current+1; return true; }
311 //if (dbg_dump_keynames) conwriteln("key: ", event.toStr, ": ", event.modifierState&ModifierState.windows);
312 //foreach (const ref kv; mainAppKeyBindings.byKeyValue) if (event == kv.key) concmd(kv.value);
314 return false;
317 // returning `false` to avoid screen rebuilding by dispatcher
318 override bool onMouseBubble (MouseEvent event) {
319 if (event.type == MouseEventType.buttonPressed || event.type == MouseEventType.buttonReleased) {
320 postScreenRebuild();
321 } else {
322 // for OpenGL, this rebuilds the whole screen anyway
323 postScreenRepaint();
325 return false;
330 // ////////////////////////////////////////////////////////////////////////// //
331 void main (string[] args) {
332 defaultColorStyle.parseStyle(TestStyle);
333 //egraDefaultFontSize = 48;
335 glconAllowOpenGLRender = false;
337 sdpyWindowClass = "EGUITest";
338 //glconShowKey = "M-Grave";
340 initConsole();
342 conProcessQueue();
343 conProcessArgs!true(args);
345 egraCreateSystemWindow("EGRA Test", allowResize:false);
347 vbwin.addEventListener((QuitEvent evt) {
348 if (vbwin.closed) return;
349 if (isQuitRequested) { vbwin.close(); return; }
350 vbwin.close();
353 static if (is(typeof(&vbwin.closeQuery))) {
354 vbwin.closeQuery = delegate () { concmd("quit"); egraPostDoConCommands(); };
357 mainPane = new MainPaneWindow();
358 //egraSkipScreenClear = true; // main pane is fullscreen
360 postScreenRebuild();
361 repostHideMouse();
363 vbwin.eventLoop(1000*10,
364 delegate () {
365 egraProcessConsole();
367 delegate (KeyEvent event) {
368 if (egraOnKey(event)) return;
370 delegate (MouseEvent event) {
371 if (egraOnMouse(event)) return;
373 delegate (dchar ch) {
374 if (egraOnChar(ch)) return;
378 flushGui();
379 conProcessQueue(int.max/4);