Honestly there should be a way to do this in one step using the RectanglePlacement flags, but I can never figure it out without trial and error:
What is the opposite to RectanglePlacement::fillDestination i.e. letterboxed, maximum size without cropping while keeping the aspect ratio?
If possible it would be great to have an alias, like RectanglePlacement::centred is an alias.
I have to admit, I only use drawable.setTransformToFit(Rectangle(x, y, width, height), Rectangleplacement) when I want to position an SVG.
Is it necessary to additionally use setBounds()?
But yes, I have seen that my SVGs are sometimes positioned a bit strangely (They can be a bit too small or slightly too big sometimes). So I have some trial and error, too.
IIUC you need the setBounds to control the drawables paint() method, while for the draw() you might not need it.
But in the past I had often unexpected results because of this duality between Drawable and Component. Seems the setBoundsToFit and other methods that modify the transformation moves the result out of the setBounds() area. I know that is to be expected, but I didn’t understand how it is used in a controlled manner (and unusally I have no trouble understanding matrices and transformations).
This is the second reason why I filed this feature request, feel free to support it here: