resize method
Resizes the buffer to the new dimensions, preserving existing content where it fits.
Implementation
void resize(int newWidth, int newHeight) {
Tracer.record(_traceResizeId, Phase.begin, TraceCategory.layout);
try {
newWidth = max(0, newWidth);
newHeight = max(0, newHeight);
final newChars = List.filled(newWidth * newHeight, ' ');
final newAttributes = Uint32List(newWidth * newHeight * 3);
for (var i = 2; i < newAttributes.length; i += 3) {
newAttributes[i] = Modifier.transparent;
}
final overlapWidth = min(width, newWidth);
final overlapHeight = min(height, newHeight);
if (overlapWidth > 0 && overlapHeight > 0) {
for (var y = 0; y < overlapHeight; y++) {
final targetCharStart = y * newWidth;
final sourceCharStart = y * width;
newChars.setRange(
targetCharStart,
targetCharStart + overlapWidth,
characters,
sourceCharStart,
);
final targetAttrStart = y * newWidth * 3;
final sourceAttrStart = y * width * 3;
newAttributes.setRange(
targetAttrStart,
targetAttrStart + overlapWidth * 3,
attributes,
sourceAttrStart,
);
}
}
width = newWidth;
height = newHeight;
characters = newChars;
attributes = newAttributes;
} finally {
Tracer.record(_traceResizeId, Phase.end, TraceCategory.layout);
}
}