StablexUI icon indicating copy to clipboard operation
StablexUI copied to clipboard

Implementation of a keepAspectRatio property on widget

Open kiroukou opened this issue 11 years ago • 3 comments

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()

kiroukou avatar Jul 30 '13 14:07 kiroukou

I'll add this to 1.1 milestone.

RealyUniqueName avatar Sep 02 '13 09:09 RealyUniqueName

+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 .

alijaya avatar Sep 02 '13 19:09 alijaya

+1

haysclark avatar Nov 29 '14 07:11 haysclark