mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-21 14:22:18 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Flutter 3.50 deprecates package:flutter/material.dart, so the app moves to material_ui 1.11.0 together with sync_settings_ui 0.8.0 and github_device_auth 0.5.0 (crdt_sync 0.13.1 rides along). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
147 lines
3.5 KiB
Dart
147 lines
3.5 KiB
Dart
import 'dart:math' show pi;
|
|
|
|
import 'package:material_ui/material_ui.dart';
|
|
import 'package:wake_alarm_sync/ui/spoken_label.dart';
|
|
|
|
/// A dashed outline slot for an empty/unregistered value.
|
|
/// Paints no text; spoken label is provided via [SpokenLabel].
|
|
class DashedSlot extends StatelessWidget {
|
|
/// Creates a dashed slot.
|
|
const DashedSlot({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final outlineColor = Theme.of(context).colorScheme.outline;
|
|
return SpokenLabel(
|
|
semanticLabel: 'none registered',
|
|
child: CustomPaint(
|
|
painter: _DashedSlotPainter(outlineColor: outlineColor),
|
|
child: const SizedBox(height: 40),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _DashedSlotPainter extends CustomPainter {
|
|
const _DashedSlotPainter({required this.outlineColor});
|
|
|
|
final Color outlineColor;
|
|
static const _dashWidth = 6.0;
|
|
static const _dashGap = 4.0;
|
|
static const _radius = 8.0;
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
final paint = Paint()
|
|
..color = outlineColor
|
|
..style = PaintingStyle.stroke
|
|
..strokeWidth = 2;
|
|
|
|
// Top edge
|
|
_drawDashedLine(
|
|
canvas,
|
|
paint,
|
|
const Offset(_radius, 0),
|
|
Offset(size.width - _radius, 0),
|
|
);
|
|
// Top-right arc
|
|
_drawDashedArc(
|
|
canvas,
|
|
paint,
|
|
Offset(size.width - _radius, _radius),
|
|
_radius,
|
|
-pi / 2,
|
|
pi / 2,
|
|
);
|
|
// Right edge
|
|
_drawDashedLine(
|
|
canvas,
|
|
paint,
|
|
Offset(size.width, _radius),
|
|
Offset(size.width, size.height - _radius),
|
|
);
|
|
// Bottom-right arc
|
|
_drawDashedArc(
|
|
canvas,
|
|
paint,
|
|
Offset(size.width - _radius, size.height - _radius),
|
|
_radius,
|
|
0,
|
|
pi / 2,
|
|
);
|
|
// Bottom edge
|
|
_drawDashedLine(
|
|
canvas,
|
|
paint,
|
|
Offset(size.width - _radius, size.height),
|
|
Offset(_radius, size.height),
|
|
);
|
|
// Bottom-left arc
|
|
_drawDashedArc(
|
|
canvas,
|
|
paint,
|
|
Offset(_radius, size.height - _radius),
|
|
_radius,
|
|
pi / 2,
|
|
pi / 2,
|
|
);
|
|
// Left edge
|
|
_drawDashedLine(
|
|
canvas,
|
|
paint,
|
|
Offset(0, size.height - _radius),
|
|
const Offset(0, _radius),
|
|
);
|
|
// Top-left arc
|
|
_drawDashedArc(
|
|
canvas,
|
|
paint,
|
|
const Offset(_radius, _radius),
|
|
_radius,
|
|
pi,
|
|
pi / 2,
|
|
);
|
|
}
|
|
|
|
void _drawDashedLine(Canvas canvas, Paint paint, Offset start, Offset end) {
|
|
final delta = end - start;
|
|
final length = delta.distance;
|
|
if (length <= 0) return;
|
|
final unit = delta / length;
|
|
var pos = 0.0;
|
|
while (pos < length) {
|
|
final dashEnd = (pos + _dashWidth < length) ? pos + _dashWidth : length;
|
|
canvas.drawLine(start + unit * pos, start + unit * dashEnd, paint);
|
|
pos += _dashWidth + _dashGap;
|
|
}
|
|
}
|
|
|
|
void _drawDashedArc(
|
|
Canvas canvas,
|
|
Paint paint,
|
|
Offset center,
|
|
double radius,
|
|
double startAngle,
|
|
double sweepAngle,
|
|
) {
|
|
final arcLength = radius * sweepAngle.abs();
|
|
var pos = 0.0;
|
|
while (pos < arcLength) {
|
|
final dashEnd = (pos + _dashWidth < arcLength)
|
|
? pos + _dashWidth
|
|
: arcLength;
|
|
canvas.drawArc(
|
|
Rect.fromCircle(center: center, radius: radius),
|
|
startAngle + (sweepAngle > 0 ? pos : -pos) / radius,
|
|
(dashEnd - pos) / radius * (sweepAngle > 0 ? 1 : -1),
|
|
false,
|
|
paint,
|
|
);
|
|
pos += _dashWidth + _dashGap;
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
|
}
|