Files
pipelines/app/lib/ui/theme/design_screen_overlay.dart
T
alan 9eaa8d18c0 Retro CRT design: Terminal on a green or amber phosphor tube
One hue per variant (brightness steps for roles, statuses and chat
colours, with cross/ring glyphs where hue alone told status), square
corners, 1px phosphor frames, a faint text glow and a static scanline and
vignette pattern painted once in its own repaint boundary. Light mode is a
paper-white phosphor. Terminal's theme builder is shared, not forked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 23:10:57 +00:00

98 lines
3.0 KiB
Dart

import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'app_design_tokens.dart';
/// [child] under the design's [AppDesignTokens.screen] pattern (Retro CRT's
/// scanlines and vignette), or [child] alone under a design without one.
///
/// The pattern is one [CustomPaint] in its own [RepaintBoundary]: it paints
/// once (again only on a resize, a pixel-ratio change or a design switch)
/// and the compositor reuses its picture every frame. It adds no saveLayer,
/// no filter and no animation, ignores the pointer and has no semantics.
/// [child] stays the Stack's first child either way, so switching to or
/// from a patterned design never remounts the app beneath.
class DesignScreenOverlay extends StatelessWidget {
const DesignScreenOverlay({super.key, required this.child});
final Widget child;
@override
Widget build(BuildContext context) {
final pattern = AppDesignTokens.of(context).screen;
return Stack(
fit: StackFit.passthrough,
children: [
child,
if (pattern != null)
Positioned.fill(
child: IgnorePointer(
child: RepaintBoundary(
key: const Key('design-screen-overlay'),
child: CustomPaint(
painter: ScreenPatternPainter(
pattern,
MediaQuery.devicePixelRatioOf(context),
),
),
),
),
),
],
);
}
}
/// Paints a [ScreenPattern]: one rectangle filled with a hard-stopped,
/// repeating vertical gradient (the scanlines, snapped to device pixels) and
/// one with a radial gradient (the vignette). Two draws, no layers.
class ScreenPatternPainter extends CustomPainter {
const ScreenPatternPainter(this.pattern, this.pixelRatio);
final ScreenPattern pattern;
final double pixelRatio;
@override
void paint(Canvas canvas, Size size) {
final rect = Offset.zero & size;
final period = pattern.period.clamp(2, 12);
final band = (period / 3).round().clamp(1, period - 1);
// In logical pixels, on device-pixel boundaries.
final step = period / pixelRatio;
final clear = (period - band) / period;
canvas.drawRect(
rect,
Paint()
..shader = ui.Gradient.linear(
Offset.zero,
Offset(0, step),
[
const Color(0x00000000),
const Color(0x00000000),
pattern.scanline,
pattern.scanline,
],
[0, clear, clear, 1],
TileMode.repeated,
),
);
final vignette = pattern.vignette;
if (vignette == null) return;
canvas.drawRect(
rect,
Paint()
..shader = ui.Gradient.radial(
rect.center,
size.longestSide * 0.75,
[const Color(0x00000000), const Color(0x00000000), vignette],
[0, 0.55, 1],
),
);
}
@override
bool shouldRepaint(ScreenPatternPainter old) =>
old.pattern != pattern || old.pixelRatio != pixelRatio;
}