annotate mde/gui/widget/ParentContent.d @ 163:24d77c52243f

Provided sensible conversions for setting the value of one AStringContent from another, along with unittest. Updated layout and Translation unittests to run.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 23 May 2009 15:47:32 +0200
parents 2476790223b8
children bb2f1a76346d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
16 /******************************************************************************
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
17 * A pop-up widget, a switch (tab) widget, and a collapsible widget
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
18 * (all parent widgets using content).
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
19 *
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
20 * Also a border widget (parent not using content).
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
21 *****************************************************************************/
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
22 module mde.gui.widget.ParentContent;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
24 import mde.gui.widget.AParentWidget;
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
25 import mde.gui.widget.layout;
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
26 import mde.content.AStringContent;
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
27 import mde.gui.exception;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
29 debug {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
30 import tango.util.log.Log : Log, Logger;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
31 private Logger logger;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
32 static this () {
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
33 logger = Log.getLogger ("mde.gui.widget.ParentContent");
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
34 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
35 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
36
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
37 /******************************************************************************
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
38 * Widget which pops up a ContentListWidget created with its content.
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
39 *
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
40 * Is a button displaying a content string, just like DisplayContentWidget.
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
41 *
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
42 * Popped up widget is a ContentListWidget created from the same creation data.
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
43 *****************************************************************************/
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
44 class PopupMenuWidget : APopupParentWidget
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 {
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
46 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
47 content_ = cast(Content)c;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
48 WDCMinCheck (data, 3,1, content_);
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
49 super (mgr, parent, id);
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
50
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
51 //popup = mgr.makeWidget (this, data.strings[0], content_);
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
52 popup = new ContentListWidget (mgr, this, id, data, c);
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
53 subWidgets = [popup];
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
54
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
55 cIndex = data.ints[2];
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
56 if (cIndex == 0)
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
57 content_.addCallback (&updateVal);
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
58 adapter = mgr.renderer.getAdapter;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
59 adapter.text = content_.toString (cIndex);
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
60 adapter.getDimensions (mw, mh);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
61 w = mw;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
62 h = mh;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
63 }
158
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
64 /+
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
65 override bool setup (uint n, uint flags) {
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
66 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
67 wdim omw = mw, omh = mh;
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
68 adapter.getDimensions (mw, mh);
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
69 if (omw != mw || omh != mh) {
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
70 w = mw;
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
71 h = mh;
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
72 return true;
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
73 }
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
74 return false;
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
75 }
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
76 +/
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
77 override IContent content () {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
78 return content_;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
79 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
80
162
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 158
diff changeset
81 override bool dropContent (IContent content) {
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
82 if (content_.set (content))
162
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 158
diff changeset
83 return true;
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 158
diff changeset
84 return parent.dropContent (content);
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 158
diff changeset
85 }
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 158
diff changeset
86
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
87 override void recursionCheck (widgetID wID, IContent c) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
88 if (wID is id && c is content_)
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
89 throw new WidgetRecursionException (wID);
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
90 parent.recursionCheck (wID, c);
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
91 }
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
92
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
93 override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
94 if (b == 1 && state == true) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
95 if (!pushed) {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
96 parentIPPW.addChildIPPW (this);
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
97 parentIPPW.menuActive = mgr.positionPopup (this, popup);
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
98 pushed = true;
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
99 } else if (!parentIPPW.parentMenuActive) { // if not a submenu
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
100 parentIPPW.removeChildIPPW (this);
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
101 }
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
102 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
103 return 0;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
104 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
105
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
106 override void removedIPPW () {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
107 super.removedIPPW;
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
108 pushed = false;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
109 }
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
110
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
111 override void underMouse (bool state) {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
112 if (state && !pushed && parentIPPW.menuActive) {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
113 parentIPPW.addChildIPPW (this);
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
114 menuActive = mgr.positionPopup (this, popup, parentIPPW.parentMenuActive);
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
115 pushed = true;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
116 }
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
117 }
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
118
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
119 override void draw () {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
120 mgr.renderer.drawButton (x,y, w,h, pushed);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
121 adapter.draw (x,y);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
122 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
123
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
124 protected:
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
125 void updateVal (Content) { // callback
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
126 adapter.text = content_.toString(cIndex);
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
127 wdim omw = mw, omh = mh;
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
128 adapter.getDimensions (mw, mh);
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
129 if (omw != mw)
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
130 parent.minWChange (this, mw);
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
131 if (omh != mh)
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
132 parent.minHChange (this, mh);
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
133 }
158
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
134
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
135 bool pushed = false;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
136 IRenderer.TextAdapter adapter;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
137 Content content_;
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
138 int cIndex;
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
139 }
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
140
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
141 /** A "tab" widget: it doesn't display the tabs, but shows one of a number of
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
142 * widgets dependant on an EnumContent.
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
143 *
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
144 * Sizability is set once. Min-size is updated when switching. */
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
145 class SwitchWidget : AParentWidget
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
146 {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
147 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
148 super (mgr, parent, id);
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
149 content_ = cast(EnumContent) c;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
150 if (content_ is null || (subWidgets.length = content_.list.length) == 0)
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
151 throw new ContentException (this);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
152 WDCheck (data, 1, subWidgets.length);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
153
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
154 foreach (i,sc; content_.list)
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
155 subWidgets[i] = mgr.makeWidget (this, data.strings[i], sc);
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
156 currentW = subWidgets[content_()];
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
157
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
158 content_.addCallback (&switchWidget);
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
159 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
160
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
161 override IContent content () {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
162 return content_;
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
163 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
164
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
165 override bool setup (uint n, uint flags) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
166 bool r = super.setup (n, flags);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
167 if (r) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
168 mw = currentW.minWidth;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
169 mh = currentW.minHeight;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
170 w = currentW.width;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
171 h = currentW.height;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
172 static if (SIZABILITY & SIZABILITY_ENUM.START_TRUE)
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
173 isWS = isHS = true;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
174 foreach (i,sc; content_.list) {
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
175 static if (SIZABILITY == SIZABILITY_ENUM.ANY_SUBWIDGETS) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
176 isWS |= subWidgets[i].isWSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
177 isHS |= subWidgets[i].isHSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
178 } else static if (SIZABILITY == SIZABILITY_ENUM.ALL_SUBWIDGETS) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
179 isWS &= subWidgets[i].isWSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
180 isHS &= subWidgets[i].isHSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
181 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
182 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
183 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
184 return r;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
185 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
186
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
187 override void minWChange (IChildWidget widget, wdim nmw) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
188 if (widget !is currentW) return;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
189 mw = nmw;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
190 parent.minWChange (this, nmw);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
191 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
192 override void minHChange (IChildWidget widget, wdim nmh) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
193 if (widget !is currentW) return;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
194 mh = nmh;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
195 parent.minHChange (this, nmh);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
196 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
197
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
198 override bool isWSizable () {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
199 return isWS;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
200 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
201 override bool isHSizable () {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
202 return isHS;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
203 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
204
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
205 override void setWidth (wdim nw, int dir) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
206 w = (nw >= mw ? nw : mw);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
207 currentW.setWidth (w, dir);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
208 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
209 override void setHeight (wdim nh, int dir) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
210 h = (nh >= mh ? nh : mh);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
211 currentW.setHeight (h, dir);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
212 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
213
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
214 override void setPosition (wdim nx, wdim ny) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
215 x = nx;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
216 y = ny;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
217 currentW.setPosition (nx,ny);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
218 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
219
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
220 override IChildWidget getWidget (wdim cx, wdim cy) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
221 return currentW.getWidget (cx, cy);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
222 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
223
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
224 override void draw () {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
225 currentW.draw;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
226 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
227
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
228 protected:
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
229 // callback on content_
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
230 void switchWidget (Content) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
231 currentW = subWidgets[content_()];
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
232 mw = currentW.minWidth;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
233 mh = currentW.minHeight;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
234 parent.minWChange (this, mw);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
235 parent.minHChange (this, mh);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
236 // Parent may change size. If it doesn't, we must set child's size.
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
237 // We can't tell if it did, so do it (call will be fast if size isn't
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
238 // changed anyway).
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
239 currentW.setWidth (w, -1);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
240 currentW.setHeight (h, -1);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
241 currentW.setPosition (x,y);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
242 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
243
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
244 IChildWidget currentW;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
245 EnumContent content_;
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
246
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
247 bool isWS, isHS; // no infrastructure for changing sizability, so need to fix it.
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
248 }
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
249
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
250 /** A collapsible widget: shows/hides a child dependant on a BoolContent.
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
251 *
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
252 * Sizability is set once. Min-size is changed (but cannot force size to 0).
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
253 *
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
254 * Uses its content as a switch, which means content cannot be passed through.
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
255 * A builtin button would improve this. */
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
256 class CollapsibleWidget : AParentWidget
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
257 {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
258 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
259 super (mgr, parent, id);
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
260 content_ = cast(BoolContent) c;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
261 WDCCheck (data, 1, 1, content_);
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
262
155
4e8819b65882 Changed collapsible widget in GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
263 subWidgets = [mgr.makeWidget (this, data.strings[0], c)];
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
264
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
265 content_.addCallback (&collapse);
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
266 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
267
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
268 override bool setup (uint n, uint flags) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
269 bool r = super.setup (n, flags);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
270 if (r) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
271 collapsed = content_();
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
272 if (!collapsed) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
273 mw = subWidgets[0].minWidth;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
274 mh = subWidgets[0].minHeight;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
275 w = subWidgets[0].width;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
276 h = subWidgets[0].height;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
277 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
278 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
279 return r;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
280 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
281
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
282 override IContent content () {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
283 return content_;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
284 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
285
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
286 override void minWChange (IChildWidget widget, wdim nmw) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
287 debug assert (widget is subWidgets[0]);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
288 mw = nmw;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
289 parent.minWChange (this, nmw);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
290 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
291 override void minHChange (IChildWidget widget, wdim nmh) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
292 debug assert (widget is subWidgets[0]);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
293 mh = nmh;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
294 parent.minHChange (this, nmh);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
295 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
296
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
297 // Doesn't change:
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
298 override bool isWSizable () {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
299 return subWidgets[0].isWSizable;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
300 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
301 override bool isHSizable () {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
302 return subWidgets[0].isHSizable;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
303 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
304
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
305 override void setWidth (wdim nw, int dir) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
306 w = (nw >= mw ? nw : mw);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
307 if (!collapsed) subWidgets[0].setWidth (w, dir);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
308 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
309 override void setHeight (wdim nh, int dir) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
310 h = (nh >= mh ? nh : mh);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
311 if (!collapsed) subWidgets[0].setHeight (h, dir);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
312 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
313
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
314 override void setPosition (wdim nx, wdim ny) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
315 x = nx;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
316 y = ny;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
317 if (!collapsed) subWidgets[0].setPosition (nx,ny);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
318 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
319
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
320 override IChildWidget getWidget (wdim cx, wdim cy) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
321 if (!collapsed)
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
322 return subWidgets[0].getWidget (cx, cy);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
323 else return this;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
324 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
325
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
326 override void draw () {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
327 if (!collapsed) subWidgets[0].draw;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
328 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
329
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
330 protected:
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
331 // callback on content_
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
332 void collapse (Content) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
333 collapsed = content_();
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
334 if (collapsed) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
335 mw = mh = 0;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
336 } else {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
337 mw = subWidgets[0].minWidth;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
338 mh = subWidgets[0].minHeight;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
339 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
340 parent.minWChange (this, mw);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
341 parent.minHChange (this, mh);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
342 if (collapsed) return;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
343 // set incase parent didn't:
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
344 subWidgets[0].setWidth (w, -1);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
345 subWidgets[0].setHeight (h, -1);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
346 subWidgets[0].setPosition (x,y);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
347 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
348
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
349 bool collapsed = false;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
350 BoolContent content_;
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
351 }
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
352
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
353 /** Puts a border around its child widget.
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
354 *
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
355 * This doesn't allow dragging like widgets in a floating area.
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
356 *
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
357 * data.ints[1] is interpreted as flags from IRenderer.Border.BTYPE.
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
358 * data.strings[0] is an ID for the child widget. */
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
359 class BorderWidget : AParentWidget
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
360 {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
361 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
362 super (mgr, parent, id);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
363 WDCheck (data, 2, 1);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
364
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
365 subWidgets = [mgr.makeWidget (this, data.strings[0], c)];
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
366 borderType = cast(BTYPE) data.ints[1];
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
367 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
368
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
369 override bool setup (uint n, uint flags) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
370 if (!subWidgets[0].setup (n, flags) && !(flags & 1)) return false;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
371
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
372 border = mgr.renderer.getBorder (borderType, false, false);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
373 mw = subWidgets[0].minWidth + border.x1 + border.x2;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
374 mh = subWidgets[0].minHeight + border.y1 + border.y2;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
375 if (w < mw || !subWidgets[0].isWSizable) w = mw;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
376 if (h < mh || !subWidgets[0].isHSizable) h = mh;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
377 return true;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
378 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
379
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
380 override void setWidth (wdim nw, int) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
381 debug assert (nw >= mw);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
382 w = nw;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
383 subWidgets[0].setWidth (w - border.x1 - border.x2, -1);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
384 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
385 override void setHeight (wdim nh, int) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
386 debug assert (nh >= mh);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
387 h = nh;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
388 subWidgets[0].setHeight (h - border.y1 - border.y2, -1);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
389 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
390
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
391 override bool isWSizable () {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
392 return subWidgets[0].isWSizable;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
393 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
394 override bool isHSizable () {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
395 return subWidgets[0].isHSizable;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
396 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
397
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
398 override void setPosition (wdim nx, wdim ny) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
399 x = nx;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
400 y = ny;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
401 subWidgets[0].setPosition (x + border.x1, y + border.y1);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
402 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
403
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
404 override void minWChange (IChildWidget widget, wdim nmw) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
405 debug assert (widget is subWidgets[0]);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
406 mw = nmw + border.x1 + border.x2;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
407 parent.minWChange (this, nmw);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
408 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
409 override void minHChange (IChildWidget widget, wdim nmh) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
410 debug assert (widget is subWidgets[0]);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
411 mh = nmh + border.y1 + border.y2;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
412 parent.minHChange (this, nmh);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
413 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
414
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
415 override void draw () {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
416 mgr.renderer.drawBorder (&border, x, y, w, h);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
417 subWidgets[0].draw;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
418 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
419
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
420 override IChildWidget getWidget (wdim cx, wdim cy) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
421 debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)");
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
422
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
423 if (subWidgets[0].onSelf (cx, cy))
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
424 return subWidgets[0];
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
425 else
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
426 return this;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
427 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
428
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
429 protected:
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
430 alias IRenderer.Border.BTYPE BTYPE;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
431 alias IRenderer.Border.RESIZE RESIZE;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
432 BTYPE borderType; // what type of border to put around the widget
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
433 IRenderer.Border border;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
434 }