Mercurial > projects > mde
diff mde/gui/widget/Floating.d @ 123:d3b2cefd46c9
minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
FloatingAreaWidget: correct resize limiters
AStringContent: allows space and ignores modifier keys
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sun, 04 Jan 2009 17:35:15 +0000 |
parents | 5b37d0400732 |
children | c9843fbaac88 |
line wrap: on
line diff
--- a/mde/gui/widget/Floating.d Fri Jan 02 18:10:14 2009 +0000 +++ b/mde/gui/widget/Floating.d Sun Jan 04 17:35:15 2009 +0000 @@ -18,6 +18,7 @@ import mde.gui.widget.Widget; import mde.gui.exception; +import mde.content.Content; import tango.util.log.Log : Log, Logger; @@ -32,13 +33,12 @@ * Rationale: parents' need to set subwidgets' positions when its position is set, so it needs to * know their positions. * - * Data: Each string item is interpreted as a subwidget widgetID. - * Ints supplied may consist of just the widget type or - * additionally an (x,y) coordinate for each subwidget (all x coords first, then all y coords). - */ + * Data: Each string item is interpreted as a sub-widget widgetID to add as a floating window. + * Ints consist of widget type followed by a border type (flags from IRenderer.Border.BTYPE) for + * each sub-widget. */ class FloatingAreaWidget : AParentWidget { - this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data) { + this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent content) { if (data.ints.length != 1 + data.strings.length) throw new WidgetDataException (this); super (mgr, parent, id); @@ -47,7 +47,7 @@ sWOrder.length = subWidgets.length; sWData.length = subWidgets.length; foreach (i,s; data.strings) { - subWidgets[i] = mgr.makeWidget (this, s); + subWidgets[i] = mgr.makeWidget (this, s, content); sWOrder[i] = i; sWData[i].borderType = cast(BTYPE) data.ints[i+1]; } @@ -116,6 +116,39 @@ subWidgets[i].setPosition (x + d.x + d.border.x1, y + d.y + d.border.y1); } + override void minSizeChange (IChildWidget widg, wdim nmw, wdim nmh) { + size_t i = 0; + while (i < subWidgets.length) { + if (subWidgets[i] is widg) + goto gotI; + ++i; + } + debug logger.error ("minSizeChange: widget is not my child (code error)"); + return; + + gotI: + with (sWData[i]) { + mw = nmw + border.x1 + border.x2; + mh = nmh + border.y1 + border.y2; + + if (mw > w || !widg.isWSizable) { + w = mw; + widg.setWidth (w - border.x1 - border.x2, -1); + } + if (mh > h || !widg.isHSizable) { + h = mh; + widg.setHeight (h - border.y1 - border.y2, -1); + } + + if (x + w > this.w) + x = (w > this.w) ? 0 : this.w - w; + if (y + h > this.h) + y = (h > this.h) ? 0 : this.h - h; + + mgr.requestRedraw; + } + } + override void draw () { super.draw; @@ -210,14 +243,20 @@ with (sWData[active]) { if (resizeType & RESIZE.X1) { wdim ow = w; - w = xDrag - cx; - if (w < mw) w = mw; - x += ow - w; + w = xDrag - cx; // new width + if (w < mw) w = mw; // limit to min width + x += ow - w; // move by difference + if (x < 0) { // limit to left edge of area + w += x; + x = 0; + } subWidgets[active].setWidth (w - border.x1 - border.x2, 1); } else if (resizeType & RESIZE.X2) { - w = xDrag + cx; - if (w < mw) w = mw; + w = xDrag + cx; // new width + if (w < mw) w = mw; // limit to min width + if (x + w > this.w) // limit to right edge of area + w = this.w - x; subWidgets[active].setWidth (w - border.x1 - border.x2, -1); } if (resizeType & RESIZE.Y1) { @@ -225,11 +264,17 @@ h = yDrag - cy; if (h < mh) h = mh; y += oh - h; + if (y < 0) { + h += y; + y = 0; + } subWidgets[active].setHeight (h - border.y1 - border.y2, 1); } else if (resizeType & RESIZE.Y2) { h = yDrag + cy; if (h < mh) h = mh; + if (y + h > this.h) + h = this.h - y; subWidgets[active].setHeight (h - border.y1 - border.y2, -1); } // Reposition widget and sub-widgets: