resize method
void
resize()
Implementation
void resize() {
if (renderCustomPaint != null) {
// https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-set-bitmap-dimensions
final Size paintingBounding = size;
renderCustomPaint!.preferredSize = paintingBounding;
// The intrinsic dimensions of the canvas element when it represents embedded content are
// equal to the dimensions of the element’s bitmap.
// A canvas element can be sized arbitrarily by a style sheet, its bitmap is then subject
// to the object-fit CSS property.
// @TODO: CSS object-fit for canvas.
// To fill (default value of object-fit) the bitmap content, use scale to get the same performed.
RenderStyle renderStyle = renderBoxModel!.renderStyle;
double? styleWidth = renderStyle.width.isAuto ? null : renderStyle.width.computedValue;
double? styleHeight = renderStyle.height.isAuto ? null : renderStyle.height.computedValue;
double? scaleX;
double? scaleY;
if (styleWidth != null) {
scaleX = paintingBounding.width / width;
}
if (styleHeight != null) {
scaleY = paintingBounding.height / height;
}
if (painter.scaleX != scaleX || painter.scaleY != scaleY) {
painter
..scaleX = scaleX
..scaleY = scaleY;
if (painter.shouldRepaint(painter)) {
renderCustomPaint!.markNeedsPaint();
}
}
}
}