Web source: container == content — element grid + selection box sized to the cropped frame's canvas extent
- FindContentBounds already trimmed the bitmap; the grid/box still rendered at the uncropped user size, so Fill stretched the tight widget into a bigger frame = dead-between-content-and-border. - ContentCanvasSize maps the crop rect to canvas units (1920/pixW per axis, DPI-correct) and the preview event now carries (bitmap, canvasW, canvasH). - OnWebView2PreviewBitmapChanged sets the element Width/Height to that size; the grid and the SelectionOverlay (both bound to the element's Width/Height) now equal the widget exactly. - IsPreviewDragging (set in MainWindow drag/resize) suppresses auto-fit mid-gesture. - Tests 10/10 (alpha bounds, canvas-size mapping incl. DPI, control size); 0 warnings.
This commit is contained in:
@@ -154,4 +154,25 @@ public sealed class WebView2ManagerTests
|
||||
|
||||
Assert.Equal((0, 0, w, h), (x, y, bw, bh));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ContentCanvasSize_Full_Frame_Maps_To_Canvas()
|
||||
{
|
||||
var (cw, ch) = WebView2Manager.ContentCanvasSize(1920, 1080, 1920, 1080);
|
||||
Assert.Equal((1920.0, 1080.0), (cw, ch));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ContentCanvasSize_Half_Widget_Is_Half_Canvas()
|
||||
{
|
||||
var (cw, ch) = WebView2Manager.ContentCanvasSize(960, 540, 1920, 1080);
|
||||
Assert.Equal((960.0, 540.0), (cw, ch));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ContentCanvasSize_Corrects_For_Dpi_Scale()
|
||||
{
|
||||
var (cw, ch) = WebView2Manager.ContentCanvasSize(1200, 675, 2400, 1350);
|
||||
Assert.Equal((960.0, 540.0), (cw, ch));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user