Refine reference liquid glass and resting grey cursor
This commit is contained in:
@@ -9,6 +9,28 @@ import 'package:hepan_everyday/widgets/glass_dock.dart';
|
||||
import 'package:hepan_everyday/widgets/glass_refraction.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('resting cursor is neutral grey and clears while held', (
|
||||
tester,
|
||||
) async {
|
||||
final resting = await _render(
|
||||
tester,
|
||||
GlassDock(selectedIndex: 0, onSelected: (_) {}),
|
||||
backdropColor: Colors.white,
|
||||
preview: true,
|
||||
);
|
||||
final selected = _channel(resting, 46, 52, 0);
|
||||
final base = _channel(resting, 160, 52, 0);
|
||||
expect(base - selected, greaterThan(20));
|
||||
expect((_channel(resting, 46, 52, 2) - selected).abs(), lessThan(12));
|
||||
final held = await _render(
|
||||
tester,
|
||||
GlassDock(selectedIndex: 0, onSelected: (_) {}),
|
||||
backdropColor: Colors.white,
|
||||
held: true,
|
||||
preview: true,
|
||||
);
|
||||
expect(_channel(held, 46, 52, 0) - selected, greaterThan(18));
|
||||
});
|
||||
testWidgets(
|
||||
'glass softens fine background detail without whitening its colour',
|
||||
(tester) async {
|
||||
@@ -37,13 +59,13 @@ void main() {
|
||||
GlassDock(selectedIndex: 0, onSelected: (_) {}),
|
||||
);
|
||||
// Below the symbol and away from the rim, the selected lens should retain
|
||||
// most of this saturated cyan backdrop instead of painting a grey pill.
|
||||
// this saturated cyan backdrop while applying the new resting grey tint.
|
||||
final red = _channel(pixels, 46, 52, 0);
|
||||
final green = _channel(pixels, 46, 52, 1);
|
||||
final blue = _channel(pixels, 46, 52, 2);
|
||||
expect(red, lessThan(50));
|
||||
expect(green - red, greaterThan(130));
|
||||
expect(blue - red, greaterThan(165));
|
||||
expect(red, lessThan(85));
|
||||
expect(green - red, greaterThan(95));
|
||||
expect(blue - red, greaterThan(140));
|
||||
},
|
||||
);
|
||||
|
||||
@@ -63,7 +85,9 @@ void main() {
|
||||
final contrast =
|
||||
reds.reduce((a, b) => a > b ? a : b) -
|
||||
reds.reduce((a, b) => a < b ? a : b);
|
||||
expect(contrast, lessThan(30), reason: 'background at x=$start');
|
||||
// Fine stripes start at 180 contrast levels; at least two thirds softens,
|
||||
// while the stronger curved rim can enlarge individual stripe details.
|
||||
expect(contrast, lessThan(60), reason: 'background at x=$start');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -140,6 +164,8 @@ Future<ByteData> _render(
|
||||
bool gradient = false,
|
||||
bool preview = false,
|
||||
Offset offset = Offset.zero,
|
||||
Color backdropColor = const Color(0xFF14B4E6),
|
||||
bool held = false,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(800, 600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -161,7 +187,12 @@ Future<ByteData> _render(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: _Backdrop(stripes, gradient, stripeWidth),
|
||||
painter: _Backdrop(
|
||||
stripes,
|
||||
gradient,
|
||||
stripeWidth,
|
||||
backdropColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned.fill(child: glass),
|
||||
@@ -180,10 +211,19 @@ Future<ByteData> _render(
|
||||
);
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
final gesture = held
|
||||
? await tester.startGesture(
|
||||
tester.getCenter(find.byKey(const Key('dock-cursor'))),
|
||||
)
|
||||
: null;
|
||||
if (held) {
|
||||
await tester.pump(const Duration(milliseconds: 110));
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
}
|
||||
if (ui.ImageFilter.isShaderFilterSupported) {
|
||||
expect(find.byType(BackdropFilter), findsNothing);
|
||||
}
|
||||
return (await tester.runAsync(() async {
|
||||
final result = (await tester.runAsync(() async {
|
||||
final boundary =
|
||||
key.currentContext!.findRenderObject()! as RenderRepaintBoundary;
|
||||
final image = await boundary.toImage(pixelRatio: 1);
|
||||
@@ -202,7 +242,12 @@ Future<ByteData> _render(
|
||||
final png = (await previewImage.toByteData(
|
||||
format: ui.ImageByteFormat.png,
|
||||
))!;
|
||||
final output = File('../dist/screenshots/glass-frosted-dock.png');
|
||||
final name = backdropColor == Colors.white
|
||||
? held
|
||||
? 'liquid-glass-held.png'
|
||||
: 'liquid-glass-rest.png'
|
||||
: 'liquid-glass-detail.png';
|
||||
final output = File('../dist/screenshots/$name');
|
||||
await output.parent.create(recursive: true);
|
||||
await output.writeAsBytes(png.buffer.asUint8List());
|
||||
previewImage.dispose();
|
||||
@@ -225,13 +270,17 @@ Future<ByteData> _render(
|
||||
image.dispose();
|
||||
return cropped;
|
||||
}))!;
|
||||
await gesture?.cancel();
|
||||
await tester.pumpAndSettle();
|
||||
return result;
|
||||
}
|
||||
|
||||
class _Backdrop extends CustomPainter {
|
||||
const _Backdrop(this.stripes, this.gradient, this.stripeWidth);
|
||||
const _Backdrop(this.stripes, this.gradient, this.stripeWidth, this.colour);
|
||||
final bool stripes;
|
||||
final bool gradient;
|
||||
final double stripeWidth;
|
||||
final Color colour;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
@@ -245,10 +294,7 @@ class _Backdrop extends CustomPainter {
|
||||
return;
|
||||
}
|
||||
if (!stripes) {
|
||||
canvas.drawRect(
|
||||
Offset.zero & size,
|
||||
Paint()..color = const Color(0xFF14B4E6),
|
||||
);
|
||||
canvas.drawRect(Offset.zero & size, Paint()..color = colour);
|
||||
return;
|
||||
}
|
||||
for (var x = 0.0; x < size.width; x += stripeWidth) {
|
||||
@@ -266,5 +312,6 @@ class _Backdrop extends CustomPainter {
|
||||
bool shouldRepaint(_Backdrop oldDelegate) =>
|
||||
oldDelegate.stripes != stripes ||
|
||||
oldDelegate.gradient != gradient ||
|
||||
oldDelegate.stripeWidth != stripeWidth;
|
||||
oldDelegate.stripeWidth != stripeWidth ||
|
||||
oldDelegate.colour != colour;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user