Keep only travelling composer border highlight
Remove glow, full-border tint, and reduced-motion overlay so the running composer paints only a short constant-speed arc. Expand focused arc tests and document verification limits.
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# Composer running border: highlight only
|
||||
|
||||
The running state now paints one short highlight travelling round the composer
|
||||
pill's edge at constant arc-length speed, and nothing else. It supersedes the
|
||||
glow, full-border tint and reduced-motion overlay described in
|
||||
`composer-running-border.md` and `composer-running-border-arc.md`.
|
||||
|
||||
## Changes
|
||||
|
||||
- `lib/features/chat/conversation/composer_running_arc.dart`
|
||||
- The highlight covers `runningHighlightSpan` (12%) of the outline, not a
|
||||
38% band. Its colour runs along its own length: transparent, `primary`,
|
||||
`tertiary`, transparent (stops 0, .3, .6, 1).
|
||||
- `runningHighlightStrokes` returns the visible pieces as plain stroke paths
|
||||
with colours. These are the only things painted: no blur, glow, shadow, fill
|
||||
or whole-border stroke.
|
||||
- `lib/features/chat/conversation/composer_running_border.dart`
|
||||
- The painter draws only those strokes, at the existing 2 px stroke width.
|
||||
The glow (`MaskFilter.blur`) and the 70% static overlay are removed.
|
||||
- Reduced motion (`MediaQuery.disableAnimations`) paints nothing. The normal
|
||||
composer outline shows alone, and the controller never ticks.
|
||||
- Period (2.75 s), colours and linear lap are unchanged.
|
||||
- `test/features/chat/conversation/composer_running_arc_test.dart` covers the
|
||||
origin speed and wrap, colour stops, the short segment, the arc split at the
|
||||
outline start, painted coverage per lap, and stroke bounds.
|
||||
|
||||
## Focused results
|
||||
|
||||
- `tool/memwatch/full.sh 'test/features/chat/conversation/composer_running_arc_test.dart test/features/chat/conversation/chat_composer_running_test.dart'`
|
||||
→ PASS 19 passed, 0 failed (peak ~954 MB, exit 0). The verdict names only these two paths.
|
||||
- `tool/analyze.sh` → clean, exit 0.
|
||||
- `dart format --set-exit-if-changed` on the three changed files → clean.
|
||||
|
||||
## Affected states
|
||||
|
||||
- Running, default: the highlight travels; no other paint is drawn (stroke-level tests).
|
||||
- Running, reduced motion: no highlight; `chat-composer-running-border` is still
|
||||
mounted and ticks zero times (widget test).
|
||||
- Turn ended: border gone, no ticker (widget test).
|
||||
|
||||
## Not verified
|
||||
|
||||
- Light and dark captures were requested but not made. This stage does not build
|
||||
or capture UI; ui-review owns that.
|
||||
- Pixel output is not tested. The "paints nothing under reduced motion" rule is
|
||||
enforced by the painter's early return and not by a canvas assertion.
|
||||
- Not profiled on device; mobile and browser behaviour unverified.
|
||||
@@ -9,22 +9,22 @@ const _primary = Color(0xFF3366FF);
|
||||
const _tertiary = Color(0xFFFF6633);
|
||||
|
||||
/// The pill outline as the painter builds it, measured by arc length.
|
||||
List<PathMetric> _outline(Size size, {double radius = 24}) {
|
||||
final path = RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(radius),
|
||||
).getOuterPath(Offset.zero & size);
|
||||
return path.computeMetrics().toList();
|
||||
}
|
||||
Path _outlinePath(Size size, {double radius = 24}) => RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(radius),
|
||||
).getOuterPath(Offset.zero & size);
|
||||
|
||||
List<PathMetric> _outline(Size size, {double radius = 24}) =>
|
||||
_outlinePath(size, radius: radius).computeMetrics().toList();
|
||||
|
||||
double _length(List<PathMetric> metrics) =>
|
||||
metrics.fold<double>(0, (sum, m) => sum + m.length);
|
||||
|
||||
/// The arc the visible band covers: from its first piece to its last. The
|
||||
/// pieces overlap by a seam each, so their own lengths would overcount.
|
||||
/// The arc the visible highlight covers: from its first piece to its last.
|
||||
/// The pieces overlap by a seam each, so their own lengths would overcount.
|
||||
double _visibleSpan(List<RunningArcSegment> segments) =>
|
||||
segments.last.end - segments.first.start;
|
||||
|
||||
/// Colours that differ only by float rounding at a band edge still match.
|
||||
/// Colours that differ only by float rounding at a stop still match.
|
||||
void _expectSameColor(Color actual, Color expected, {required String reason}) {
|
||||
expect(actual.a, closeTo(expected.a, 1e-6), reason: reason);
|
||||
expect(actual.r, closeTo(expected.r, 1e-6), reason: reason);
|
||||
@@ -32,6 +32,14 @@ void _expectSameColor(Color actual, Color expected, {required String reason}) {
|
||||
expect(actual.b, closeTo(expected.b, 1e-6), reason: reason);
|
||||
}
|
||||
|
||||
/// The pieces cover [span] of the outline. Each overlaps its neighbour by a
|
||||
/// seam (a half pixel on each side), so their summed lengths may exceed it by
|
||||
/// about a pixel per piece; path metrics add about a pixel of approximation.
|
||||
void _expectCovered(double covered, int pieces, double span) {
|
||||
expect(covered, greaterThanOrEqualTo(span - 1));
|
||||
expect(covered, lessThanOrEqualTo(span + pieces + 1));
|
||||
}
|
||||
|
||||
void main() {
|
||||
const size = Size(320, 48);
|
||||
final metrics = _outline(size);
|
||||
@@ -86,43 +94,34 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('colours wrap: a fraction and its +1 are the same colour', () {
|
||||
for (var f = 0.0; f < 1; f += .02) {
|
||||
test(
|
||||
'the colour fades in, turns tertiary and fades out along its length',
|
||||
() {
|
||||
expect(runningHighlightColorAt(0, _primary, _tertiary).a, 0);
|
||||
expect(runningHighlightColorAt(1, _primary, _tertiary).a, 0);
|
||||
_expectSameColor(
|
||||
runningHighlightColorAt(f + 1, _primary, _tertiary),
|
||||
runningHighlightColorAt(f, _primary, _tertiary),
|
||||
reason: 'f=$f',
|
||||
runningHighlightColorAt(.3, _primary, _tertiary),
|
||||
_primary,
|
||||
reason: 'primary stop',
|
||||
);
|
||||
}
|
||||
expect(runningHighlightColorAt(0, _primary, _tertiary).a, 0);
|
||||
_expectSameColor(
|
||||
runningHighlightColorAt(.6, _primary, _tertiary),
|
||||
_tertiary,
|
||||
reason: 'tertiary stop',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('colour is transparent outside the highlight', () {
|
||||
expect(runningHighlightColorAt(-.1, _primary, _tertiary).a, 0);
|
||||
expect(runningHighlightColorAt(1.1, _primary, _tertiary).a, 0);
|
||||
});
|
||||
|
||||
test('the highlight travels by arc: a shift of one step shifts colours', () {
|
||||
// The colour at a given arc point, one step later, equals the colour one
|
||||
// step earlier at a point shifted back by the arc that step covers.
|
||||
const dt = .1;
|
||||
final arc = dt * length;
|
||||
for (var x = 0.0; x < length; x += length / 40) {
|
||||
final before = runningHighlightColorAt(
|
||||
(x - runningHighlightOrigin(0, length)) / length,
|
||||
_primary,
|
||||
_tertiary,
|
||||
);
|
||||
final after = runningHighlightColorAt(
|
||||
(x + arc - runningHighlightOrigin(dt, length)) / length,
|
||||
_primary,
|
||||
_tertiary,
|
||||
);
|
||||
_expectSameColor(after, before, reason: 'x=$x');
|
||||
}
|
||||
});
|
||||
|
||||
test('the visible band covers the same arc on a long and a square shape', () {
|
||||
// The band is 38% of a lap. Measured along the outline it has the same
|
||||
// length whatever the aspect, which an angle-based sweep would not give.
|
||||
final long = _outline(const Size(320, 48));
|
||||
final square = _outline(const Size(120, 120), radius: 12);
|
||||
for (final shape in [long, square]) {
|
||||
test('the highlight is a short segment, never a trail round the edge', () {
|
||||
for (final shape in [
|
||||
_outline(const Size(320, 48)),
|
||||
_outline(const Size(120, 120), radius: 12),
|
||||
]) {
|
||||
final len = _length(shape);
|
||||
final segments = runningHighlightSegments(
|
||||
progress: .3,
|
||||
@@ -130,11 +129,12 @@ void main() {
|
||||
primary: _primary,
|
||||
tertiary: _tertiary,
|
||||
);
|
||||
expect(_visibleSpan(segments), closeTo(.38 * len, 2 * 3 + 1));
|
||||
expect(_visibleSpan(segments), closeTo(runningHighlightSpan * len, 7));
|
||||
expect(runningHighlightSpan, lessThanOrEqualTo(.15));
|
||||
}
|
||||
});
|
||||
|
||||
test('the visible segments tile the outline without gaps', () {
|
||||
test('the visible segments tile the highlight without gaps', () {
|
||||
final segments = runningHighlightSegments(
|
||||
progress: .6,
|
||||
length: length,
|
||||
@@ -150,6 +150,58 @@ void main() {
|
||||
expect(segments.last.end, lessThanOrEqualTo(length));
|
||||
});
|
||||
|
||||
test('a highlight across the outline start is split into two pieces', () {
|
||||
// At progress .99 the segment begins near the end and wraps to the start.
|
||||
final segments = runningHighlightSegments(
|
||||
progress: .99,
|
||||
length: length,
|
||||
primary: _primary,
|
||||
tertiary: _tertiary,
|
||||
);
|
||||
expect(segments.any((s) => s.start == 0), isTrue);
|
||||
expect(segments.any((s) => s.end == length), isTrue);
|
||||
_expectCovered(
|
||||
segments.fold<double>(0, (s, p) => s + p.end - p.start),
|
||||
segments.length,
|
||||
runningHighlightSpan * length,
|
||||
);
|
||||
});
|
||||
|
||||
test('only the travelling segment is painted, not the whole outline', () {
|
||||
for (var k = 0; k < 8; k++) {
|
||||
final strokes = runningHighlightStrokes(
|
||||
outline: _outlinePath(size),
|
||||
progress: k / 8,
|
||||
primary: _primary,
|
||||
tertiary: _tertiary,
|
||||
);
|
||||
final painted = strokes.fold<double>(
|
||||
0,
|
||||
(sum, s) => sum + _length(s.path.computeMetrics().toList()),
|
||||
);
|
||||
expect(strokes, isNotEmpty, reason: 'lap $k');
|
||||
_expectCovered(painted, strokes.length, runningHighlightSpan * length);
|
||||
expect(painted, lessThan(length * .2), reason: 'lap $k');
|
||||
}
|
||||
});
|
||||
|
||||
test('strokes are plain colour strokes inside the outline bounds', () {
|
||||
final strokes = runningHighlightStrokes(
|
||||
outline: _outlinePath(size),
|
||||
progress: .4,
|
||||
primary: _primary,
|
||||
tertiary: _tertiary,
|
||||
);
|
||||
for (final stroke in strokes) {
|
||||
expect(stroke.color.a, inInclusiveRange(0, 1));
|
||||
final bounds = stroke.path.getBounds();
|
||||
expect(bounds.left, greaterThanOrEqualTo(-1));
|
||||
expect(bounds.top, greaterThanOrEqualTo(-1));
|
||||
expect(bounds.right, lessThanOrEqualTo(size.width + 1));
|
||||
expect(bounds.bottom, lessThanOrEqualTo(size.height + 1));
|
||||
}
|
||||
});
|
||||
|
||||
test('runningArcPath draws the requested arc of the outline', () {
|
||||
final piece = runningArcPath(metrics, 10, 30);
|
||||
final pieceMetrics = piece.computeMetrics().toList();
|
||||
|
||||
Reference in New Issue
Block a user