Continuing the thread about FitIn and FitOut not working as expected here for Skia Renderers, where its also not correct.
If you look at the help patch How to load and draw images" and you put Size at 2.00, 2.00 (full size) and then Size Mode Fit In, it only works in one direction:
I thought the bug must be in FixAspectRatio, but the weird thing is that this doesn’t actually use the size of the renderer like you normally would in that calculation.
So the bug must be in DrawImage (SKCanvas) since that is the only code that actually has the window aspect ratio. Or rather its not a bug, its just the way its set up you can’t do actual fit in/out.
I’m sure there is a reason for it, but its a bit backwards to correct the aspect ratio without the window and then sort of reverse transform it again when you draw the image.
The thing is that since the way DrawImage works, it is basically impossibe to achieve the “normal” FitIn or FitOut behavior as we know it from CSS.
The only way to make it work is to actually calculate the size ourselves from the window size, like so:
Now the FitIn and FitOut actually work as expected and as far as I can tell this is the only way it can ever work. Without this it can only ever work in one direction.
you are right: In order to fit the image into the renderer you need to feed this info in some way from upstream.
Why is that?
The main reason for this is that we don’t offer a distorted space in skia. Even the normalized space is undistored. If your window is not a square then also the part of the space that is visble inside the window will be non-sqaure.
You can think in all sorts of spaces: try them in attached patch.
But for layouting task all of them require you to feed the rectangle into which you want to fit the image into from upstream.
I wouldn’t say it’s a bug. It’s just the naming of the space “Normalized” which tricked you into believing its always 2 by 2. Fit into Canvas Bounds.vl (14.5 KB)
Okay, understood. So its more of a UX issue than an actual bug, especially since without the inputs it works half the time so one might think its working and then discover only later that it doesnt work when you change the aspect ratio of the renderer.
For me the only question would be then why it shouldn’t always work like that. Are there any cases where it only works correctly WITHOUT the client bounds input?
Not sure I understand what you mean actually. Can you rephrase?
Think of it like in an illustrator app.
Elements on the Canvas: You can draw an image into whatever Rectangle you want to. It is in world space - on the canvas.
Views onto the Canvas: Cameras or Spaces - are independent concepts which reveal parts of the content.
In your scenario the Normalized Space makes sure that the height is always 2, no matter how big the window. With the Rectangle at centered at (0,0) and having a size of (2,2) you created a case where those conceptual distinctions start to fade away.
Our current Normalized mode:
the camera is adjusted in a way that the height of the visible canvas is always 2.0.
I can imagine Spaces with the following properties:
FitIn: Cam shows max 2.0 in width and height. One of both is typically is smaller
…
Hmm. But this would again not free you from feeding the actual client bounds upstream. E.g. If now your ClientBounds width is 2 and height only 1.4, then you need to Draw a Portrait image in a way that it has height of 1.4 and maybe a width of 0.7…
So. The only way to make you not trick yourself is to remove the Normalized mode. Then it’s more obvious that you need to feed the canvas bounds info upstream and draw your rectangle at that exact location.