StablexUI
StablexUI copied to clipboard
Implementation of a keepAspectRatio property on widget
Hi,
I think it is very useful( it was for me) to be able to lock a component to an aspectRatio.
So here is an implementation :
//@author tpfeiffer
private var _aspectRatio:Null<Float>;
public var keepAspectRatio:Bool;
public function resize(width:Float, height:Float, keepPercentage:Bool = false) : Void {
if( !keepPercentage ) {
this._silentResize = true;
if( false == keepAspectRatio || _aspectRatio == null ) {
this.w = width;
this.h = height;
if( this._height != 0 )
_aspectRatio = this._width / this._height;
} else {
var tw = height * _aspectRatio;
var th = height;
if ( tw > width ) {
tw = width;
th = tw / _aspectRatio;
}
this.w = tw;
this.h = th;
}
this._silentResize = false;
} else {
if( false == keepAspectRatio || _aspectRatio == null ) {
this._width = width;
this._height = height;
if ( this._height != 0 )
_aspectRatio = this._width / this._height;
} else {
var tw = height * _aspectRatio;
var th = height;
if ( tw > width ) {
tw = width;
th = tw / _aspectRatio;
}
this._width = tw;
this._height = th;
}
}
this._onResize();
}//function resize()
I'll add this to 1.1 milestone.
+1... I think this thing has frequent uses... such as if we want to make a square widget... For now, I hack this with on-resize event...
On 2 September 2013 16:19, RealyUniqueName [email protected] wrote:
I'll add this to 1.1 milestone.
— Reply to this email directly or view it on GitHubhttps://github.com/RealyUniqueName/StablexUI/issues/65#issuecomment-23649130 .
+1