annotate mde/gui/widget/ParentContent.d @ 170:e45226d3deae

Context menu services not applicable to the current type can now be hidden. Added files missing from previous commits.
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 29 Jun 2009 21:20:16 +0200
parents da8d3091fdaf
children 0dd49f333189
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
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
51 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
52 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
53
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
54 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
55 if (cIndex == 0)
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
56 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
57 adapter = mgr.renderer.getAdapter;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
58 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
59 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
60 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
61 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
62 }
165
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
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 override bool setup (uint n, uint flags) {
165
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
65 bool ret = super.setup (n, flags);
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
66 if (!(flags & 3)) return ret;
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
67 // else string or renderer (and possibly font) changed
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
68 adapter.text = content_.toString (cIndex);
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
69 wdim omw = mw, omh = mh;
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
70 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
71 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
72 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
73 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
74 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
75 }
165
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
76 return ret;
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
77 }
165
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
78
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
79 override IContent content () {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
80 return content_;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
81 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
82
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 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
84 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
85 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
86 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
87 }
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
88
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
89 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
90 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
91 throw new WidgetRecursionException (wID);
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
92 parent.recursionCheck (wID, c);
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
93 }
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
94
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
95 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
96 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
97 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
98 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
99 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
100 pushed = true;
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
101 } 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
102 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
103 }
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
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 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
106 }
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
107
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
108 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
109 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
110 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
111 }
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
112
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 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
114 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
115 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
116 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
117 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
118 }
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
119 }
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
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
121 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
122 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
123 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
124 }
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
125
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
126 protected:
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
127 void updateVal (IContent) { // callback
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 }
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
136
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
137 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
138 IRenderer.TextAdapter adapter;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
139 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
140 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
141 }
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
142
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
143 /** 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
144 * widgets dependant on an EnumContent.
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
145 *
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
146 * 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
147 class SwitchWidget : AParentWidget
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
148 {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
149 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
150 super (mgr, parent, id);
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
151 content_ = cast(EnumContent) c;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
152 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
153 throw new ContentException (this);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
154 WDCheck (data, 1, subWidgets.length);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
155
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
156 foreach (i,sc; content_.list)
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
157 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
158 currentW = subWidgets[content_()];
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
159
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
160 content_.addCallback (&switchWidget);
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
161 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
162
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
163 override IContent content () {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
164 return content_;
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
165 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
166
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
167 override bool setup (uint n, uint flags) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
168 bool r = super.setup (n, flags);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
169 if (r) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
170 mw = currentW.minWidth;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
171 mh = currentW.minHeight;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
172 w = currentW.width;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
173 h = currentW.height;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
174 static if (SIZABILITY & SIZABILITY_ENUM.START_TRUE)
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
175 isWS = isHS = true;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
176 foreach (i,sc; content_.list) {
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
177 static if (SIZABILITY == SIZABILITY_ENUM.ANY_SUBWIDGETS) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
178 isWS |= subWidgets[i].isWSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
179 isHS |= subWidgets[i].isHSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
180 } else static if (SIZABILITY == SIZABILITY_ENUM.ALL_SUBWIDGETS) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
181 isWS &= subWidgets[i].isWSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
182 isHS &= subWidgets[i].isHSizable;
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 }
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 return r;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
187 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
188
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
189 override void recursionCheck (widgetID wID, IContent c) {
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
190 if (wID is id && c is content_)
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
191 throw new WidgetRecursionException (wID);
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
192 parent.recursionCheck (wID, c);
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
193 }
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
194
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
195 override void minWChange (IChildWidget widget, wdim nmw) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
196 if (widget !is currentW) return;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
197 mw = nmw;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
198 parent.minWChange (this, nmw);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
199 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
200 override void minHChange (IChildWidget widget, wdim nmh) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
201 if (widget !is currentW) return;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
202 mh = nmh;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
203 parent.minHChange (this, nmh);
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
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
206 override bool isWSizable () {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
207 return isWS;
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 bool isHSizable () {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
210 return isHS;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
211 }
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 override void setWidth (wdim nw, int dir) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
214 w = (nw >= mw ? nw : mw);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
215 currentW.setWidth (w, dir);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
216 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
217 override void setHeight (wdim nh, int dir) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
218 h = (nh >= mh ? nh : mh);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
219 currentW.setHeight (h, dir);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
220 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
221
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
222 override void setPosition (wdim nx, wdim ny) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
223 x = nx;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
224 y = ny;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
225 currentW.setPosition (nx,ny);
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 override IChildWidget getWidget (wdim cx, wdim cy) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
229 return currentW.getWidget (cx, cy);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
230 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
231
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
232 override void draw () {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
233 currentW.draw;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
234 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
235
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
236 protected:
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
237 // callback on content_
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
238 void switchWidget (IContent) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
239 currentW = subWidgets[content_()];
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
240 mw = currentW.minWidth;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
241 mh = currentW.minHeight;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
242 parent.minWChange (this, mw);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
243 parent.minHChange (this, mh);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
244 // 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
245 // 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
246 // changed anyway).
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
247 currentW.setWidth (w, -1);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
248 currentW.setHeight (h, -1);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
249 currentW.setPosition (x,y);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
250 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
251
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
252 IChildWidget currentW;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
253 EnumContent content_;
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
254
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
255 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
256 }
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
257
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
258 /** A collapsible widget: shows/hides a child dependant on an IBoolContent.
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
259 *
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
260 * 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
261 *
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
262 * 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
263 * A builtin button would improve this. */
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
264 class CollapsibleWidget : AParentWidget
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
265 {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
266 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
267 super (mgr, parent, id);
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
268 content_ = cast(IBoolContent) c;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
269 WDCCheck (data, 1, 1, content_);
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
270
155
4e8819b65882 Changed collapsible widget in GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
271 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
272
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
273 content_.addCallback (&collapse);
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
274 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
275
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
276 override bool setup (uint n, uint flags) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
277 bool r = super.setup (n, flags);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
278 if (r) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
279 collapsed = content_();
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
280 if (!collapsed) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
281 mw = subWidgets[0].minWidth;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
282 mh = subWidgets[0].minHeight;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
283 w = subWidgets[0].width;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
284 h = subWidgets[0].height;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
285 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
286 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
287 return r;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
288 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
289
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
290 override void recursionCheck (widgetID wID, IContent c) {
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
291 if (wID is id && c is content_)
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
292 throw new WidgetRecursionException (wID);
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
293 parent.recursionCheck (wID, c);
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
294 }
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
295
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
296 override IContent content () {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
297 return content_;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
298 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
299
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
300 override void minWChange (IChildWidget widget, wdim nmw) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
301 debug assert (widget is subWidgets[0]);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
302 mw = nmw;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
303 parent.minWChange (this, nmw);
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 minHChange (IChildWidget widget, wdim nmh) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
306 debug assert (widget is subWidgets[0]);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
307 mh = nmh;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
308 parent.minHChange (this, nmh);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
309 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
310
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
311 // Doesn't change:
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
312 override bool isWSizable () {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
313 return subWidgets[0].isWSizable;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
314 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
315 override bool isHSizable () {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
316 return subWidgets[0].isHSizable;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
317 }
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 override void setWidth (wdim nw, int dir) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
320 w = (nw >= mw ? nw : mw);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
321 if (!collapsed) subWidgets[0].setWidth (w, dir);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
322 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
323 override void setHeight (wdim nh, int dir) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
324 h = (nh >= mh ? nh : mh);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
325 if (!collapsed) subWidgets[0].setHeight (h, dir);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
326 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
327
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
328 override void setPosition (wdim nx, wdim ny) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
329 x = nx;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
330 y = ny;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
331 if (!collapsed) subWidgets[0].setPosition (nx,ny);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
332 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
333
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
334 override IChildWidget getWidget (wdim cx, wdim cy) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
335 if (!collapsed)
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
336 return subWidgets[0].getWidget (cx, cy);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
337 else return this;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
338 }
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 override void draw () {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
341 if (!collapsed) subWidgets[0].draw;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
342 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
343
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
344 protected:
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
345 // callback on content_
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
346 void collapse (IContent) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
347 collapsed = content_();
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
348 if (collapsed) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
349 mw = mh = 0;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
350 } else {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
351 mw = subWidgets[0].minWidth;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
352 mh = subWidgets[0].minHeight;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
353 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
354 parent.minWChange (this, mw);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
355 parent.minHChange (this, mh);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
356 if (collapsed) return;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
357 // set incase parent didn't:
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
358 subWidgets[0].setWidth (w, -1);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
359 subWidgets[0].setHeight (h, -1);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
360 subWidgets[0].setPosition (x,y);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
361 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
362
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
363 bool collapsed = false;
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
364 IBoolContent content_;
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
365 }
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
366
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
367 /** Puts a border around its child widget.
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 * 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
370 *
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
371 * 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
372 * 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
373 class BorderWidget : AParentWidget
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
374 {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
375 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
376 super (mgr, parent, id);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
377 WDCheck (data, 2, 1);
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 subWidgets = [mgr.makeWidget (this, data.strings[0], c)];
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
380 borderType = cast(BTYPE) data.ints[1];
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
381 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
382
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
383 override bool setup (uint n, uint flags) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
384 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
385
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
386 border = mgr.renderer.getBorder (borderType, false, false);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
387 mw = subWidgets[0].minWidth + border.x1 + border.x2;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
388 mh = subWidgets[0].minHeight + border.y1 + border.y2;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
389 if (w < mw || !subWidgets[0].isWSizable) w = mw;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
390 if (h < mh || !subWidgets[0].isHSizable) h = mh;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
391 return true;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
392 }
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 void setWidth (wdim nw, int) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
395 debug assert (nw >= mw);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
396 w = nw;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
397 subWidgets[0].setWidth (w - border.x1 - border.x2, -1);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
398 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
399 override void setHeight (wdim nh, int) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
400 debug assert (nh >= mh);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
401 h = nh;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
402 subWidgets[0].setHeight (h - border.y1 - border.y2, -1);
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
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
405 override bool isWSizable () {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
406 return subWidgets[0].isWSizable;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
407 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
408 override bool isHSizable () {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
409 return subWidgets[0].isHSizable;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
410 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
411
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
412 override void setPosition (wdim nx, wdim ny) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
413 x = nx;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
414 y = ny;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
415 subWidgets[0].setPosition (x + border.x1, y + border.y1);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
416 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
417
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
418 override void minWChange (IChildWidget widget, wdim nmw) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
419 debug assert (widget is subWidgets[0]);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
420 mw = nmw + border.x1 + border.x2;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
421 parent.minWChange (this, nmw);
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 override void minHChange (IChildWidget widget, wdim nmh) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
424 debug assert (widget is subWidgets[0]);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
425 mh = nmh + border.y1 + border.y2;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
426 parent.minHChange (this, nmh);
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 override void draw () {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
430 mgr.renderer.drawBorder (&border, x, y, w, h);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
431 subWidgets[0].draw;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
432 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
433
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
434 override IChildWidget getWidget (wdim cx, wdim cy) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
435 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
436
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
437 if (subWidgets[0].onSelf (cx, cy))
168
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
438 return subWidgets[0].getWidget (cx, cy);
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
439 else
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
440 return this;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
441 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
442
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
443 protected:
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
444 alias IRenderer.Border.BTYPE BTYPE;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
445 alias IRenderer.Border.RESIZE RESIZE;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
446 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
447 IRenderer.Border border;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
448 }