vg icon indicating copy to clipboard operation
vg copied to clipboard

HTML canvas grows with each redraw with resize:false if there is no CSS styling

Open johnridesabike opened this issue 10 months ago • 4 comments

It seems that if there is no CSS styling applied to the given canvas element, Vgr_htmlc can cause the canvas to grow with every redraw when ~resize:false. I'm not sure how much of a real-world problem this is considering users would be expected to always have styling, but I noticed this while developing on a minimalist web page. Adding CSS height and width styles fixed it for me.

I think an additional warning in the docs would probably be sufficient if there is not a better fix available.

johnridesabike avatar Feb 06 '25 14:02 johnridesabike

I just did some additional testing, and this issue seems to be also related to the device pixel ratio. If the DPR is 1 then the canvas does not grow on each redraw, but if the DPR is 2 or higher then it does.

johnridesabike avatar Feb 06 '25 16:02 johnridesabike

Yeah this stuff is brittle, I can't remember the number of times I had problems with auto growing canvases. I don't have the stuff in my head but the only thing that this influences is here.

dbuenzli avatar Feb 06 '25 16:02 dbuenzli

Perhaps the bound_h and bound_w need to be divided by Brr.Window.device_pixel_ratio? I haven't tested that but it seems to make sense based on my observations.

johnridesabike avatar Feb 06 '25 19:02 johnridesabike

Note if you have a simple repro using the blueprint https://github.com/dbuenzli/vg/blob/master/test/min_htmlc.ml it will increase the chances that I look into it at some point.

dbuenzli avatar Mar 01 '25 23:03 dbuenzli