hydrolysis-m3 0.3.0

Material 3 widget theme for WaterUI self-drawn backends
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
use crate::{Brush, DrawContext, PressWave, PressWaves, WidgetInteractionState};
use vello::kurbo::{Point, Rect, RoundedRectRadii};
use vello::peniko::Color;

/// Minimum ripple diameter (Material Web `MINIMUM_PRESS_DIAMETER`): small
/// targets still produce a ripple at least this wide.
const RIPPLE_MINIMUM_DIAMETER: f64 = 48.0;

/// `StateTokens.HoverStateLayerOpacity`.
pub const HOVER_STATE_LAYER_OPACITY: f32 = 0.08;
/// `StateTokens.FocusStateLayerOpacity`.
pub const FOCUS_STATE_LAYER_OPACITY: f32 = 0.1;
/// `StateTokens.PressedStateLayerOpacity`.
pub const PRESSED_STATE_LAYER_OPACITY: f32 = 0.1;
/// `StateTokens.DraggedStateLayerOpacity`.
pub const DRAGGED_STATE_LAYER_OPACITY: f32 = 0.16;

/// The dominant resting state-layer opacity for `state`: the renderer-sampled
/// animated value when one is in flight, otherwise the MD3 token for the
/// active boolean state (focus outranks hover).
fn resolved_state_layer_opacity(state: WidgetInteractionState) -> f32 {
    if state.focus_visible {
        state.focus_progress * FOCUS_STATE_LAYER_OPACITY
    } else if state.state_layer_opacity > 0.0 {
        state.state_layer_opacity
    } else if state.hovered {
        HOVER_STATE_LAYER_OPACITY
    } else {
        0.0
    }
}

/// The press waves to draw for `state`: the renderer-sampled waves when any
/// are in flight, otherwise — for states constructed without renderer
/// animation (static previews, tests) — a single full-coverage wave at the
/// MD3 pressed token while the state reads as pressed.
fn resolved_press_waves(state: WidgetInteractionState) -> PressWaves {
    if !state.press_waves.is_empty() {
        return state.press_waves;
    }
    let mut waves = PressWaves::EMPTY;
    if state.pressed {
        waves.push(PressWave {
            origin: None,
            progress: 1.0,
            opacity: PRESSED_STATE_LAYER_OPACITY,
        });
    }
    waves
}

/// Initial ripple size as a fraction of the full diameter: a wave starts at
/// this scale over its press point and grows to full size as the renderer's
/// press-grow animation advances the wave's progress from 0 to 1.
const RIPPLE_INITIAL_SCALE: f64 = 0.4;

/// The full Material ripple diameter for a target: the surface diagonal,
/// floored at [`RIPPLE_MINIMUM_DIAMETER`]. Waves are drawn fresh each frame
/// from the sampled interaction state — [`ripple_kinematics`] scales each
/// from the initial fraction up to full size while its center drifts from its
/// press point to the surface center.
pub fn ripple_diameter(bounds: Rect) -> f64 {
    bounds
        .width()
        .hypot(bounds.height())
        .max(RIPPLE_MINIMUM_DIAMETER)
}

/// Material ripple kinematics for one frame: given the wave's convergence
/// `target` center and full `diameter`, returns the wave's current center and
/// radius.
///
/// The center drifts linearly from the wave's press point (already mapped by
/// the renderer into the same coordinate space; `target` when absent) to
/// `target`, and the radius grows from [`RIPPLE_INITIAL_SCALE`] of
/// `diameter` to the full size, both driven by the wave's progress.
fn ripple_kinematics(target: Point, diameter: f64, wave: PressWave) -> (Point, f64) {
    let progress = f64::from(wave.progress.clamp(0.0, 1.0));
    let origin = wave.origin.unwrap_or(target);
    let center = Point::new(
        (target.x - origin.x).mul_add(progress, origin.x),
        (target.y - origin.y).mul_add(progress, origin.y),
    );
    let scale = (1.0 - RIPPLE_INITIAL_SCALE).mul_add(progress, RIPPLE_INITIAL_SCALE);
    (center, diameter * 0.5 * scale)
}

/// Fills every visible wave as a solid circle at its current animated
/// geometry. The waves are ordered oldest to newest, so overlapping ripples
/// from rapid re-presses composite naturally (Material semantics: older waves keep
/// fading while the newest grows).
fn fill_waves(
    draw: &mut dyn DrawContext,
    target: Point,
    diameter: f64,
    color: Color,
    waves: PressWaves,
) {
    for wave in waves.iter() {
        if wave.opacity <= 0.0 {
            continue;
        }
        let (center, radius) = ripple_kinematics(target, diameter, wave);
        let brush = Brush::from(color.with_alpha(wave.opacity.clamp(0.0, 1.0)));
        draw.fill_circle(center, radius, &brush);
    }
}

/// Draws the resting state layer (hover/focus tint) into `bounds`.
fn draw_state_tint_rounded(
    draw: &mut dyn DrawContext,
    bounds: Rect,
    radii: RoundedRectRadii,
    color: Color,
    state_opacity: f32,
) {
    if state_opacity > 0.0 {
        draw.push_rounded_layer(state_opacity, bounds, radii);
        draw.fill_rounded_rect(bounds, radii, &Brush::from(color));
        draw.pop_layer();
    }
}

pub fn draw_bounded(
    draw: &mut dyn DrawContext,
    bounds: Rect,
    radii: RoundedRectRadii,
    color: Color,
    state: WidgetInteractionState,
) {
    draw_state_tint_rounded(
        draw,
        bounds,
        radii,
        color,
        resolved_state_layer_opacity(state),
    );

    let waves = resolved_press_waves(state);
    if waves.is_empty() {
        return;
    }

    // Solid Material ripple waves, drawn fresh each frame at their current
    // animated geometry: the retained tree re-encodes the scene every frame
    // while press animations run, so each wave's sampled progress/origin
    // drives its growth and drift directly.
    draw.push_rounded_layer(1.0, bounds, radii);
    fill_waves(draw, bounds.center(), ripple_diameter(bounds), color, waves);
    draw.pop_layer();
}

pub fn draw_unbounded_circle(
    draw: &mut dyn DrawContext,
    center: Point,
    radius: f64,
    color: Color,
    state: WidgetInteractionState,
) {
    let state_opacity = resolved_state_layer_opacity(state);
    if state_opacity > 0.0 {
        draw.push_layer(state_opacity, None);
        draw.fill_circle(center, radius, &Brush::from(color));
        draw.pop_layer();
    }

    let waves = resolved_press_waves(state);
    if waves.is_empty() {
        return;
    }
    // An unbounded halo caps the wave at exactly `radius` — not the disc's
    // diagonal and not the bounded-ripple minimum diameter — so the wave
    // target is the requested diameter directly.
    draw.push_layer(1.0, None);
    fill_waves(draw, center, radius * 2.0, color, waves);
    draw.pop_layer();
}

#[cfg(test)]
mod tests {
    use super::{PRESSED_STATE_LAYER_OPACITY, RIPPLE_MINIMUM_DIAMETER, ripple_diameter};
    use crate::{
        Brush, DrawContext, PressWave, PressWaves, WidgetInteractionState, theme::state_layer,
    };
    use std::path::Path;
    use vello::kurbo::{Affine, BezPath, Circle, Line, Point, Rect, RoundedRect, RoundedRectRadii};
    use vello::peniko::Color;
    use waterui_graphics::{
        GpuContext, GpuFrame, GpuRuntime, GpuSurface, GpuView, OffscreenRenderConfig, OffscreenSize,
    };

    #[test]
    fn material_ripple_diameter_spans_diagonal_with_minimum() {
        // Large surface: ripple diameter is the diagonal so the solid circle
        // covers the whole target at full scale.
        let wide = Rect::new(0.0, 0.0, 100.0, 40.0);
        assert!((ripple_diameter(wide) - 100.0_f64.hypot(40.0)).abs() < 1e-6);

        // Tiny surface: floored at the Material minimum press diameter.
        let tiny = Rect::new(0.0, 0.0, 20.0, 20.0);
        assert_eq!(ripple_diameter(tiny), RIPPLE_MINIMUM_DIAMETER);
    }

    fn pressed_state(waves: &[PressWave]) -> WidgetInteractionState {
        let mut press_waves = PressWaves::EMPTY;
        for wave in waves {
            press_waves.push(*wave);
        }
        WidgetInteractionState {
            pressed: true,
            press_waves,
            ..WidgetInteractionState::NONE
        }
    }

    #[test]
    fn material_ripple_animates_from_press_point_to_full_coverage() {
        // Mid-press: the ripple sits between the press point and the bounds
        // center, at a radius between the initial fraction and full size.
        let bounds = Rect::new(0.0, 0.0, 100.0, 40.0);
        let origin = Point::new(10.0, 12.0);
        let mut recorder = RecordingDrawContext::default();
        state_layer::draw_bounded(
            &mut recorder,
            bounds,
            8.0.into(),
            Color::new([1.0, 1.0, 1.0, 1.0]),
            pressed_state(&[PressWave {
                origin: Some(origin),
                progress: 0.5,
                opacity: 0.12,
            }]),
        );
        let circle = recorder
            .single_circle()
            .expect("mid-press ripple must fill a solid circle");
        assert_eq!(
            circle.center,
            Point::new(30.0, 16.0),
            "center drifts halfway from the press point to the bounds center"
        );
        let full_radius = ripple_diameter(bounds) * 0.5;
        assert!(
            (circle.radius - full_radius * 0.7).abs() < 1e-6,
            "radius is halfway between the 0.4 initial fraction and full size"
        );
    }

    #[test]
    fn material_ripple_press_layer_is_a_solid_circle() {
        // At full progress the ripple covers the target: a solid circle (no
        // soft-edge gradient) centered in bounds at the full ripple diameter.
        let bounds = Rect::new(0.0, 0.0, 100.0, 40.0);
        let mut recorder = RecordingDrawContext::default();
        state_layer::draw_bounded(
            &mut recorder,
            bounds,
            8.0.into(),
            Color::new([1.0, 1.0, 1.0, 1.0]),
            pressed_state(&[PressWave {
                origin: Some(Point::new(10.0, 12.0)),
                progress: 1.0,
                opacity: 0.12,
            }]),
        );
        let circle = recorder
            .single_circle()
            .expect("press ripple must fill a solid circle");
        assert_eq!(circle.center, Point::new(50.0, 20.0), "circle is centered");
        assert!(
            (circle.radius - ripple_diameter(bounds) * 0.5).abs() < 1e-6,
            "circle radius is half the ripple diameter"
        );
        assert!(
            matches!(circle.brush, RecordedBrush::Solid(alpha) if (alpha - 0.12).abs() < 1e-6),
            "ripple is a solid color at the press opacity, not a gradient"
        );
    }

    #[test]
    fn unbounded_circle_ripple_converges_to_the_requested_radius() {
        // Compose caps an unbounded ripple at `StateLayerSize / 2`: the wave
        // converges to the halo radius itself, not the disc's diagonal.
        let center = Point::new(50.0, 30.0);
        let radius = 20.0;
        let mut recorder = RecordingDrawContext::default();
        state_layer::draw_unbounded_circle(
            &mut recorder,
            center,
            radius,
            Color::new([1.0, 1.0, 1.0, 1.0]),
            pressed_state(&[PressWave {
                origin: None,
                progress: 1.0,
                opacity: 0.12,
            }]),
        );
        let circle = recorder
            .single_circle()
            .expect("press ripple must fill a solid circle");
        assert_eq!(circle.center, center, "wave converges on the halo center");
        assert!(
            (circle.radius - radius).abs() < 1e-6,
            "wave radius {} must converge to the halo radius {}",
            circle.radius,
            radius
        );
    }

    #[test]
    fn overlapping_press_waves_draw_oldest_to_newest() {
        // Rapid re-press: the older, released wave keeps fading at full size
        // while the fresh wave grows from its own press point — both are
        // filled the same frame, oldest first.
        let bounds = Rect::new(0.0, 0.0, 100.0, 40.0);
        let mut recorder = RecordingDrawContext::default();
        state_layer::draw_bounded(
            &mut recorder,
            bounds,
            8.0.into(),
            Color::new([1.0, 1.0, 1.0, 1.0]),
            pressed_state(&[
                PressWave {
                    origin: Some(Point::new(10.0, 12.0)),
                    progress: 1.0,
                    opacity: 0.06,
                },
                PressWave {
                    origin: Some(Point::new(80.0, 30.0)),
                    progress: 0.0,
                    opacity: 0.12,
                },
            ]),
        );
        let circles = &recorder.filled_circles;
        assert_eq!(circles.len(), 2, "both waves must be filled");
        assert_eq!(
            circles[0].center,
            Point::new(50.0, 20.0),
            "the older wave is centered at full coverage"
        );
        assert!(
            matches!(circles[0].brush, RecordedBrush::Solid(alpha) if (alpha - 0.06).abs() < 1e-6),
            "the older wave fades at its own sampled opacity"
        );
        assert_eq!(
            circles[1].center,
            Point::new(80.0, 30.0),
            "the fresh wave starts over its own press point"
        );
        let full_radius = ripple_diameter(bounds) * 0.5;
        assert!(
            (circles[1].radius - full_radius * 0.4).abs() < 1e-6,
            "the fresh wave starts at the initial scale fraction"
        );
    }

    #[test]
    fn static_pressed_state_synthesizes_a_full_coverage_wave() {
        // A pressed state constructed without renderer animation (static
        // previews, tests) still renders a press layer: one centered,
        // full-coverage wave at the MD3 pressed token.
        let bounds = Rect::new(0.0, 0.0, 100.0, 40.0);
        let mut recorder = RecordingDrawContext::default();
        state_layer::draw_bounded(
            &mut recorder,
            bounds,
            8.0.into(),
            Color::new([1.0, 1.0, 1.0, 1.0]),
            WidgetInteractionState {
                pressed: true,
                ..WidgetInteractionState::NONE
            },
        );
        let circle = recorder
            .single_circle()
            .expect("static pressed state must fill a press layer");
        assert_eq!(circle.center, Point::new(50.0, 20.0));
        assert!(
            matches!(
                circle.brush,
                RecordedBrush::Solid(alpha)
                    if (alpha - PRESSED_STATE_LAYER_OPACITY).abs() < 1e-6
            ),
            "synthesized wave uses StateTokens.PressedStateLayerOpacity"
        );
    }

    #[derive(Debug, Clone, Copy)]
    enum RecordedBrush {
        Solid(f32),
        Gradient,
    }

    #[derive(Debug, Clone, Copy)]
    struct RecordedCircle {
        center: Point,
        radius: f64,
        brush: RecordedBrush,
    }

    #[derive(Default)]
    struct RecordingDrawContext {
        filled_circles: Vec<RecordedCircle>,
    }

    impl RecordingDrawContext {
        fn record_brush(brush: &Brush) -> RecordedBrush {
            match brush {
                Brush::Solid(color) => RecordedBrush::Solid(color.components[3]),
                Brush::Gradient(_) => RecordedBrush::Gradient,
            }
        }

        fn single_circle(&self) -> Option<RecordedCircle> {
            assert!(
                self.filled_circles.len() <= 1,
                "expected at most one filled circle, recorded {}",
                self.filled_circles.len()
            );
            self.filled_circles.first().copied()
        }
    }

    impl DrawContext for RecordingDrawContext {
        fn fill_rect(&mut self, _rect: Rect, _brush: &Brush) {}
        fn fill_rounded_rect(&mut self, _rect: Rect, _radii: RoundedRectRadii, _brush: &Brush) {}
        fn stroke_rect(&mut self, _rect: Rect, _brush: &Brush, _width: f64) {}
        fn stroke_rounded_rect(
            &mut self,
            _rect: Rect,
            _radii: RoundedRectRadii,
            _brush: &Brush,
            _width: f64,
        ) {
        }
        fn stroke_line(&mut self, _from: Point, _to: Point, _brush: &Brush, _width: f64) {}
        fn stroke_circle(&mut self, _center: Point, _radius: f64, _brush: &Brush, _width: f64) {}
        fn fill_circle(&mut self, center: Point, radius: f64, brush: &Brush) {
            self.filled_circles.push(RecordedCircle {
                center,
                radius,
                brush: Self::record_brush(brush),
            });
        }
        fn fill_path(&mut self, _path: &BezPath, _brush: &Brush) {}
        fn stroke_path(&mut self, _path: &BezPath, _brush: &Brush, _width: f64) {}
        fn draw_shadow(
            &mut self,
            _rect: Rect,
            _radii: RoundedRectRadii,
            _offset: vello::kurbo::Vec2,
            _blur: f64,
            _color: Color,
        ) {
        }
        fn push_layer(&mut self, _alpha: f32, _clip: Option<&Rect>) {}
        fn push_rounded_layer(&mut self, _alpha: f32, _clip: Rect, _radii: RoundedRectRadii) {}
        fn pop_layer(&mut self) {}
        fn push_transform(&mut self, _affine: Affine) {}
        fn pop_transform(&mut self) {}
    }

    struct VelloTestDrawContext<'a> {
        scene: &'a mut vello::Scene,
    }

    impl VelloTestDrawContext<'_> {
        fn fill_shape(&mut self, shape: &impl vello::kurbo::Shape, brush: &Brush) {
            match brush {
                Brush::Solid(color) => self.scene.fill(
                    vello::peniko::Fill::NonZero,
                    Affine::IDENTITY,
                    color,
                    None,
                    shape,
                ),
                Brush::Gradient(gradient) => self.scene.fill(
                    vello::peniko::Fill::NonZero,
                    Affine::IDENTITY,
                    gradient,
                    None,
                    shape,
                ),
            }
        }

        fn stroke_shape(&mut self, shape: &impl vello::kurbo::Shape, brush: &Brush, width: f64) {
            let stroke = vello::kurbo::Stroke::new(width);
            match brush {
                Brush::Solid(color) => {
                    self.scene
                        .stroke(&stroke, Affine::IDENTITY, color, None, shape);
                }
                Brush::Gradient(gradient) => {
                    self.scene
                        .stroke(&stroke, Affine::IDENTITY, gradient, None, shape);
                }
            }
        }
    }

    impl DrawContext for VelloTestDrawContext<'_> {
        fn fill_rect(&mut self, rect: Rect, brush: &Brush) {
            self.fill_shape(&rect, brush);
        }

        fn fill_rounded_rect(&mut self, rect: Rect, radii: RoundedRectRadii, brush: &Brush) {
            self.fill_shape(&RoundedRect::from_rect(rect, radii), brush);
        }

        fn stroke_rect(&mut self, rect: Rect, brush: &Brush, width: f64) {
            self.stroke_shape(&rect, brush, width);
        }

        fn stroke_rounded_rect(
            &mut self,
            rect: Rect,
            radii: RoundedRectRadii,
            brush: &Brush,
            width: f64,
        ) {
            self.stroke_shape(&RoundedRect::from_rect(rect, radii), brush, width);
        }

        fn stroke_line(&mut self, from: Point, to: Point, brush: &Brush, width: f64) {
            self.stroke_shape(&Line::new(from, to), brush, width);
        }

        fn stroke_circle(&mut self, center: Point, radius: f64, brush: &Brush, width: f64) {
            self.stroke_shape(&Circle::new(center, radius), brush, width);
        }

        fn fill_circle(&mut self, center: Point, radius: f64, brush: &Brush) {
            self.fill_shape(&Circle::new(center, radius), brush);
        }

        fn fill_path(&mut self, path: &BezPath, brush: &Brush) {
            self.fill_shape(path, brush);
        }

        fn stroke_path(&mut self, path: &BezPath, brush: &Brush, width: f64) {
            self.stroke_shape(path, brush, width);
        }

        fn draw_shadow(
            &mut self,
            rect: Rect,
            radii: RoundedRectRadii,
            offset: vello::kurbo::Vec2,
            blur: f64,
            color: Color,
        ) {
            let radius = radii
                .as_single_radius()
                .expect("vello blurred shadows require uniform corner radii");
            self.scene.draw_blurred_rounded_rect(
                Affine::IDENTITY,
                rect + offset,
                color,
                radius,
                blur.max(0.0),
            );
        }

        fn push_layer(&mut self, alpha: f32, clip: Option<&Rect>) {
            let clip = clip
                .copied()
                .unwrap_or(Rect::new(-1.0e9, -1.0e9, 1.0e9, 1.0e9));
            self.scene.push_layer(
                vello::peniko::Fill::NonZero,
                vello::peniko::BlendMode::default(),
                alpha,
                Affine::IDENTITY,
                &clip,
            );
        }

        fn push_rounded_layer(&mut self, alpha: f32, clip: Rect, radii: RoundedRectRadii) {
            let clip = RoundedRect::from_rect(clip, radii);
            self.scene.push_layer(
                vello::peniko::Fill::NonZero,
                vello::peniko::BlendMode::default(),
                alpha,
                Affine::IDENTITY,
                &clip,
            );
        }

        fn pop_layer(&mut self) {
            self.scene.pop_layer();
        }

        fn push_transform(&mut self, _affine: Affine) {
            panic!("ripple visual test does not use transforms");
        }

        fn pop_transform(&mut self) {
            panic!("ripple visual test does not use transforms");
        }
    }

    struct RippleVisualRenderer {
        renderer: Option<vello::Renderer>,
        scene: vello::Scene,
    }

    impl RippleVisualRenderer {
        fn new() -> Self {
            Self {
                renderer: None,
                scene: vello::Scene::new(),
            }
        }
    }

    impl GpuView for RippleVisualRenderer {
        #[expect(
            clippy::future_not_send,
            reason = "GpuView runs on the render thread; this future borrows the non-Send `GpuContext`/`Environment`"
        )]
        async fn setup(&mut self, ctx: &GpuContext<'_>, _env: &mut waterui_core::Environment) {
            self.renderer = Some(
                vello::Renderer::new(
                    ctx.device,
                    vello::RendererOptions {
                        use_cpu: false,
                        antialiasing_support: vello::AaSupport::area_only(),
                        num_init_threads: std::num::NonZeroUsize::new(1),
                        pipeline_cache: None,
                    },
                )
                .expect("failed to create ripple visual vello renderer"),
            );
        }

        fn render(&mut self, frame: &mut GpuFrame) {
            self.scene.reset();
            let bounds = Rect::new(24.0, 24.0, 216.0, 96.0);
            let mut draw = VelloTestDrawContext {
                scene: &mut self.scene,
            };
            draw.fill_rounded_rect(
                bounds,
                20.0.into(),
                &Brush::from(Color::new([0.40, 0.31, 0.64, 1.0])),
            );
            let mut press_waves = PressWaves::EMPTY;
            press_waves.push(PressWave {
                origin: Some(Point::new(56.0, 48.0)),
                progress: 0.72,
                opacity: 0.30,
            });
            state_layer::draw_bounded(
                &mut draw,
                bounds,
                20.0.into(),
                Color::new([1.0, 1.0, 1.0, 1.0]),
                WidgetInteractionState {
                    pressed: true,
                    press_waves,
                    ..WidgetInteractionState::NONE
                },
            );

            self.renderer
                .as_mut()
                .expect("ripple visual renderer was not set up")
                .render_to_texture(
                    frame.device,
                    frame.queue,
                    &self.scene,
                    &frame.view,
                    &vello::RenderParams {
                        base_color: Color::WHITE,
                        width: frame.width,
                        height: frame.height,
                        antialiasing_method: vello::AaConfig::Area,
                    },
                )
                .expect("ripple visual vello render failed");
        }
    }
    #[test]
    #[ignore = "writes a visual acceptance PNG for direct image review"]
    fn material_ripple_visual_snapshot() {
        let mut env = waterui_core::Environment::new();
        let runtime = pollster::block_on(GpuRuntime::new())
            .expect("ripple visual test requires a high-performance GPU");
        let output = pollster::block_on(
            GpuSurface::new(RippleVisualRenderer::new()).render_offscreen(
                &runtime,
                OffscreenRenderConfig::new(
                    OffscreenSize::try_from_pixels(240, 120).expect("static size must be valid"),
                )
                .format(vello::wgpu::TextureFormat::Rgba8Unorm),
                &mut env,
            ),
        )
        .expect("ripple visual offscreen render failed");
        let output_path = Path::new("target/hydrolysis-m3-visual/material-ripple-solid.png");
        std::fs::create_dir_all(
            output_path
                .parent()
                .expect("ripple visual output path must have parent"),
        )
        .expect("failed to create ripple visual output directory");
        output
            .save_png(output_path)
            .expect("failed to save ripple visual output");
    }
}