CanvasTerminal.withParent constructor
CanvasTerminal.withParent(
- Element parent,
- CanvasRendererType rendererType, {
- int? scale,
- String? font,
- Vec2? minSize,
Builds a CanvasTerminal by creating a new html.CanvasElement so that
it fills the dimensions of the given html.Element (or is at least the
given minSize
in columns and rows). Creates a default CanvasRenderer
of the requested type for the CanvasTerminal.
Note: will remove any existing canvas elements within the given parent
.
Implementation
factory CanvasTerminal.withParent(
html.Element parent, CanvasRendererType rendererType,
{int? scale, String? font, Vec2? minSize}) {
scale ??= html.window.devicePixelRatio.toInt();
CanvasRenderer renderer;
var canvas = html.CanvasElement();
switch (rendererType) {
case CanvasRendererType.font:
renderer = FontRenderer(canvas.context2D, scale, font);
break;
case CanvasRendererType.glyph:
renderer = GlyphRenderer.dosVga437(canvas.context2D, scale);
break;
}
// remove any existing canvases and add the new one
parent.children.removeWhere((element) => element is html.CanvasElement);
parent.append(canvas);
return CanvasTerminal.withCanvas(canvas, renderer, parent.clientWidth,
parent.clientHeight, scale, minSize);
}