render method
Renders the widget onto the provided buffer within the specified area.
Implementation
@override
void render(Buffer buffer, Rect area) {
if (bounds.width <= 0 || bounds.height <= 0) return;
// 1. Check/force focus to modal if it got lost/not set
bool anyFocused = false;
for (final node in modalFocusNodes) {
if (node.isFocused) {
anyFocused = true;
break;
}
}
if (!anyFocused && modalFocusNodes.isNotEmpty) {
modalFocusNodes.first.requestFocus();
}
// 2. Draw the background scrim (dimming the cells beneath the modal)
for (var y = 0; y < bounds.height; y++) {
for (var x = 0; x < bounds.width; x++) {
final cell = buffer.getCell(bounds.x + x, bounds.y + y);
if (cell != null) {
final isInsideDialog =
x >= dialogBounds.x &&
x < dialogBounds.x + dialogBounds.width &&
y >= dialogBounds.y &&
y < dialogBounds.y + dialogBounds.height;
if (!isInsideDialog) {
cell.style = Style(
foreground: cell.style.foreground,
background: cell.style.background,
modifiers: cell.style.modifiers | Modifier.dim,
);
}
}
}
}
// 3. Draw the central dialog box inside dialogBounds
final originalBounds = bounds;
bounds = dialogBounds;
super.render(buffer, area);
bounds = originalBounds;
}