Created
November 16, 2009 19:35
-
-
Save aherrman/236264 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resizeDragger = new BoundedDragResizer(this, resizeHandle, | |
BoundedDragResizer.rangedCheckSizeFactory(new Dimensions(50, 20))); | |
/////////////////////////////////////////////////////////////////////////////// | |
/** | |
* Factory that returns a checkSize() implementation that bounds the window | |
* to be within some min and max size. No validation is done on the min | |
* and max sizes. | |
* | |
* @param min The minimum size. If null then the component's minWidth and | |
* minHeight values are used. | |
* @param max The maximum size. If null then the component's maxWidth and | |
* maxHeight values are used. | |
* @param doDefaultFirst true to run the default bounds first (restricts to | |
* parent's size), false to only bound by the min/max size. | |
* @return A function suitable for use as a BoundedDragResizer checkBounds | |
* method that restricts the component to be within the min and max | |
* sizes. | |
*/ | |
public static function rangedCheckSizeFactory(min:Dimensions = null, | |
max:Dimensions = null, doDefaultFirst:Boolean = true):Function | |
{ | |
if(min == null) { | |
min = new Dimensions(1, 1); | |
} | |
if(max == null) { | |
max = new Dimensions(Number.MAX_VALUE, Number.MAX_VALUE); | |
} | |
return function(d:Dimensions, c:UIComponent):Dimensions { | |
return rangedCheckSize(min, max, doDefaultFirst, d, c); | |
} | |
} | |
private static function rangedCheckSize(min:Dimensions, max:Dimensions, | |
doDefaultFirst:Boolean, d:Dimensions, c:UIComponent):Dimensions | |
{ | |
var newD:Dimensions; | |
if(doDefaultFirst) {n | |
newD = defaultCheckSize(d, c); | |
} else { | |
newD = d.clone(); | |
} | |
var realMin:Dimensions = min; | |
if(realMin == null) { realMin = new Dimensions(c.minWidth, c.minHeight); } | |
var realMax:Dimensions = max; | |
if(realMax == null) { realMax = new Dimensions(c.maxWidth, c.maxHeight); } | |
if(newD.width < realMin.width) { newD.width = realMin.width; } | |
else if(newD.width > realMax.width) { newD.width = realMax.width; } | |
if(newD.height < realMin.height) { newD.height = realMin.height; } | |
else if(newD.height > realMax.height) { newD.height = realMax.height; } | |
return newD; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment