Cover and Contain scaling options

This is probably insignificant request but could we have built in methods to scale a display object to either the parent container or a specific container. Essentially it would work like css background-size: container / cover; Both keep the object's aspect ratio.

displayObject.cover(/* target container or parent */)
displayObject.contain(/* target container or parent */)

Cover: Scales a displayObject to be as large as possible, ensuring that the entire area of the parent / target is completely covered.

Contain: Fits the displayObject inside the parent / target area.

Yes :wink: - lol - that is what scaleTo() does. It is very handy.

https://zimjs.com/docs.html?item=scaleTo


// If you just use:

new Pic().scaleTo().center() // it will FILL to cover the stage and keeps ratio.

// As soon as you provide a percentage, 
// then the default is FIT which contains it and keeps ratio:

new Pic().scaleTo(S, 100)

// or whichever the lesser of 80% width or 70% height:

new Pic().scaleTo(S, 80, 70)

// And FULL changes the ratio:

new Pic().scaleTo(S, 80,70, FULL)

Aaaah there is always something I miss. HAHAH

1 Like