Merge commit '7f31e16bc1f9fe8cd6d0ac0fbe0d509756880aff' into pipelines/run-20261112-1235-gear-icon-for-background-tasks-1cb4
This commit is contained in:
@@ -3,20 +3,24 @@ import 'dart:ui' show PathMetric;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Arc-length geometry for the composer's running border.
|
||||
/// Arc-length geometry for the composer's running highlight.
|
||||
///
|
||||
/// The highlight is laid out by distance travelled along the outline, not by
|
||||
/// angle around the centre, so equal time steps move it equal lengths around
|
||||
/// a rounded rectangle: no racing along the long edges, no crawling at ends.
|
||||
///
|
||||
/// One lap is `progress` in [0, 1]; progress 1 is the same place as 0, so the
|
||||
/// loop restarts without a jump.
|
||||
/// loop restarts without a jump. The highlight is the only thing drawn: a
|
||||
/// short segment of the outline, with no glow, trail or tint of the rest.
|
||||
|
||||
/// The colour bands, as fractions of a lap measured forward from the origin.
|
||||
/// They match the original sweep's stops and colours.
|
||||
const List<double> runningHighlightStops = [0, .12, .24, .38, 1];
|
||||
/// The fraction of the outline one highlight covers. It is a short segment
|
||||
/// that travels, not a trail round the whole edge.
|
||||
const double runningHighlightSpan = .12;
|
||||
|
||||
/// Half a device pixel of overlap so neighbouring segments leave no seam.
|
||||
/// Colour fractions along the highlight's own length, tail (0) to head (1).
|
||||
const List<double> runningHighlightStops = [0, .3, .6, 1];
|
||||
|
||||
/// Half a device pixel of overlap so neighbouring pieces leave no seam.
|
||||
const double _seamOverlap = .5;
|
||||
|
||||
/// One piece of the outline and the highlight colour drawn over it.
|
||||
@@ -36,37 +40,44 @@ class RunningArcSegment {
|
||||
final Color color;
|
||||
}
|
||||
|
||||
/// The arc length of the highlight's origin along an outline of [length].
|
||||
/// One stroke of the highlight: a piece of the outline and its colour.
|
||||
class RunningBorderStroke {
|
||||
const RunningBorderStroke({required this.path, required this.color});
|
||||
|
||||
final Path path;
|
||||
final Color color;
|
||||
}
|
||||
|
||||
/// The arc length of the highlight's tail along an outline of [length].
|
||||
double runningHighlightOrigin(double progress, double length) {
|
||||
final lap = progress - progress.floorToDouble();
|
||||
return lap * length;
|
||||
}
|
||||
|
||||
/// The highlight colour [fraction] of a lap ahead of its origin. Fractions
|
||||
/// wrap, so `f` and `f + 1` are the same colour.
|
||||
/// The highlight colour at [fraction] along its own length (0 is the tail,
|
||||
/// 1 the head). Outside [0, 1] it is transparent.
|
||||
Color runningHighlightColorAt(double fraction, Color primary, Color tertiary) {
|
||||
if (fraction < 0 || fraction > 1) return primary.withValues(alpha: 0);
|
||||
final colors = [
|
||||
primary.withValues(alpha: 0),
|
||||
primary,
|
||||
tertiary,
|
||||
tertiary.withValues(alpha: 0),
|
||||
primary.withValues(alpha: 0),
|
||||
];
|
||||
final f = fraction - fraction.floorToDouble();
|
||||
for (var i = 1; i < runningHighlightStops.length; i++) {
|
||||
final stop = runningHighlightStops[i];
|
||||
if (f <= stop) {
|
||||
if (fraction <= stop) {
|
||||
final from = runningHighlightStops[i - 1];
|
||||
final t = (f - from) / (stop - from);
|
||||
final t = (fraction - from) / (stop - from);
|
||||
return Color.lerp(colors[i - 1], colors[i], t)!;
|
||||
}
|
||||
}
|
||||
return colors.last;
|
||||
}
|
||||
|
||||
/// Splits an outline of [length] into pieces about [step] long and colours
|
||||
/// each by where it sits in the highlight at [progress]. Pieces with no
|
||||
/// visible colour are left out.
|
||||
/// Splits the highlight into pieces about [step] long along an outline of
|
||||
/// [length], starting at the lap's origin and wrapping past the outline's
|
||||
/// start. Each piece takes the colour of its middle along the highlight.
|
||||
List<RunningArcSegment> runningHighlightSegments({
|
||||
required double progress,
|
||||
required double length,
|
||||
@@ -75,29 +86,75 @@ List<RunningArcSegment> runningHighlightSegments({
|
||||
double step = 3,
|
||||
}) {
|
||||
if (length <= 0) return const [];
|
||||
final count = math.max(1, (length / step).ceil());
|
||||
final size = length / count;
|
||||
final span = length * runningHighlightSpan;
|
||||
final count = math.max(1, (span / step).ceil());
|
||||
final size = span / count;
|
||||
final origin = runningHighlightOrigin(progress, length);
|
||||
final segments = <RunningArcSegment>[];
|
||||
for (var i = 0; i < count; i++) {
|
||||
final mid = (i + .5) * size;
|
||||
final color = runningHighlightColorAt(
|
||||
(mid - origin) / length,
|
||||
(i + .5) * size / span,
|
||||
primary,
|
||||
tertiary,
|
||||
);
|
||||
if (color.a == 0) continue;
|
||||
segments.add(
|
||||
RunningArcSegment(
|
||||
start: math.max(0, i * size - _seamOverlap),
|
||||
end: math.min(length, (i + 1) * size + _seamOverlap),
|
||||
color: color,
|
||||
),
|
||||
_addWrapped(
|
||||
segments,
|
||||
from: origin + i * size - _seamOverlap,
|
||||
to: origin + (i + 1) * size + _seamOverlap,
|
||||
length: length,
|
||||
color: color,
|
||||
);
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
/// Adds the arc from [from] to [to] (which may lie outside the outline) as
|
||||
/// one or, across the outline's start, two pieces.
|
||||
void _addWrapped(
|
||||
List<RunningArcSegment> out, {
|
||||
required double from,
|
||||
required double to,
|
||||
required double length,
|
||||
required Color color,
|
||||
}) {
|
||||
final start = from - (from / length).floorToDouble() * length;
|
||||
final end = start + math.min(to - from, length);
|
||||
if (end <= length) {
|
||||
out.add(RunningArcSegment(start: start, end: end, color: color));
|
||||
return;
|
||||
}
|
||||
out
|
||||
..add(RunningArcSegment(start: start, end: length, color: color))
|
||||
..add(RunningArcSegment(start: 0, end: end - length, color: color));
|
||||
}
|
||||
|
||||
/// The strokes that paint the highlight over [outline] at [progress]: one
|
||||
/// per visible piece, each a plain stroke with no blur or glow. Empty for an
|
||||
/// empty outline.
|
||||
List<RunningBorderStroke> runningHighlightStrokes({
|
||||
required Path outline,
|
||||
required double progress,
|
||||
required Color primary,
|
||||
required Color tertiary,
|
||||
}) {
|
||||
final metrics = outline.computeMetrics().toList();
|
||||
final length = metrics.fold<double>(0, (sum, m) => sum + m.length);
|
||||
final segments = runningHighlightSegments(
|
||||
progress: progress,
|
||||
length: length,
|
||||
primary: primary,
|
||||
tertiary: tertiary,
|
||||
);
|
||||
return [
|
||||
for (final segment in segments)
|
||||
RunningBorderStroke(
|
||||
path: runningArcPath(metrics, segment.start, segment.end),
|
||||
color: segment.color,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// The part of an outline between arc lengths [start] and [end]. The outline
|
||||
/// may be made of several contours, so the range is taken across all of them.
|
||||
Path runningArcPath(List<PathMetric> metrics, double start, double end) {
|
||||
|
||||
@@ -2,13 +2,16 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'composer_running_arc.dart';
|
||||
|
||||
/// The composer's "agent is working" edge: a soft highlight that travels once
|
||||
/// around the pill's rounded border in [primary] and [tertiary], with a faint
|
||||
/// glow beneath it. Mount it only while a turn runs; disposing it stops the
|
||||
/// animation, so the border ends cleanly with the turn.
|
||||
/// The composer's "agent is working" edge: one short highlight in [primary]
|
||||
/// and [tertiary] that travels around the pill's rounded border at constant
|
||||
/// speed. Nothing else changes: the rest of the border, its fill and its
|
||||
/// thickness stay the normal static outline drawn beneath it.
|
||||
///
|
||||
/// With reduced motion (the platform's disable-animations setting) it draws
|
||||
/// a static, evenly highlighted border instead and never ticks.
|
||||
/// Mount it only while a turn runs; disposing it stops the animation, so the
|
||||
/// border ends cleanly with the turn.
|
||||
///
|
||||
/// With reduced motion (the platform's disable-animations setting) it paints
|
||||
/// nothing, leaving the normal static border, and never ticks.
|
||||
class ComposerRunningBorder extends StatefulWidget {
|
||||
const ComposerRunningBorder({
|
||||
super.key,
|
||||
@@ -25,12 +28,9 @@ class ComposerRunningBorder extends StatefulWidget {
|
||||
/// One lap of the highlight around the border (about 2.5–3 s).
|
||||
static const Duration period = Duration(milliseconds: 2750);
|
||||
|
||||
/// The stroke drawn just inside the pill's edge.
|
||||
/// The stroke width of the highlight, drawn just inside the pill's edge.
|
||||
static const double strokeWidth = 2;
|
||||
|
||||
/// The static border's opacity under reduced motion.
|
||||
static const double staticOpacity = 0.7;
|
||||
|
||||
@override
|
||||
State<ComposerRunningBorder> createState() => _ComposerRunningBorderState();
|
||||
}
|
||||
@@ -99,46 +99,23 @@ class _RunningBorderPainter extends CustomPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
if (size.isEmpty) return;
|
||||
final progress = lap?.value;
|
||||
// Reduced motion: no highlight; the normal static border shows alone.
|
||||
if (progress == null || size.isEmpty) return;
|
||||
const width = ComposerRunningBorder.strokeWidth;
|
||||
final rect = Offset.zero & size;
|
||||
final path = shape.getOuterPath(rect.deflate(width / 2));
|
||||
final glow = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = width * 3
|
||||
..maskFilter = const MaskFilter.blur(BlurStyle.normal, 4);
|
||||
final outline = shape.getOuterPath((Offset.zero & size).deflate(width / 2));
|
||||
final line = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = width;
|
||||
final progress = lap?.value;
|
||||
if (progress == null) {
|
||||
final solid = primary.withValues(
|
||||
alpha: ComposerRunningBorder.staticOpacity,
|
||||
);
|
||||
glow.color = solid.withValues(alpha: solid.a * .4);
|
||||
line.color = solid;
|
||||
canvas
|
||||
..drawPath(path, glow)
|
||||
..drawPath(path, line);
|
||||
return;
|
||||
}
|
||||
// The highlight is laid along the outline by arc length, one piece at a
|
||||
// time, so its speed is even around corners and straight edges alike.
|
||||
final metrics = path.computeMetrics().toList();
|
||||
final length = metrics.fold<double>(0, (sum, m) => sum + m.length);
|
||||
final segments = runningHighlightSegments(
|
||||
// The highlight is laid along the outline by arc length, so its speed is
|
||||
// even around corners and straight edges alike. Only its pieces are drawn.
|
||||
for (final stroke in runningHighlightStrokes(
|
||||
outline: outline,
|
||||
progress: progress,
|
||||
length: length,
|
||||
primary: primary,
|
||||
tertiary: tertiary,
|
||||
);
|
||||
for (final segment in segments) {
|
||||
final piece = runningArcPath(metrics, segment.start, segment.end);
|
||||
glow.color = segment.color;
|
||||
line.color = segment.color;
|
||||
canvas
|
||||
..drawPath(piece, glow)
|
||||
..drawPath(piece, line);
|
||||
)) {
|
||||
canvas.drawPath(stroke.path, line..color = stroke.color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user