Line data Source code
1 : part of 'foss_calendar.dart';
2 :
3 : /// Paints a single chevron pointing left or right, the month navigation
4 : /// affordance. Mirrors under RTL via [pointsLeft], set by the caller.
5 : class _ChevronPainter extends CustomPainter {
6 2 : const _ChevronPainter({required this.color, required this.pointsLeft});
7 :
8 : final Color color;
9 : final bool pointsLeft;
10 :
11 2 : @override
12 : void paint(Canvas canvas, Size size) {
13 2 : final w = size.width;
14 2 : final h = size.height;
15 2 : final near = pointsLeft ? 0.38 : 0.62;
16 2 : final far = pointsLeft ? 0.62 : 0.38;
17 2 : final path = Path()
18 6 : ..moveTo(w * far, h * 0.24)
19 6 : ..lineTo(w * near, h * 0.5)
20 6 : ..lineTo(w * far, h * 0.76);
21 2 : canvas.drawPath(
22 : path,
23 2 : Paint()
24 4 : ..color = color
25 2 : ..style = PaintingStyle.stroke
26 2 : ..strokeWidth = 1.5
27 2 : ..strokeCap = StrokeCap.round
28 2 : ..strokeJoin = StrokeJoin.round,
29 : );
30 : }
31 :
32 2 : @override
33 : bool shouldRepaint(_ChevronPainter old) =>
34 12 : old.color != color || old.pointsLeft != pointsLeft;
35 : }
36 :
37 : /// Paints the keyboard focus ring: a superellipse stroke inset just inside the
38 : /// cell edge, so it reads as the day's corner shape and is not clipped by the
39 : /// abutting neighbor cells. It traces [borderRadius], the corners of the fill
40 : /// underneath, so a range end keeps its flat inner edge.
41 : class _DayRingPainter extends CustomPainter {
42 1 : const _DayRingPainter({required this.color, required this.borderRadius});
43 :
44 : final Color color;
45 : final BorderRadius borderRadius;
46 :
47 : // The stroke is centered on the ring path, so each corner shrinks by half the
48 : // stroke to stay concentric with the fill it traces.
49 1 : static Radius _inset(Radius corner) {
50 3 : final r = corner.x - _ringWidth / 2;
51 2 : return r <= 0 ? Radius.zero : Radius.circular(r);
52 : }
53 :
54 1 : @override
55 : void paint(Canvas canvas, Size size) {
56 3 : final rect = (Offset.zero & size).deflate(_ringWidth / 2);
57 1 : canvas.drawRSuperellipse(
58 1 : RSuperellipse.fromRectAndCorners(
59 : rect,
60 3 : topLeft: _inset(borderRadius.topLeft),
61 3 : topRight: _inset(borderRadius.topRight),
62 3 : bottomRight: _inset(borderRadius.bottomRight),
63 3 : bottomLeft: _inset(borderRadius.bottomLeft),
64 : ),
65 1 : Paint()
66 2 : ..color = color
67 1 : ..style = PaintingStyle.stroke
68 1 : ..strokeWidth = _ringWidth,
69 : );
70 : }
71 :
72 1 : @override
73 : bool shouldRepaint(_DayRingPainter old) =>
74 6 : old.color != color || old.borderRadius != borderRadius;
75 : }
|