euv-example 0.48.0

Cross-platform native showcase application demonstrating euv fine-grained reactivity, multi-mode rendering, window controls, and euv-ui components.
Documentation
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
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
use super::*;

/// Mounts the real-time Gyroscope Liquid Water Studio page with an adaptive interactive liquid vessel, 6-DOF `use_device_motion()` synchronization, edge-to-edge fullscreen portal, and SI physics inspector rail.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted `/water` showcase page handle.
pub fn mount_water_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
    let host: GameEngineHost = state.get_water_host().clone();
    let scene: GyroLiquidGameScene = state.get_or_init_water_scene();
    let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
    let motion_sig: Signal<DeviceMotionSample> = use_device_motion();
    scene.bind_device_motion(motion_sig);
    let _: bool = stats_sig.set_if_changed(scene.stats());
    let viewport: NodeId = host.mount_viewport(
        Style::default()
            .width(Length::Percent(100.0))
            .height(Length::Percent(100.0)),
    );
    let vp_sig: Signal<Size> = use_viewport_size();
    let vp_frame_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        let h: f32 = adaptive_viewport_height(vp_sig.get().get_height());
        Style::default()
            .column()
            .width(Length::Percent(100.0))
            .height(Length::Px(h))
            .overflow(Overflow::Hidden)
            .border(
                live.get_geometry().get_border_width(),
                live.get_palette().get_border(),
            )
            .radius(live.get_geometry().get_radius_md())
    };
    let viewport_frame: NodeId = view! {
        column {
            bind_style: vp_frame_style
            { viewport }
        }
    };
    let fs_portal: NodeId = mount_water_fullscreen_portal(state, &scene, viewport);
    let main_card: NodeId = mount_water_viewport_card(state, viewport_frame, &scene, tokens);
    let sensor_card: NodeId = mount_water_sensor_card(state, &scene, tokens);
    let motion_card: NodeId = mount_water_motion_card(state, &scene, tokens);
    let physics_card: NodeId = mount_water_physics_card(state, &scene, tokens);
    let telemetry_card: NodeId = mount_water_telemetry_card(stats_sig, tokens);
    let rail: NodeId = view! {
        column {
            style: {
                width: Length::Percent(100.0)
                gap: SPACE_MD
            }
            { sensor_card }
            { motion_card }
            { physics_card }
            { telemetry_card }
        }
    };
    let studio: NodeId = mount_studio_layout(main_card, rail);
    let ctx: Context = current_context();
    let sync_scope: Scope = create_water_sync_scope(state, &scene, motion_sig);
    let page: NodeId = view! {
        EuvPage {
            title: WATER_TITLE.to_string()
            subtitle: WATER_SUBTITLE.to_string()
            tokens: tokens
            { studio }
            { fs_portal }
        }
    };
    ctx.get_scene().with_write(
        |tree: &mut SceneTree| {
            tree.attach_scope(page, sync_scope);
        },
        (),
    );
    page
}

/// Creates the reactive effect scope syncing live `use_device_motion()`, fill ratio, viscosity preset, and buoyant body toggles directly into `GyroLiquidGameScene`.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `&GyroLiquidGameScene` - Shareable liquid physics scene handle.
/// - `Signal<DeviceMotionSample>` - Reactive hardware device motion signal.
///
/// # Returns
///
/// - `Scope` - Ownership scope to attach to the `/water` page root node.
fn create_water_sync_scope(
    state: &ShowcaseState,
    scene: &GyroLiquidGameScene,
    motion_sig: Signal<DeviceMotionSample>,
) -> Scope {
    let host: GameEngineHost = state.get_water_host().clone();
    let fill_pct_sig: Signal<f32> = state.get_water_fill_pct();
    let visc_idx_sig: Signal<usize> = state.get_water_viscosity_idx();
    let buoyant_sig: Signal<bool> = state.get_water_buoyant_enabled();
    let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
    let scene_motion: GyroLiquidGameScene = scene.clone();
    let host_motion: GameEngineHost = host.clone();
    let scene_fill: GyroLiquidGameScene = scene.clone();
    let host_fill: GameEngineHost = host.clone();
    let scene_visc: GyroLiquidGameScene = scene.clone();
    let host_visc: GameEngineHost = host.clone();
    let scene_buoy: GyroLiquidGameScene = scene.clone();
    let host_buoy: GameEngineHost = host;
    let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
        let _: Effect = Effect::new(move || {
            let sample: DeviceMotionSample = motion_sig.get();
            if sample.get_sensor_active() {
                scene_motion.set_sensor_mode(FluidSensorMode::Auto);
                scene_motion.set_device_motion(None);
                let _: u32 = host_motion.step(WATER_STEP_DT);
                let _: bool = stats_sig.set_if_changed(scene_motion.stats());
            }
        });
        let _: Effect = Effect::new(move || {
            let pct: f32 = fill_pct_sig
                .get()
                .clamp(WATER_FILL_MIN_PCT, WATER_FILL_MAX_PCT);
            let target_ratio: f32 = (pct / 100.0).clamp(FLUID_MIN_FILL_RATIO, FLUID_MAX_FILL_RATIO);
            if (scene_fill.stats().get_fill_ratio() - target_ratio).abs() > 0.005 {
                scene_fill.set_fill_ratio(target_ratio);
                let _: u32 = host_fill.step(WATER_STEP_DT);
                let _: bool = stats_sig.set_if_changed(scene_fill.stats());
            }
        });
        let _: Effect = Effect::new(move || {
            let (visc, tension): (f32, f32) = match visc_idx_sig.get() {
                1 => (WATER_VISC_SCALE_OIL, WATER_TENSION_OIL),
                2 => (WATER_VISC_SCALE_HONEY, WATER_TENSION_HONEY),
                _ => (WATER_VISC_SCALE_WATER, WATER_TENSION_WATER),
            };
            scene_visc.set_viscosity(visc);
            scene_visc.set_surface_tension(tension);
            let _: u32 = host_visc.step(WATER_STEP_DT);
            let _: bool = stats_sig.set_if_changed(scene_visc.stats());
        });
        Effect::new(move || {
            let enabled: bool = buoyant_sig.get();
            let cur_enabled: bool = scene_buoy.stats().get_buoyant_body_count() > 0;
            if cur_enabled != enabled {
                scene_buoy.set_buoyant_bodies_enabled(enabled);
                let _: u32 = host_buoy.step(WATER_STEP_DT);
                let _: bool = stats_sig.set_if_changed(scene_buoy.stats());
            }
        })
    });
    scope
}

/// Steps `host` by one fixed physics frame and mirrors updated `GyroLiquidStats` into `stats_sig`.
///
/// # Arguments
///
/// - `&GameEngineHost` - Target liquid engine host.
/// - `&GyroLiquidGameScene` - Target liquid physics scene handle.
/// - `Signal<GyroLiquidStats>` - Reactive telemetry signal to refresh.
fn step_and_refresh_water(
    host: &GameEngineHost,
    scene: &GyroLiquidGameScene,
    stats_sig: Signal<GyroLiquidStats>,
) {
    let _: u32 = host.step(WATER_STEP_DT);
    let _: bool = stats_sig.set_if_changed(scene.stats());
}

/// Mounts the primary interactive liquid vessel card with inline quick actions (`Fullscreen`, `Rotate 90°`, `Shake`) and control hint.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `NodeId` - Adaptive-height mounted liquid viewport frame.
/// - `&GyroLiquidGameScene` - Active liquid physics scene handle.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted main vessel card handle.
fn mount_water_viewport_card(
    state: &ShowcaseState,
    viewport_frame: NodeId,
    scene: &GyroLiquidGameScene,
    tokens: ThemeTokens,
) -> NodeId {
    let host_rot: GameEngineHost = state.get_water_host().clone();
    let scene_rot: GyroLiquidGameScene = scene.clone();
    let host_shake: GameEngineHost = state.get_water_host().clone();
    let scene_shake: GyroLiquidGameScene = scene.clone();
    let fs_open_sig: Signal<bool> = state.get_water_fullscreen_open();
    let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
    let on_open_fs = move |_: &UiEvent| {
        let _: bool = fs_open_sig.set_if_changed(true);
    };
    let on_rotate_90 = move |_: &UiEvent| {
        scene_rot.set_sensor_mode(FluidSensorMode::VirtualTilt);
        scene_rot.rotate_container_by(WATER_ROT_90_RAD);
        step_and_refresh_water(&host_rot, &scene_rot, stats_sig);
    };
    let on_shake = move |_: &UiEvent| {
        scene_shake.apply_shake_impulse(WATER_SHAKE_AX_MPS2, WATER_SHAKE_AY_MPS2);
        step_and_refresh_water(&host_shake, &scene_shake, stats_sig);
    };
    let hint_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        Style::default()
            .width(Length::Percent(100.0))
            .font_size(12.0)
            .font_family(FontFamily::Monospace)
            .color(live.get_palette().get_muted_foreground())
    };
    view! {
        EuvCard {
            title: WATER_VESSEL_TITLE.to_string()
            tokens: tokens
            subtitle: WATER_VESSEL_SUB
            column {
                style: {
                    width: Length::Percent(100.0)
                    gap: SPACE_MD
                    overflow: Overflow::Hidden
                }
                { viewport_frame }
                EuvActionRow {
                    EuvButton {
                        label: BTN_WATER_FULLSCREEN.to_string()
                        tokens: tokens
                        sm()
                        on_click: on_open_fs
                    }
                    EuvButton {
                        label: BTN_WATER_ROTATE_90.to_string()
                        tokens: tokens
                        secondary()
                        sm()
                        on_click: on_rotate_90
                    }
                    EuvButton {
                        label: BTN_WATER_SHAKE.to_string()
                        tokens: tokens
                        outline()
                        sm()
                        on_click: on_shake
                    }
                }
                text {
                    bind_style: hint_style
                    { WATER_CONTROLS_HINT }
                }
            }
        }
    }
}

/// Mounts the Sensor Mode & Calibration inspector card with live IMU status badge and iOS Safari / desktop sensor permission action.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `&GyroLiquidGameScene` - Active liquid physics scene handle.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted sensor calibration card handle.
fn mount_water_sensor_card(
    state: &ShowcaseState,
    scene: &GyroLiquidGameScene,
    tokens: ThemeTokens,
) -> NodeId {
    let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
    let perm_status_sig: Signal<String> = state.get_water_sensor_perm_status();
    let scene_perm: GyroLiquidGameScene = scene.clone();
    let on_request_perm = move |_: &UiEvent| {
        scene_perm.set_sensor_mode(FluidSensorMode::Auto);
        scene_perm.set_device_motion(None);
        #[cfg(target_arch = "wasm32")]
        {
            let granted: bool = request_web_motion_permission();
            let msg: &str = if granted {
                WATER_PERM_WEB_GRANTED
            } else {
                WATER_PERM_WEB_UNAVAILABLE
            };
            let _: bool = perm_status_sig.set_if_changed(msg.to_string());
        }
        #[cfg(not(target_arch = "wasm32"))]
        {
            let _: bool = perm_status_sig.set_if_changed(WATER_PERM_DESKTOP_STATUS.to_string());
        }
        let _: bool = stats_sig.set_if_changed(scene_perm.stats());
    };
    let badge_box_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        let live_p: ThemePalette = live.get_palette();
        let active: bool = stats_sig.get().get_sensor_active();
        let bg: Color = if active {
            live_p.get_primary()
        } else {
            live_p.get_secondary()
        };
        Style::default()
            .row()
            .padding(Edges::symmetric(SPACE_XS, SPACE_SM))
            .radius(WATER_FS_PILL_RADIUS)
            .background(bg)
            .align(AlignItems::Center)
    };
    let badge_text_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        let live_p: ThemePalette = live.get_palette();
        let active: bool = stats_sig.get().get_sensor_active();
        let fg: Color = if active {
            live_p.get_primary_foreground()
        } else {
            live_p.get_secondary_foreground()
        };
        Style::default()
            .font_size(12.0)
            .font_weight(FontWeight::SemiBold)
            .color(fg)
    };
    let badge_label = move || -> String {
        if stats_sig.get().get_sensor_active() {
            WATER_STATUS_HARDWARE_IMU.to_string()
        } else {
            WATER_STATUS_VIRTUAL_TILT.to_string()
        }
    };
    let status_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        Style::default()
            .width(Length::Percent(100.0))
            .font_size(12.0)
            .color(live.get_palette().get_muted_foreground())
    };
    let status_text = move || -> String { perm_status_sig.get() };
    view! {
        EuvCard {
            title: WATER_SENSOR_CARD_TITLE.to_string()
            tokens: tokens
            subtitle: WATER_SENSOR_CARD_SUB
            column {
                style: {
                    width: Length::Percent(100.0)
                    gap: SPACE_SM
                    overflow: Overflow::Hidden
                }
                row {
                    style: {
                        width: Length::Percent(100.0)
                        flex_wrap: FlexWrap::Wrap
                        align: AlignItems::Center
                        gap: SPACE_SM
                    }
                    row {
                        bind_style: badge_box_style
                        text {
                            bind_style: badge_text_style
                            { badge_label }
                        }
                    }
                    EuvButton {
                        label: BTN_WATER_ENABLE_SENSOR.to_string()
                        tokens: tokens
                        outline()
                        sm()
                        on_click: on_request_perm
                    }
                }
                text {
                    bind_style: status_style
                    { status_text }
                }
            }
        }
    }
}

/// Mounts the Device Rotation & Motion Simulator inspector card for desktop and test rotation/tilt/shake impulses.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `&GyroLiquidGameScene` - Active liquid physics scene handle.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted motion simulator card handle.
fn mount_water_motion_card(
    state: &ShowcaseState,
    scene: &GyroLiquidGameScene,
    tokens: ThemeTokens,
) -> NodeId {
    let host: GameEngineHost = state.get_water_host().clone();
    let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
    let host_left: GameEngineHost = host.clone();
    let scene_left: GyroLiquidGameScene = scene.clone();
    let host_lvl: GameEngineHost = host.clone();
    let scene_lvl: GyroLiquidGameScene = scene.clone();
    let host_right: GameEngineHost = host.clone();
    let scene_right: GyroLiquidGameScene = scene.clone();
    let host_cw: GameEngineHost = host.clone();
    let scene_cw: GyroLiquidGameScene = scene.clone();
    let host_ccw: GameEngineHost = host.clone();
    let scene_ccw: GyroLiquidGameScene = scene.clone();
    let host_flip: GameEngineHost = host.clone();
    let scene_flip: GyroLiquidGameScene = scene.clone();
    let host_shake: GameEngineHost = host;
    let scene_shake: GyroLiquidGameScene = scene.clone();
    let on_tilt_left = move |_: &UiEvent| {
        scene_left.set_sensor_mode(FluidSensorMode::VirtualTilt);
        scene_left.set_virtual_tilt(-WATER_TILT_30_RAD, 0.0);
        step_and_refresh_water(&host_left, &scene_left, stats_sig);
    };
    let on_level = move |_: &UiEvent| {
        scene_lvl.set_sensor_mode(FluidSensorMode::VirtualTilt);
        scene_lvl.set_virtual_tilt(0.0, 0.0);
        step_and_refresh_water(&host_lvl, &scene_lvl, stats_sig);
    };
    let on_tilt_right = move |_: &UiEvent| {
        scene_right.set_sensor_mode(FluidSensorMode::VirtualTilt);
        scene_right.set_virtual_tilt(WATER_TILT_30_RAD, 0.0);
        step_and_refresh_water(&host_right, &scene_right, stats_sig);
    };
    let on_rot_cw = move |_: &UiEvent| {
        scene_cw.set_sensor_mode(FluidSensorMode::VirtualTilt);
        scene_cw.rotate_container_by(WATER_ROT_90_RAD);
        step_and_refresh_water(&host_cw, &scene_cw, stats_sig);
    };
    let on_rot_ccw = move |_: &UiEvent| {
        scene_ccw.set_sensor_mode(FluidSensorMode::VirtualTilt);
        scene_ccw.rotate_container_by(-WATER_ROT_90_RAD);
        step_and_refresh_water(&host_ccw, &scene_ccw, stats_sig);
    };
    let on_flip_180 = move |_: &UiEvent| {
        scene_flip.set_sensor_mode(FluidSensorMode::VirtualTilt);
        scene_flip.rotate_container_by(PI);
        step_and_refresh_water(&host_flip, &scene_flip, stats_sig);
    };
    let on_shake = move |_: &UiEvent| {
        scene_shake.apply_shake_impulse(WATER_SHAKE_AX_MPS2, WATER_SHAKE_AY_MPS2);
        step_and_refresh_water(&host_shake, &scene_shake, stats_sig);
    };
    let key_hint_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        Style::default()
            .width(Length::Percent(100.0))
            .font_size(12.0)
            .font_family(FontFamily::Monospace)
            .color(live.get_palette().get_muted_foreground())
    };
    view! {
        EuvCard {
            title: WATER_MOTION_CARD_TITLE.to_string()
            tokens: tokens
            subtitle: WATER_MOTION_CARD_SUB
            column {
                style: {
                    width: Length::Percent(100.0)
                    gap: SPACE_SM
                    overflow: Overflow::Hidden
                }
                EuvActionRow {
                    EuvButton {
                        label: BTN_WATER_TILT_LEFT.to_string()
                        tokens: tokens
                        outline()
                        sm()
                        on_click: on_tilt_left
                    }
                    EuvButton {
                        label: BTN_WATER_LEVEL.to_string()
                        tokens: tokens
                        outline()
                        sm()
                        on_click: on_level
                    }
                    EuvButton {
                        label: BTN_WATER_TILT_RIGHT.to_string()
                        tokens: tokens
                        outline()
                        sm()
                        on_click: on_tilt_right
                    }
                }
                EuvActionRow {
                    EuvButton {
                        label: BTN_WATER_ROT_CW.to_string()
                        tokens: tokens
                        secondary()
                        sm()
                        on_click: on_rot_cw
                    }
                    EuvButton {
                        label: BTN_WATER_ROT_CCW.to_string()
                        tokens: tokens
                        secondary()
                        sm()
                        on_click: on_rot_ccw
                    }
                    EuvButton {
                        label: BTN_WATER_FLIP_180.to_string()
                        tokens: tokens
                        outline()
                        sm()
                        on_click: on_flip_180
                    }
                    EuvButton {
                        label: BTN_WATER_SHAKE_IMPULSE.to_string()
                        tokens: tokens
                        sm()
                        on_click: on_shake
                    }
                }
                text {
                    bind_style: key_hint_style
                    { WATER_KEYBOARD_HINT }
                }
            }
        }
    }
}

/// Mounts the Physical Parameters inspector card with Fill Level slider, Viscosity segmented preset, Buoyant Objects switch, and Reset Water control.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `&GyroLiquidGameScene` - Active liquid physics scene handle.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted physical parameters card handle.
fn mount_water_physics_card(
    state: &ShowcaseState,
    scene: &GyroLiquidGameScene,
    tokens: ThemeTokens,
) -> NodeId {
    let fill_pct_sig: Signal<f32> = state.get_water_fill_pct();
    let visc_idx_sig: Signal<usize> = state.get_water_viscosity_idx();
    let buoyant_sig: Signal<bool> = state.get_water_buoyant_enabled();
    let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
    let fill_slider: NodeId = view! {
        EuvSlider {
            value: fill_pct_sig
            min: WATER_FILL_MIN_PCT
            max: WATER_FILL_MAX_PCT
            tokens: tokens
        }
    };
    let visc_options: Vec<String> = vec![
        WATER_VISC_PURE_WATER.to_string(),
        WATER_VISC_LIGHT_OIL.to_string(),
        WATER_VISC_HONEY.to_string(),
    ];
    let visc_control: NodeId = view! {
        EuvSegmented {
            options: visc_options
            selected: visc_idx_sig
            tokens: tokens
        }
    };
    let fill_label_text = move || -> String {
        let pct: f32 = fill_pct_sig
            .get()
            .clamp(WATER_FILL_MIN_PCT, WATER_FILL_MAX_PCT);
        format!("Fill Level ({pct:.0}%)")
    };
    let fill_label_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        Style::default()
            .width(Length::Percent(100.0))
            .font_size(12.5)
            .font_weight(FontWeight::Medium)
            .color(live.get_palette().get_card_foreground())
    };
    let host_reset: GameEngineHost = state.get_water_host().clone();
    let scene_reset: GyroLiquidGameScene = scene.clone();
    let on_reset_params = move |_: &UiEvent| {
        scene_reset.set_sensor_mode(FluidSensorMode::VirtualTilt);
        let _: bool = fill_pct_sig.set_if_changed(FLUID_DEFAULT_FILL_RATIO * 100.0);
        let _: bool = visc_idx_sig.set_if_changed(0);
        let _: bool = buoyant_sig.set_if_changed(true);
        scene_reset.set_fill_ratio(FLUID_DEFAULT_FILL_RATIO);
        scene_reset.set_viscosity(WATER_VISC_SCALE_WATER);
        scene_reset.set_surface_tension(WATER_TENSION_WATER);
        scene_reset.set_buoyant_bodies_enabled(true);
        scene_reset.reset_water();
        step_and_refresh_water(&host_reset, &scene_reset, stats_sig);
    };
    view! {
        EuvCard {
            title: WATER_PHYSICS_CARD_TITLE.to_string()
            tokens: tokens
            subtitle: WATER_PHYSICS_CARD_SUB
            column {
                style: {
                    width: Length::Percent(100.0)
                    gap: SPACE_MD
                    overflow: Overflow::Hidden
                }
                column {
                    style: {
                        width: Length::Percent(100.0)
                        gap: SPACE_XS
                    }
                    text {
                        bind_style: fill_label_style
                        { fill_label_text }
                    }
                    { fill_slider }
                }
                EuvField {
                    label: WATER_FIELD_VISCOSITY.to_string()
                    control: visc_control
                    tokens: tokens
                }
                EuvSwitch {
                    checked: buoyant_sig
                    label: WATER_SWITCH_BUOYANT.to_string()
                    tokens: tokens
                }
                EuvActionRow {
                    EuvButton {
                        label: BTN_WATER_RESET.to_string()
                        tokens: tokens
                        outline()
                        sm()
                        on_click: on_reset_params
                    }
                }
            }
        }
    }
}

/// Mounts the Real-Time Physics Telemetry card displaying live gravity vector, roll tilt, particle & micro-bubble counts, kinetic energy, and frame timings.
///
/// # Arguments
///
/// - `Signal<GyroLiquidStats>` - Reactive telemetry signal.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted telemetry card handle.
fn mount_water_telemetry_card(stats_sig: Signal<GyroLiquidStats>, tokens: ThemeTokens) -> NodeId {
    let mono_primary_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        Style::default()
            .width(Length::Percent(100.0))
            .font_size(12.5)
            .font_family(FontFamily::Monospace)
            .font_weight(FontWeight::SemiBold)
            .color(live.get_palette().get_card_foreground())
    };
    let mono_muted_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        Style::default()
            .width(Length::Percent(100.0))
            .font_size(12.0)
            .font_family(FontFamily::Monospace)
            .color(live.get_palette().get_muted_foreground())
    };
    let gravity_text = move || -> String {
        let s: GyroLiquidStats = stats_sig.get();
        format!(
            "Gravity: ({:+.2}, {:+.2}, {:+.2}) m/s²",
            s.get_gravity_x(),
            s.get_gravity_y(),
            s.get_gravity_z()
        )
    };
    let tilt_text = move || -> String {
        let s: GyroLiquidStats = stats_sig.get();
        format!(
            "Tilt: {:+.1}° · Wave Peak: {:.1} mm",
            s.get_tilt_angle_deg(),
            s.get_peak_wave_height_m() * 1000.0
        )
    };
    let counts_text = move || -> String {
        let s: GyroLiquidStats = stats_sig.get();
        format!(
            "Particles: {} · Micro-Bubbles: {} · Bodies: {}",
            s.get_particle_count(),
            s.get_bubble_count(),
            s.get_buoyant_body_count()
        )
    };
    let perf_text = move || -> String {
        let s: GyroLiquidStats = stats_sig.get();
        format!(
            "Kinetic: {:.2} mJ · Sim: {:.2} ms · Render: {:.2} ms",
            s.get_kinetic_energy_mj(),
            s.get_sim_time_ms(),
            s.get_render_time_ms()
        )
    };
    view! {
        EuvCard {
            title: WATER_TELEMETRY_CARD_TITLE.to_string()
            tokens: tokens
            subtitle: WATER_TELEMETRY_CARD_SUB
            column {
                style: {
                    width: Length::Percent(100.0)
                    gap: SPACE_XS
                    overflow: Overflow::Hidden
                }
                text {
                    bind_style: mono_primary_style
                    { gravity_text }
                }
                text {
                    bind_style: mono_muted_style
                    { tilt_text }
                }
                text {
                    bind_style: mono_muted_style
                    { counts_text }
                }
                text {
                    bind_style: mono_muted_style
                    { perf_text }
                }
            }
        }
    }
}

/// Mounts a compact high-contrast translucent floating button pill for the edge-to-edge liquid fullscreen overlay.
///
/// # Arguments
///
/// - `&str` - Pill button label.
/// - `F` - Click handler closure.
///
/// # Returns
///
/// - `NodeId` - Mounted translucent floating control button handle.
fn mount_water_fs_pill_button<F>(label: &str, on_click: F) -> NodeId
where
    F: Fn(&UiEvent) + 'static,
{
    let text_str: String = label.to_string();
    let a11y_str: String = label.to_string();
    view! {
        row {
            style: {
                padding: Edges::symmetric(SPACE_XS, SPACE_MD)
                radius: WATER_FS_PILL_RADIUS
                background: Color::rgba(9, 14, 26, 226)
                border: (1.0, Color::rgba(255, 255, 255, 52))
                align: AlignItems::Center
                justify: JustifyContent::Center
                cursor: CursorIcon::Pointer
            }
            role: A11yRole::Button
            a11y_label: a11y_str
            on_click: on_click
            text {
                style: {
                    font_size: 12.5
                    font_weight: FontWeight::SemiBold
                    color: Color::hex(WATER_FS_TEXT_HEX)
                    text_overflow: TextOverflow::Clip
                }
                { text_str }
            }
        }
    }
}

/// Mounts the dedicated `Z_INDEX_FULLSCREEN` edge-to-edge liquid vessel portal with SafeArea insets, `EuvOverlayStack` Escape/Back dismissal, and translucent floating controls (`Rotate 90°`, `Shake`, `Reset`, `Exit Fullscreen`).
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `&GyroLiquidGameScene` - Active liquid physics scene handle.
/// - `NodeId` - Inline viewport node hidden while fullscreen is active.
///
/// # Returns
///
/// - `NodeId` - Mounted edge-to-edge fullscreen portal handle.
fn mount_water_fullscreen_portal(
    state: &ShowcaseState,
    scene: &GyroLiquidGameScene,
    inline_viewport: NodeId,
) -> NodeId {
    let open: Signal<bool> = state.get_water_fullscreen_open();
    let host: GameEngineHost = state.get_water_host().clone();
    let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
    let ctx: Context = current_context();
    bind_fullscreen_context(&ctx);
    let fs_viewport: NodeId = host.mount_viewport(
        Style::default()
            .position(Position::Absolute)
            .inset(Some(0.0), Some(0.0), Some(0.0), Some(0.0))
            .width(Length::Percent(100.0))
            .height(Length::Percent(100.0))
            .overflow(Overflow::Hidden)
            .stop_scroll_propagation(true)
            .stop_event_propagation(true),
    );
    let host_rot: GameEngineHost = host.clone();
    let scene_rot: GyroLiquidGameScene = scene.clone();
    let host_shake: GameEngineHost = host.clone();
    let scene_shake: GyroLiquidGameScene = scene.clone();
    let host_reset: GameEngineHost = host;
    let scene_reset: GyroLiquidGameScene = scene.clone();
    let on_fs_rot = move |_: &UiEvent| {
        scene_rot.set_sensor_mode(FluidSensorMode::VirtualTilt);
        scene_rot.rotate_container_by(WATER_ROT_90_RAD);
        step_and_refresh_water(&host_rot, &scene_rot, stats_sig);
    };
    let on_fs_shake = move |_: &UiEvent| {
        scene_shake.apply_shake_impulse(WATER_SHAKE_AX_MPS2, WATER_SHAKE_AY_MPS2);
        step_and_refresh_water(&host_shake, &scene_shake, stats_sig);
    };
    let on_fs_reset = move |_: &UiEvent| {
        scene_reset.set_sensor_mode(FluidSensorMode::VirtualTilt);
        scene_reset.reset_water();
        step_and_refresh_water(&host_reset, &scene_reset, stats_sig);
    };
    let on_fs_exit_top = move |_: &UiEvent| {
        let _: bool = open.set_if_changed(false);
    };
    let on_fs_exit_bottom = move |_: &UiEvent| {
        let _: bool = open.set_if_changed(false);
    };
    let fs_rot_btn: NodeId = mount_water_fs_pill_button(BTN_WATER_ROTATE_90, on_fs_rot);
    let fs_shake_btn: NodeId = mount_water_fs_pill_button(BTN_WATER_SHAKE, on_fs_shake);
    let fs_reset_btn: NodeId = mount_water_fs_pill_button(BTN_WATER_FS_RESET, on_fs_reset);
    let fs_exit_btn: NodeId = mount_water_fs_pill_button(BTN_WATER_EXIT_FS, on_fs_exit_bottom);
    let hud_telemetry = move || -> String {
        let s: GyroLiquidStats = stats_sig.get();
        format!("{} · {:+.1}°", WATER_FS_TITLE, s.get_tilt_angle_deg())
    };
    let paint_exit_icon = move |bounds: Rect, dl: &mut DisplayList| {
        draw_euv_icon(
            EuvIconName::Minimize,
            bounds,
            dl,
            Color::hex(WATER_FS_TEXT_HEX),
        );
    };
    let mut top_hud_id: NodeId = NodeId::default();
    let mut bottom_hud_id: NodeId = NodeId::default();
    let portal: NodeId = view! {
        portal {
            style: {
                Style::default().column()
                display: Display::None
                position: Position::Fixed
                inset: (Some(0.0), Some(0.0), Some(0.0), Some(0.0))
                width: Length::Percent(100.0)
                height: Length::Percent(100.0)
                padding: Edges::all(0.0)
                margin: Edges::all(0.0)
                background: Color::hex(WATER_FS_BG_HEX)
                border: (0.0, COLOR_TRANSPARENT)
                radius: 0.0
                overflow: Overflow::Hidden
                pointer_events: PointerEvents::None
                stop_scroll_propagation: true
                stop_event_propagation: true
                z_index: Z_INDEX_FULLSCREEN
            }
            { fs_viewport }
            row {
                node_ref: top_hud_id
                style: {
                    position: Position::Absolute
                    inset: (Some(0.0), Some(0.0), None, Some(0.0))
                    width: Length::Percent(100.0)
                    justify: JustifyContent::SpaceBetween
                    align: AlignItems::Center
                    padding: Edges::symmetric(SPACE_SM, SPACE_MD)
                    pointer_events: PointerEvents::None
                }
                row {
                    style: {
                        padding: Edges::symmetric(SPACE_XS, SPACE_MD)
                        radius: WATER_FS_PILL_RADIUS
                        background: Color::rgba(9, 14, 26, 224)
                        border: (1.0, Color::rgba(255, 255, 255, 48))
                        align: AlignItems::Center
                        pointer_events: PointerEvents::Auto
                    }
                    text {
                        style: {
                            font_size: 12.5
                            font_weight: FontWeight::SemiBold
                            color: Color::hex(WATER_FS_TEXT_HEX)
                            text_overflow: TextOverflow::Clip
                        }
                        { hud_telemetry }
                    }
                }
                row {
                    style: {
                        width: Length::Px(FS_EXIT_BTN_SIZE)
                        height: Length::Px(FS_EXIT_BTN_SIZE)
                        justify: JustifyContent::Center
                        align: AlignItems::Center
                        radius: WATER_FS_PILL_RADIUS
                        background: Color::rgba(9, 14, 26, 224)
                        border: (1.0, Color::rgba(255, 255, 255, 52))
                        cursor: CursorIcon::Pointer
                        pointer_events: PointerEvents::Auto
                    }
                    role: A11yRole::Button
                    a11y_label: BTN_WATER_EXIT_FS.to_string()
                    on_click: on_fs_exit_top
                    canvas {
                        caching: CanvasCaching::RetainedStatic
                        style: {
                            width: Length::Px(WATER_FS_EXIT_ICON_SIZE)
                            height: Length::Px(WATER_FS_EXIT_ICON_SIZE)
                        }
                        painter: paint_exit_icon
                    }
                }
            }
            row {
                node_ref: bottom_hud_id
                style: {
                    position: Position::Absolute
                    inset: (None, Some(0.0), Some(0.0), Some(0.0))
                    width: Length::Percent(100.0)
                    justify: JustifyContent::Center
                    align: AlignItems::Center
                    flex_wrap: FlexWrap::Wrap
                    gap: SPACE_SM
                    padding: Edges::symmetric(SPACE_SM, SPACE_MD)
                    pointer_events: PointerEvents::Auto
                }
                { fs_rot_btn }
                { fs_shake_btn }
                { fs_reset_btn }
                { fs_exit_btn }
            }
        }
    };
    let handle: SceneHandle = ctx.get_scene().clone();
    let safe_sig: Signal<SafeAreaInsets> = ctx.get_safe_area();
    let prev_fs: Rc<Cell<bool>> = Rc::new(Cell::new(false));
    let fs_acquired: Rc<Cell<bool>> = Rc::new(Cell::new(false));
    let fs_cleanup: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
    let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
        on_cleanup(move || {
            if fs_cleanup.replace(false) {
                exit_fullscreen();
            }
        });
        let _: Effect =
            EuvOverlayStack::bind_signal(open, WATER_FS_OVERLAY_NAME, Z_INDEX_FULLSCREEN);
        Effect::new(move || {
            let is_open: bool = open.get();
            let safe: SafeAreaInsets = safe_sig.get();
            if is_open != prev_fs.replace(is_open) {
                if is_open {
                    if !fs_acquired.replace(true) {
                        enter_fullscreen();
                    }
                } else if fs_acquired.replace(false) {
                    exit_fullscreen();
                }
            }
            handle.with_write(
                |tree: &mut SceneTree| {
                    tree.cancel_subtree_transitions(portal);
                    if let Some(n) = tree.get_node_mut(inline_viewport) {
                        let mut st: Style = n.get_style();
                        st.get_mut_layout().set_display(if is_open {
                            Display::None
                        } else {
                            Display::Flex
                        });
                        n.set_style(st);
                        tree.mark_dirty(inline_viewport, DIRTY_LAYOUT | DIRTY_PAINT);
                    }
                    if let Some(n) = tree.get_node_mut(portal) {
                        let mut st: Style = n.get_style();
                        st.get_mut_layout().set_display(if is_open {
                            Display::Flex
                        } else {
                            Display::None
                        });
                        st.get_mut_paint()
                            .set_pointer_events(if is_open {
                                PointerEvents::Auto
                            } else {
                                PointerEvents::None
                            })
                            .set_opacity(1.0)
                            .set_transform(Transform2D::default());
                        n.set_style(st);
                    }
                    if let Some(n) = tree.get_node_mut(top_hud_id) {
                        let mut st: Style = n.get_style();
                        st.get_mut_layout().set_padding(Edges::new(
                            SPACE_SM + safe.get_top(),
                            SPACE_MD + safe.get_right(),
                            SPACE_SM,
                            SPACE_MD + safe.get_left(),
                        ));
                        n.set_style(st);
                        tree.mark_dirty(top_hud_id, DIRTY_LAYOUT | DIRTY_PAINT);
                    }
                    if let Some(n) = tree.get_node_mut(bottom_hud_id) {
                        let mut st: Style = n.get_style();
                        st.get_mut_layout().set_padding(Edges::new(
                            SPACE_SM,
                            SPACE_MD + safe.get_right(),
                            SPACE_SM + safe.get_bottom(),
                            SPACE_MD + safe.get_left(),
                        ));
                        n.set_style(st);
                        tree.mark_dirty(bottom_hud_id, DIRTY_LAYOUT | DIRTY_PAINT);
                    }
                    let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
                    tree.mark_dirty(portal, dirty_l | DIRTY_PAINT);
                },
                (),
            );
        })
    });
    ctx.get_scene().with_write(
        |tree: &mut SceneTree| {
            tree.attach_scope(portal, scope);
        },
        (),
    );
    portal
}