asCanvasElement method

CanvasElement asCanvasElement(
  1. Element element
)

Ensures that DOM element to render is a canvas. If not will insert a canvas inside the element and use it.

Implementation

CanvasElement asCanvasElement(Element element) {
  if (element is CanvasElement) return element;

  var w = getElementWidth(element, 640);
  var h = getElementHeight(element, 480);

  var canvas = CanvasElement(width: w, height: h);
  element.children.add(canvas);

  return canvas;
}