comparison mde/gui/widget/ParentContent.d @ 147:075705ad664a

Added a border widget.
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 11 Feb 2009 13:02:30 +0000
parents 783969f4665c
children c67d074a7111
comparison
equal deleted inserted replaced
146:783969f4665c 147:075705ad664a
12 12
13 You should have received a copy of the GNU General Public License 13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
15 15
16 /****************************************************************************** 16 /******************************************************************************
17 * A pop-up widget and a switch (tab) widget (both parent widgets using 17 * A pop-up widget, a switch (tab) widget, and a collapsible widget
18 * content). 18 * (all parent widgets using content).
19 *
20 * Also a border widget (parent not using content).
19 *****************************************************************************/ 21 *****************************************************************************/
20 module mde.gui.widget.ParentContent; 22 module mde.gui.widget.ParentContent;
21 23
22 import mde.gui.widget.AParentWidget; 24 import mde.gui.widget.AParentWidget;
23 import mde.gui.widget.layout; 25 import mde.gui.widget.layout;
336 } 338 }
337 339
338 bool collapsed = false; 340 bool collapsed = false;
339 BoolContent content_; 341 BoolContent content_;
340 } 342 }
343
344 /** Puts a border around its child widget.
345 *
346 * This doesn't allow dragging like widgets in a floating area.
347 *
348 * data.ints[1] is interpreted as flags from IRenderer.Border.BTYPE.
349 * data.strings[0] is an ID for the child widget. */
350 class BorderWidget : AParentWidget
351 {
352 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
353 super (mgr, parent, id);
354 WDCheck (data, 2, 1);
355
356 subWidgets = [mgr.makeWidget (this, data.strings[0], c)];
357 borderType = cast(BTYPE) data.ints[1];
358 }
359
360 override bool setup (uint n, uint flags) {
361 if (!subWidgets[0].setup (n, flags) && !(flags & 1)) return false;
362
363 border = mgr.renderer.getBorder (borderType, false, false);
364 mw = subWidgets[0].minWidth + border.x1 + border.x2;
365 mh = subWidgets[0].minHeight + border.y1 + border.y2;
366 if (w < mw || !subWidgets[0].isWSizable) w = mw;
367 if (h < mh || !subWidgets[0].isHSizable) h = mh;
368 return true;
369 }
370
371 override void setWidth (wdim nw, int) {
372 debug assert (nw >= mw);
373 w = nw;
374 subWidgets[0].setWidth (w - border.x1 - border.x2, -1);
375 }
376 override void setHeight (wdim nh, int) {
377 debug assert (nh >= mh);
378 h = nh;
379 subWidgets[0].setHeight (h - border.y1 - border.y2, -1);
380 }
381
382 override bool isWSizable () {
383 return subWidgets[0].isWSizable;
384 }
385 override bool isHSizable () {
386 return subWidgets[0].isHSizable;
387 }
388
389 override void setPosition (wdim nx, wdim ny) {
390 x = nx;
391 y = ny;
392 subWidgets[0].setPosition (x + border.x1, y + border.y1);
393 }
394
395 override void minWChange (IChildWidget widget, wdim nmw) {
396 debug assert (widget is subWidgets[0]);
397 mw = nmw + border.x1 + border.x2;
398 parent.minWChange (this, nmw);
399 }
400 override void minHChange (IChildWidget widget, wdim nmh) {
401 debug assert (widget is subWidgets[0]);
402 mh = nmh + border.y1 + border.y2;
403 parent.minHChange (this, nmh);
404 }
405
406 override void draw () {
407 mgr.renderer.drawBorder (&border, x, y, w, h);
408 subWidgets[0].draw;
409 }
410
411 override IChildWidget getWidget (wdim cx, wdim cy) {
412 debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)");
413
414 if (subWidgets[0].onSelf (cx, cy))
415 return subWidgets[0];
416 else
417 return this;
418 }
419
420 protected:
421 alias IRenderer.Border.BTYPE BTYPE;
422 alias IRenderer.Border.RESIZE RESIZE;
423 BTYPE borderType; // what type of border to put around the widget
424 IRenderer.Border border;
425 }