1use super::*;
2
3pub fn mount_water_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
14 let host: GameEngineHost = state.get_water_host().clone();
15 let scene: GyroLiquidGameScene = state.get_or_init_water_scene();
16 let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
17 let motion_sig: Signal<DeviceMotionSample> = use_device_motion();
18 scene.bind_device_motion(motion_sig);
19 let _: bool = stats_sig.set_if_changed(scene.stats());
20 let viewport: NodeId = host.mount_viewport(
21 Style::default()
22 .width(Length::Percent(100.0))
23 .height(Length::Percent(100.0)),
24 );
25 let vp_sig: Signal<Size> = use_viewport_size();
26 let vp_frame_style = move || -> Style {
27 let live: ThemeTokens = use_live_tokens(tokens);
28 let h: f32 = adaptive_viewport_height(vp_sig.get().get_height());
29 Style::default()
30 .column()
31 .width(Length::Percent(100.0))
32 .height(Length::Px(h))
33 .overflow(Overflow::Hidden)
34 .border(
35 live.get_geometry().get_border_width(),
36 live.get_palette().get_border(),
37 )
38 .radius(live.get_geometry().get_radius_md())
39 };
40 let viewport_frame: NodeId = view! {
41 column {
42 bind_style: vp_frame_style
43 { viewport }
44 }
45 };
46 let fs_portal: NodeId = mount_water_fullscreen_portal(state, &scene, viewport, tokens);
47 let main_card: NodeId = mount_water_viewport_card(state, viewport_frame, &scene, tokens);
48 let sensor_card: NodeId = mount_water_sensor_card(state, &scene, tokens);
49 let motion_card: NodeId = mount_water_motion_card(state, &scene, tokens);
50 let physics_card: NodeId = mount_water_physics_card(state, &scene, tokens);
51 let telemetry_card: NodeId = mount_water_telemetry_card(stats_sig, tokens);
52 let rail: NodeId = view! {
53 column {
54 style: {
55 width: Length::Percent(100.0)
56 gap: SPACE_MD
57 }
58 { sensor_card }
59 { motion_card }
60 { physics_card }
61 { telemetry_card }
62 }
63 };
64 let studio: NodeId = mount_studio_layout(main_card, rail);
65 let ctx: Context = current_context();
66 let sync_scope: Scope = create_water_sync_scope(state, &scene, motion_sig);
67 let page: NodeId = view! {
68 EuvPage {
69 title: WATER_TITLE.to_string()
70 subtitle: WATER_SUBTITLE.to_string()
71 tokens: tokens
72 { studio }
73 { fs_portal }
74 }
75 };
76 ctx.get_scene().with_write(
77 |tree: &mut SceneTree| {
78 tree.attach_scope(page, sync_scope);
79 },
80 (),
81 );
82 page
83}
84
85fn create_water_sync_scope(
97 state: &ShowcaseState,
98 scene: &GyroLiquidGameScene,
99 motion_sig: Signal<DeviceMotionSample>,
100) -> Scope {
101 let host: GameEngineHost = state.get_water_host().clone();
102 let fill_pct_sig: Signal<f32> = state.get_water_fill_pct();
103 let visc_idx_sig: Signal<usize> = state.get_water_viscosity_idx();
104 let buoyant_sig: Signal<bool> = state.get_water_buoyant_enabled();
105 let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
106 let scene_motion: GyroLiquidGameScene = scene.clone();
107 let host_motion: GameEngineHost = host.clone();
108 let scene_fill: GyroLiquidGameScene = scene.clone();
109 let host_fill: GameEngineHost = host.clone();
110 let scene_visc: GyroLiquidGameScene = scene.clone();
111 let host_visc: GameEngineHost = host.clone();
112 let scene_buoy: GyroLiquidGameScene = scene.clone();
113 let host_buoy: GameEngineHost = host;
114 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
115 let _: Effect = Effect::new(move || {
116 let sample: DeviceMotionSample = motion_sig.get();
117 if sample.get_sensor_active() {
118 scene_motion.set_sensor_mode(FluidSensorMode::Auto);
119 scene_motion.set_device_motion(None);
120 let _: u32 = host_motion.step(WATER_STEP_DT);
121 let _: bool = stats_sig.set_if_changed(scene_motion.stats());
122 }
123 });
124 let _: Effect = Effect::new(move || {
125 let pct: f32 = fill_pct_sig
126 .get()
127 .clamp(WATER_FILL_MIN_PCT, WATER_FILL_MAX_PCT);
128 let target_ratio: f32 = (pct / 100.0).clamp(FLUID_MIN_FILL_RATIO, FLUID_MAX_FILL_RATIO);
129 if (scene_fill.stats().get_fill_ratio() - target_ratio).abs() > 0.005 {
130 scene_fill.set_fill_ratio(target_ratio);
131 let _: u32 = host_fill.step(WATER_STEP_DT);
132 let _: bool = stats_sig.set_if_changed(scene_fill.stats());
133 }
134 });
135 let _: Effect = Effect::new(move || {
136 let (visc, tension): (f32, f32) = match visc_idx_sig.get() {
137 1 => (WATER_VISC_SCALE_OIL, WATER_TENSION_OIL),
138 2 => (WATER_VISC_SCALE_HONEY, WATER_TENSION_HONEY),
139 _ => (WATER_VISC_SCALE_WATER, WATER_TENSION_WATER),
140 };
141 scene_visc.set_viscosity(visc);
142 scene_visc.set_surface_tension(tension);
143 let _: u32 = host_visc.step(WATER_STEP_DT);
144 let _: bool = stats_sig.set_if_changed(scene_visc.stats());
145 });
146 Effect::new(move || {
147 let enabled: bool = buoyant_sig.get();
148 let cur_enabled: bool = scene_buoy.stats().get_buoyant_body_count() > 0;
149 if cur_enabled != enabled {
150 scene_buoy.set_buoyant_bodies_enabled(enabled);
151 let _: u32 = host_buoy.step(WATER_STEP_DT);
152 let _: bool = stats_sig.set_if_changed(scene_buoy.stats());
153 }
154 })
155 });
156 scope
157}
158
159fn step_and_refresh_water(
167 host: &GameEngineHost,
168 scene: &GyroLiquidGameScene,
169 stats_sig: Signal<GyroLiquidStats>,
170) {
171 let _: u32 = host.step(WATER_STEP_DT);
172 let _: bool = stats_sig.set_if_changed(scene.stats());
173}
174
175fn mount_water_viewport_card(
188 state: &ShowcaseState,
189 viewport_frame: NodeId,
190 scene: &GyroLiquidGameScene,
191 tokens: ThemeTokens,
192) -> NodeId {
193 let host_rot: GameEngineHost = state.get_water_host().clone();
194 let scene_rot: GyroLiquidGameScene = scene.clone();
195 let host_shake: GameEngineHost = state.get_water_host().clone();
196 let scene_shake: GyroLiquidGameScene = scene.clone();
197 let fs_open_sig: Signal<bool> = state.get_water_fullscreen_open();
198 let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
199 let on_open_fs = move |_: &UiEvent| {
200 let _: bool = fs_open_sig.set_if_changed(true);
201 };
202 let on_rotate_90 = move |_: &UiEvent| {
203 scene_rot.set_sensor_mode(FluidSensorMode::VirtualTilt);
204 scene_rot.rotate_container_by(WATER_ROT_90_RAD);
205 step_and_refresh_water(&host_rot, &scene_rot, stats_sig);
206 };
207 let on_shake = move |_: &UiEvent| {
208 scene_shake.apply_shake_impulse(WATER_SHAKE_AX_MPS2, WATER_SHAKE_AY_MPS2);
209 step_and_refresh_water(&host_shake, &scene_shake, stats_sig);
210 };
211 let hint_style = move || -> Style {
212 let live: ThemeTokens = use_live_tokens(tokens);
213 Style::default()
214 .width(Length::Percent(100.0))
215 .font_size(12.0)
216 .font_family(FontFamily::Monospace)
217 .color(live.get_palette().get_muted_foreground())
218 };
219 view! {
220 EuvCard {
221 title: WATER_VESSEL_TITLE.to_string()
222 tokens: tokens
223 subtitle: WATER_VESSEL_SUB
224 column {
225 style: {
226 width: Length::Percent(100.0)
227 gap: SPACE_MD
228 overflow: Overflow::Hidden
229 }
230 { viewport_frame }
231 EuvActionRow {
232 EuvButton {
233 label: BTN_WATER_FULLSCREEN.to_string()
234 tokens: tokens
235 sm()
236 on_click: on_open_fs
237 }
238 EuvButton {
239 label: BTN_WATER_ROTATE_90.to_string()
240 tokens: tokens
241 outline()
242 sm()
243 on_click: on_rotate_90
244 }
245 EuvButton {
246 label: BTN_WATER_SHAKE.to_string()
247 tokens: tokens
248 outline()
249 sm()
250 on_click: on_shake
251 }
252 }
253 text {
254 bind_style: hint_style
255 { WATER_CONTROLS_HINT }
256 }
257 }
258 }
259 }
260}
261
262fn mount_water_sensor_card(
274 state: &ShowcaseState,
275 scene: &GyroLiquidGameScene,
276 tokens: ThemeTokens,
277) -> NodeId {
278 let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
279 let perm_status_sig: Signal<String> = state.get_water_sensor_perm_status();
280 let scene_perm: GyroLiquidGameScene = scene.clone();
281 let on_request_perm = move |_: &UiEvent| {
282 scene_perm.set_sensor_mode(FluidSensorMode::Auto);
283 scene_perm.set_device_motion(None);
284 #[cfg(target_arch = "wasm32")]
285 {
286 let granted: bool = request_web_motion_permission();
287 let msg: &str = if granted {
288 WATER_PERM_WEB_GRANTED
289 } else {
290 WATER_PERM_WEB_UNAVAILABLE
291 };
292 let _: bool = perm_status_sig.set_if_changed(msg.to_string());
293 }
294 #[cfg(not(target_arch = "wasm32"))]
295 {
296 let _: bool = perm_status_sig.set_if_changed(WATER_PERM_DESKTOP_STATUS.to_string());
297 }
298 let _: bool = stats_sig.set_if_changed(scene_perm.stats());
299 };
300 let badge_box_style = move || -> Style {
301 let live: ThemeTokens = use_live_tokens(tokens);
302 let live_p: ThemePalette = live.get_palette();
303 let active: bool = stats_sig.get().get_sensor_active();
304 let bg: Color = if active {
305 live_p.get_primary()
306 } else {
307 live_p.get_secondary()
308 };
309 Style::default()
310 .row()
311 .padding(Edges::symmetric(SPACE_XS, SPACE_SM))
312 .radius(WATER_FS_PILL_RADIUS)
313 .background(bg)
314 .align(AlignItems::Center)
315 };
316 let badge_text_style = move || -> Style {
317 let live: ThemeTokens = use_live_tokens(tokens);
318 let live_p: ThemePalette = live.get_palette();
319 let active: bool = stats_sig.get().get_sensor_active();
320 let fg: Color = if active {
321 live_p.get_primary_foreground()
322 } else {
323 live_p.get_secondary_foreground()
324 };
325 Style::default()
326 .font_size(12.0)
327 .font_weight(FontWeight::SemiBold)
328 .color(fg)
329 };
330 let badge_label = move || -> String {
331 if stats_sig.get().get_sensor_active() {
332 WATER_STATUS_HARDWARE_IMU.to_string()
333 } else {
334 WATER_STATUS_VIRTUAL_TILT.to_string()
335 }
336 };
337 let status_style = move || -> Style {
338 let live: ThemeTokens = use_live_tokens(tokens);
339 Style::default()
340 .width(Length::Percent(100.0))
341 .font_size(12.0)
342 .color(live.get_palette().get_muted_foreground())
343 };
344 let status_text = move || -> String { perm_status_sig.get() };
345 view! {
346 EuvCard {
347 title: WATER_SENSOR_CARD_TITLE.to_string()
348 tokens: tokens
349 subtitle: WATER_SENSOR_CARD_SUB
350 column {
351 style: {
352 width: Length::Percent(100.0)
353 gap: SPACE_SM
354 overflow: Overflow::Hidden
355 }
356 row {
357 style: {
358 width: Length::Percent(100.0)
359 flex_wrap: FlexWrap::Wrap
360 align: AlignItems::Center
361 gap: SPACE_SM
362 }
363 row {
364 bind_style: badge_box_style
365 text {
366 bind_style: badge_text_style
367 { badge_label }
368 }
369 }
370 EuvButton {
371 label: BTN_WATER_ENABLE_SENSOR.to_string()
372 tokens: tokens
373 outline()
374 sm()
375 on_click: on_request_perm
376 }
377 }
378 text {
379 bind_style: status_style
380 { status_text }
381 }
382 }
383 }
384 }
385}
386
387fn mount_water_motion_card(
399 state: &ShowcaseState,
400 scene: &GyroLiquidGameScene,
401 tokens: ThemeTokens,
402) -> NodeId {
403 let host: GameEngineHost = state.get_water_host().clone();
404 let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
405 let host_left: GameEngineHost = host.clone();
406 let scene_left: GyroLiquidGameScene = scene.clone();
407 let host_lvl: GameEngineHost = host.clone();
408 let scene_lvl: GyroLiquidGameScene = scene.clone();
409 let host_right: GameEngineHost = host.clone();
410 let scene_right: GyroLiquidGameScene = scene.clone();
411 let host_cw: GameEngineHost = host.clone();
412 let scene_cw: GyroLiquidGameScene = scene.clone();
413 let host_ccw: GameEngineHost = host.clone();
414 let scene_ccw: GyroLiquidGameScene = scene.clone();
415 let host_flip: GameEngineHost = host.clone();
416 let scene_flip: GyroLiquidGameScene = scene.clone();
417 let host_shake: GameEngineHost = host;
418 let scene_shake: GyroLiquidGameScene = scene.clone();
419 let on_tilt_left = move |_: &UiEvent| {
420 scene_left.set_sensor_mode(FluidSensorMode::VirtualTilt);
421 scene_left.set_virtual_tilt(-WATER_TILT_30_RAD, 0.0);
422 step_and_refresh_water(&host_left, &scene_left, stats_sig);
423 };
424 let on_level = move |_: &UiEvent| {
425 scene_lvl.set_sensor_mode(FluidSensorMode::VirtualTilt);
426 scene_lvl.set_virtual_tilt(0.0, 0.0);
427 step_and_refresh_water(&host_lvl, &scene_lvl, stats_sig);
428 };
429 let on_tilt_right = move |_: &UiEvent| {
430 scene_right.set_sensor_mode(FluidSensorMode::VirtualTilt);
431 scene_right.set_virtual_tilt(WATER_TILT_30_RAD, 0.0);
432 step_and_refresh_water(&host_right, &scene_right, stats_sig);
433 };
434 let on_rot_cw = move |_: &UiEvent| {
435 scene_cw.set_sensor_mode(FluidSensorMode::VirtualTilt);
436 scene_cw.rotate_container_by(WATER_ROT_90_RAD);
437 step_and_refresh_water(&host_cw, &scene_cw, stats_sig);
438 };
439 let on_rot_ccw = move |_: &UiEvent| {
440 scene_ccw.set_sensor_mode(FluidSensorMode::VirtualTilt);
441 scene_ccw.rotate_container_by(-WATER_ROT_90_RAD);
442 step_and_refresh_water(&host_ccw, &scene_ccw, stats_sig);
443 };
444 let on_flip_180 = move |_: &UiEvent| {
445 scene_flip.set_sensor_mode(FluidSensorMode::VirtualTilt);
446 scene_flip.rotate_container_by(PI);
447 step_and_refresh_water(&host_flip, &scene_flip, stats_sig);
448 };
449 let on_shake = move |_: &UiEvent| {
450 scene_shake.apply_shake_impulse(WATER_SHAKE_AX_MPS2, WATER_SHAKE_AY_MPS2);
451 step_and_refresh_water(&host_shake, &scene_shake, stats_sig);
452 };
453 let key_hint_style = move || -> Style {
454 let live: ThemeTokens = use_live_tokens(tokens);
455 Style::default()
456 .width(Length::Percent(100.0))
457 .font_size(12.0)
458 .font_family(FontFamily::Monospace)
459 .color(live.get_palette().get_muted_foreground())
460 };
461 view! {
462 EuvCard {
463 title: WATER_MOTION_CARD_TITLE.to_string()
464 tokens: tokens
465 subtitle: WATER_MOTION_CARD_SUB
466 column {
467 style: {
468 width: Length::Percent(100.0)
469 gap: SPACE_SM
470 overflow: Overflow::Hidden
471 }
472 EuvActionRow {
473 EuvButton {
474 label: BTN_WATER_TILT_LEFT.to_string()
475 tokens: tokens
476 outline()
477 sm()
478 on_click: on_tilt_left
479 }
480 EuvButton {
481 label: BTN_WATER_LEVEL.to_string()
482 tokens: tokens
483 outline()
484 sm()
485 on_click: on_level
486 }
487 EuvButton {
488 label: BTN_WATER_TILT_RIGHT.to_string()
489 tokens: tokens
490 outline()
491 sm()
492 on_click: on_tilt_right
493 }
494 }
495 EuvActionRow {
496 EuvButton {
497 label: BTN_WATER_ROT_CW.to_string()
498 tokens: tokens
499 outline()
500 sm()
501 on_click: on_rot_cw
502 }
503 EuvButton {
504 label: BTN_WATER_ROT_CCW.to_string()
505 tokens: tokens
506 outline()
507 sm()
508 on_click: on_rot_ccw
509 }
510 EuvButton {
511 label: BTN_WATER_FLIP_180.to_string()
512 tokens: tokens
513 outline()
514 sm()
515 on_click: on_flip_180
516 }
517 EuvButton {
518 label: BTN_WATER_SHAKE_IMPULSE.to_string()
519 tokens: tokens
520 sm()
521 on_click: on_shake
522 }
523 }
524 text {
525 bind_style: key_hint_style
526 { WATER_KEYBOARD_HINT }
527 }
528 }
529 }
530 }
531}
532
533fn mount_water_physics_card(
545 state: &ShowcaseState,
546 scene: &GyroLiquidGameScene,
547 tokens: ThemeTokens,
548) -> NodeId {
549 let fill_pct_sig: Signal<f32> = state.get_water_fill_pct();
550 let visc_idx_sig: Signal<usize> = state.get_water_viscosity_idx();
551 let buoyant_sig: Signal<bool> = state.get_water_buoyant_enabled();
552 let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
553 let fill_slider: NodeId = view! {
554 EuvSlider {
555 value: fill_pct_sig
556 min: WATER_FILL_MIN_PCT
557 max: WATER_FILL_MAX_PCT
558 tokens: tokens
559 }
560 };
561 let visc_options: Vec<String> = vec![
562 WATER_VISC_PURE_WATER.to_string(),
563 WATER_VISC_LIGHT_OIL.to_string(),
564 WATER_VISC_HONEY.to_string(),
565 ];
566 let visc_control: NodeId = view! {
567 EuvSegmented {
568 options: visc_options
569 selected: visc_idx_sig
570 tokens: tokens
571 }
572 };
573 let fill_label_text = move || -> String {
574 let pct: f32 = fill_pct_sig
575 .get()
576 .clamp(WATER_FILL_MIN_PCT, WATER_FILL_MAX_PCT);
577 format!("Fill Level ({pct:.0}%)")
578 };
579 let fill_label_style = move || -> Style {
580 let live: ThemeTokens = use_live_tokens(tokens);
581 Style::default()
582 .width(Length::Percent(100.0))
583 .font_size(12.5)
584 .font_weight(FontWeight::Medium)
585 .color(live.get_palette().get_card_foreground())
586 };
587 let host_reset: GameEngineHost = state.get_water_host().clone();
588 let scene_reset: GyroLiquidGameScene = scene.clone();
589 let on_reset_params = move |_: &UiEvent| {
590 scene_reset.set_sensor_mode(FluidSensorMode::VirtualTilt);
591 let _: bool = fill_pct_sig.set_if_changed(FLUID_DEFAULT_FILL_RATIO * 100.0);
592 let _: bool = visc_idx_sig.set_if_changed(0);
593 let _: bool = buoyant_sig.set_if_changed(true);
594 scene_reset.set_fill_ratio(FLUID_DEFAULT_FILL_RATIO);
595 scene_reset.set_viscosity(WATER_VISC_SCALE_WATER);
596 scene_reset.set_surface_tension(WATER_TENSION_WATER);
597 scene_reset.set_buoyant_bodies_enabled(true);
598 scene_reset.reset_water();
599 step_and_refresh_water(&host_reset, &scene_reset, stats_sig);
600 };
601 view! {
602 EuvCard {
603 title: WATER_PHYSICS_CARD_TITLE.to_string()
604 tokens: tokens
605 subtitle: WATER_PHYSICS_CARD_SUB
606 column {
607 style: {
608 width: Length::Percent(100.0)
609 gap: SPACE_MD
610 overflow: Overflow::Hidden
611 }
612 column {
613 style: {
614 width: Length::Percent(100.0)
615 gap: SPACE_XS
616 }
617 text {
618 bind_style: fill_label_style
619 { fill_label_text }
620 }
621 { fill_slider }
622 }
623 EuvField {
624 label: WATER_FIELD_VISCOSITY.to_string()
625 control: visc_control
626 tokens: tokens
627 }
628 EuvSwitch {
629 checked: buoyant_sig
630 label: WATER_SWITCH_BUOYANT.to_string()
631 tokens: tokens
632 }
633 EuvActionRow {
634 EuvButton {
635 label: BTN_WATER_RESET.to_string()
636 tokens: tokens
637 outline()
638 sm()
639 on_click: on_reset_params
640 }
641 }
642 }
643 }
644 }
645}
646
647fn mount_water_telemetry_card(stats_sig: Signal<GyroLiquidStats>, tokens: ThemeTokens) -> NodeId {
658 let mono_primary_style = move || -> Style {
659 let live: ThemeTokens = use_live_tokens(tokens);
660 Style::default()
661 .width(Length::Percent(100.0))
662 .font_size(12.5)
663 .font_family(FontFamily::Monospace)
664 .font_weight(FontWeight::SemiBold)
665 .color(live.get_palette().get_card_foreground())
666 };
667 let mono_muted_style = move || -> Style {
668 let live: ThemeTokens = use_live_tokens(tokens);
669 Style::default()
670 .width(Length::Percent(100.0))
671 .font_size(12.0)
672 .font_family(FontFamily::Monospace)
673 .color(live.get_palette().get_muted_foreground())
674 };
675 let gravity_text = move || -> String {
676 let s: GyroLiquidStats = stats_sig.get();
677 format!(
678 "Gravity: ({:+.2}, {:+.2}, {:+.2}) m/s²",
679 s.get_gravity_x(),
680 s.get_gravity_y(),
681 s.get_gravity_z()
682 )
683 };
684 let tilt_text = move || -> String {
685 let s: GyroLiquidStats = stats_sig.get();
686 format!(
687 "Tilt: {:+.1}° · Wave Peak: {:.1} mm",
688 s.get_tilt_angle_deg(),
689 s.get_peak_wave_height_m() * 1000.0
690 )
691 };
692 let counts_text = move || -> String {
693 let s: GyroLiquidStats = stats_sig.get();
694 format!(
695 "Particles: {} · Micro-Bubbles: {} · Bodies: {}",
696 s.get_particle_count(),
697 s.get_bubble_count(),
698 s.get_buoyant_body_count()
699 )
700 };
701 let perf_text = move || -> String {
702 let s: GyroLiquidStats = stats_sig.get();
703 format!(
704 "Kinetic: {:.2} mJ · Sim: {:.2} ms · Render: {:.2} ms",
705 s.get_kinetic_energy_mj(),
706 s.get_sim_time_ms(),
707 s.get_render_time_ms()
708 )
709 };
710 view! {
711 EuvCard {
712 title: WATER_TELEMETRY_CARD_TITLE.to_string()
713 tokens: tokens
714 subtitle: WATER_TELEMETRY_CARD_SUB
715 column {
716 style: {
717 width: Length::Percent(100.0)
718 gap: SPACE_XS
719 overflow: Overflow::Hidden
720 }
721 text {
722 bind_style: mono_primary_style
723 { gravity_text }
724 }
725 text {
726 bind_style: mono_muted_style
727 { tilt_text }
728 }
729 text {
730 bind_style: mono_muted_style
731 { counts_text }
732 }
733 text {
734 bind_style: mono_muted_style
735 { perf_text }
736 }
737 }
738 }
739 }
740}
741
742fn mount_water_fs_pill_button<F>(label: &str, tokens: ThemeTokens, on_click: F) -> NodeId
754where
755 F: Fn(&UiEvent) + 'static,
756{
757 let text_str: String = label.to_string();
758 let a11y_str: String = label.to_string();
759 let pill_style = move || -> Style {
760 let dark_tok: ThemeTokens =
761 ThemeTokens::resolve(use_live_tokens(tokens).get_scheme(), ThemeMode::Dark);
762 let dark_p: ThemePalette = dark_tok.get_palette();
763 let dark_g: ThemeGeometry = dark_tok.get_geometry();
764 Style::default()
765 .row()
766 .padding(Edges::symmetric(SPACE_XS, SPACE_MD))
767 .radius(WATER_FS_PILL_RADIUS)
768 .background(dark_p.get_card().with_alpha(232))
769 .border(dark_g.get_border_width(), dark_p.get_border())
770 .align(AlignItems::Center)
771 .justify(JustifyContent::Center)
772 .cursor(CursorIcon::Pointer)
773 };
774 let text_style = move || -> Style {
775 let dark_tok: ThemeTokens =
776 ThemeTokens::resolve(use_live_tokens(tokens).get_scheme(), ThemeMode::Dark);
777 Style::default()
778 .font_size(12.5)
779 .font_weight(FontWeight::SemiBold)
780 .color(dark_tok.get_palette().get_foreground())
781 .text_overflow(TextOverflow::Clip)
782 };
783 view! {
784 row {
785 bind_style: pill_style
786 role: A11yRole::Button
787 a11y_label: a11y_str
788 on_click: on_click
789 text {
790 bind_style: text_style
791 { text_str }
792 }
793 }
794 }
795}
796
797fn mount_water_fullscreen_portal(
810 state: &ShowcaseState,
811 scene: &GyroLiquidGameScene,
812 inline_viewport: NodeId,
813 tokens: ThemeTokens,
814) -> NodeId {
815 let open: Signal<bool> = state.get_water_fullscreen_open();
816 let host: GameEngineHost = state.get_water_host().clone();
817 let stats_sig: Signal<GyroLiquidStats> = state.get_water_stats();
818 let ctx: Context = current_context();
819 bind_fullscreen_context(&ctx);
820 let fs_viewport: NodeId = host.mount_viewport(
821 Style::default()
822 .position(Position::Absolute)
823 .inset(Some(0.0), Some(0.0), Some(0.0), Some(0.0))
824 .width(Length::Percent(100.0))
825 .height(Length::Percent(100.0))
826 .overflow(Overflow::Hidden)
827 .stop_scroll_propagation(true)
828 .stop_event_propagation(true),
829 );
830 let host_rot: GameEngineHost = host.clone();
831 let scene_rot: GyroLiquidGameScene = scene.clone();
832 let host_shake: GameEngineHost = host.clone();
833 let scene_shake: GyroLiquidGameScene = scene.clone();
834 let host_reset: GameEngineHost = host;
835 let scene_reset: GyroLiquidGameScene = scene.clone();
836 let on_fs_rot = move |_: &UiEvent| {
837 scene_rot.set_sensor_mode(FluidSensorMode::VirtualTilt);
838 scene_rot.rotate_container_by(WATER_ROT_90_RAD);
839 step_and_refresh_water(&host_rot, &scene_rot, stats_sig);
840 };
841 let on_fs_shake = move |_: &UiEvent| {
842 scene_shake.apply_shake_impulse(WATER_SHAKE_AX_MPS2, WATER_SHAKE_AY_MPS2);
843 step_and_refresh_water(&host_shake, &scene_shake, stats_sig);
844 };
845 let on_fs_reset = move |_: &UiEvent| {
846 scene_reset.set_sensor_mode(FluidSensorMode::VirtualTilt);
847 scene_reset.reset_water();
848 step_and_refresh_water(&host_reset, &scene_reset, stats_sig);
849 };
850 let on_fs_exit_top = move |_: &UiEvent| {
851 let _: bool = open.set_if_changed(false);
852 };
853 let on_fs_exit_bottom = move |_: &UiEvent| {
854 let _: bool = open.set_if_changed(false);
855 };
856 let fs_rot_btn: NodeId = mount_water_fs_pill_button(BTN_WATER_ROTATE_90, tokens, on_fs_rot);
857 let fs_shake_btn: NodeId = mount_water_fs_pill_button(BTN_WATER_SHAKE, tokens, on_fs_shake);
858 let fs_reset_btn: NodeId = mount_water_fs_pill_button(BTN_WATER_FS_RESET, tokens, on_fs_reset);
859 let fs_exit_btn: NodeId =
860 mount_water_fs_pill_button(BTN_WATER_EXIT_FS, tokens, on_fs_exit_bottom);
861 let hud_telemetry = move || -> String {
862 let s: GyroLiquidStats = stats_sig.get();
863 format!("{} · {:+.1}°", WATER_FS_TITLE, s.get_tilt_angle_deg())
864 };
865 let hud_chip_style = move || -> Style {
866 let dark_tok: ThemeTokens =
867 ThemeTokens::resolve(use_live_tokens(tokens).get_scheme(), ThemeMode::Dark);
868 let dark_p: ThemePalette = dark_tok.get_palette();
869 let dark_g: ThemeGeometry = dark_tok.get_geometry();
870 Style::default()
871 .row()
872 .padding(Edges::symmetric(SPACE_XS, SPACE_MD))
873 .radius(WATER_FS_PILL_RADIUS)
874 .background(dark_p.get_card().with_alpha(232))
875 .border(dark_g.get_border_width(), dark_p.get_border())
876 .align(AlignItems::Center)
877 .pointer_events(PointerEvents::Auto)
878 };
879 let hud_chip_text_style = move || -> Style {
880 let dark_tok: ThemeTokens =
881 ThemeTokens::resolve(use_live_tokens(tokens).get_scheme(), ThemeMode::Dark);
882 Style::default()
883 .font_size(12.5)
884 .font_weight(FontWeight::SemiBold)
885 .color(dark_tok.get_palette().get_foreground())
886 .text_overflow(TextOverflow::Clip)
887 };
888 let hud_exit_icon_btn_style = move || -> Style {
889 let dark_tok: ThemeTokens =
890 ThemeTokens::resolve(use_live_tokens(tokens).get_scheme(), ThemeMode::Dark);
891 let dark_p: ThemePalette = dark_tok.get_palette();
892 let dark_g: ThemeGeometry = dark_tok.get_geometry();
893 Style::default()
894 .row()
895 .width(Length::Px(FS_EXIT_BTN_SIZE))
896 .height(Length::Px(FS_EXIT_BTN_SIZE))
897 .justify(JustifyContent::Center)
898 .align(AlignItems::Center)
899 .radius(WATER_FS_PILL_RADIUS)
900 .background(dark_p.get_card().with_alpha(232))
901 .border(dark_g.get_border_width(), dark_p.get_border())
902 .cursor(CursorIcon::Pointer)
903 .pointer_events(PointerEvents::Auto)
904 };
905 let paint_exit_icon = move |bounds: Rect, dl: &mut DisplayList| {
906 let dark_tok: ThemeTokens =
907 ThemeTokens::resolve(live_tokens_untracked(tokens).get_scheme(), ThemeMode::Dark);
908 draw_euv_icon(
909 EuvIconName::Minimize,
910 bounds,
911 dl,
912 dark_tok.get_palette().get_foreground(),
913 );
914 };
915 let mut top_hud_id: NodeId = NodeId::default();
916 let mut bottom_hud_id: NodeId = NodeId::default();
917 let portal: NodeId = view! {
918 portal {
919 style: {
920 Style::default().column()
921 display: Display::None
922 position: Position::Fixed
923 inset: (Some(0.0), Some(0.0), Some(0.0), Some(0.0))
924 width: Length::Percent(100.0)
925 height: Length::Percent(100.0)
926 padding: Edges::all(0.0)
927 margin: Edges::all(0.0)
928 background: Color::hex(WATER_FS_BG_HEX)
929 border: (0.0, COLOR_TRANSPARENT)
930 radius: 0.0
931 overflow: Overflow::Hidden
932 pointer_events: PointerEvents::None
933 stop_scroll_propagation: true
934 stop_event_propagation: true
935 z_index: Z_INDEX_FULLSCREEN
936 }
937 { fs_viewport }
938 row {
939 node_ref: top_hud_id
940 style: {
941 position: Position::Absolute
942 inset: (Some(0.0), Some(0.0), None, Some(0.0))
943 width: Length::Percent(100.0)
944 justify: JustifyContent::SpaceBetween
945 align: AlignItems::Center
946 padding: Edges::symmetric(SPACE_SM, SPACE_MD)
947 pointer_events: PointerEvents::None
948 }
949 row {
950 bind_style: hud_chip_style
951 text {
952 bind_style: hud_chip_text_style
953 { hud_telemetry }
954 }
955 }
956 row {
957 bind_style: hud_exit_icon_btn_style
958 role: A11yRole::Button
959 a11y_label: BTN_WATER_EXIT_FS.to_string()
960 on_click: on_fs_exit_top
961 canvas {
962 caching: CanvasCaching::RetainedStatic
963 style: {
964 width: Length::Px(WATER_FS_EXIT_ICON_SIZE)
965 height: Length::Px(WATER_FS_EXIT_ICON_SIZE)
966 }
967 painter: paint_exit_icon
968 }
969 }
970 }
971 row {
972 node_ref: bottom_hud_id
973 style: {
974 position: Position::Absolute
975 inset: (None, Some(0.0), Some(0.0), Some(0.0))
976 width: Length::Percent(100.0)
977 justify: JustifyContent::Center
978 align: AlignItems::Center
979 flex_wrap: FlexWrap::Wrap
980 gap: SPACE_SM
981 padding: Edges::symmetric(SPACE_SM, SPACE_MD)
982 pointer_events: PointerEvents::Auto
983 }
984 { fs_rot_btn }
985 { fs_shake_btn }
986 { fs_reset_btn }
987 { fs_exit_btn }
988 }
989 }
990 };
991 let handle: SceneHandle = ctx.get_scene().clone();
992 let safe_sig: Signal<SafeAreaInsets> = ctx.get_safe_area();
993 let prev_fs: Rc<Cell<bool>> = Rc::new(Cell::new(false));
994 let fs_acquired: Rc<Cell<bool>> = Rc::new(Cell::new(false));
995 let fs_cleanup: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
996 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
997 on_cleanup(move || {
998 if fs_cleanup.replace(false) {
999 exit_fullscreen();
1000 }
1001 });
1002 let _: Effect =
1003 EuvOverlayStack::bind_signal(open, WATER_FS_OVERLAY_NAME, Z_INDEX_FULLSCREEN);
1004 Effect::new(move || {
1005 let is_open: bool = open.get();
1006 let safe: SafeAreaInsets = safe_sig.get();
1007 if is_open != prev_fs.replace(is_open) {
1008 if is_open {
1009 if !fs_acquired.replace(true) {
1010 enter_fullscreen();
1011 }
1012 } else if fs_acquired.replace(false) {
1013 exit_fullscreen();
1014 }
1015 }
1016 handle.with_write(
1017 |tree: &mut SceneTree| {
1018 tree.cancel_subtree_transitions(portal);
1019 if let Some(n) = tree.get_node_mut(inline_viewport) {
1020 let mut st: Style = n.get_style();
1021 st.get_mut_layout().set_display(if is_open {
1022 Display::None
1023 } else {
1024 Display::Flex
1025 });
1026 n.set_style(st);
1027 tree.mark_dirty(inline_viewport, DIRTY_LAYOUT | DIRTY_PAINT);
1028 }
1029 if let Some(n) = tree.get_node_mut(portal) {
1030 let mut st: Style = n.get_style();
1031 st.get_mut_layout().set_display(if is_open {
1032 Display::Flex
1033 } else {
1034 Display::None
1035 });
1036 st.get_mut_paint()
1037 .set_pointer_events(if is_open {
1038 PointerEvents::Auto
1039 } else {
1040 PointerEvents::None
1041 })
1042 .set_opacity(1.0)
1043 .set_transform(Transform2D::default());
1044 n.set_style(st);
1045 }
1046 if let Some(n) = tree.get_node_mut(top_hud_id) {
1047 let mut st: Style = n.get_style();
1048 st.get_mut_layout().set_padding(Edges::new(
1049 SPACE_SM + safe.get_top(),
1050 SPACE_MD + safe.get_right(),
1051 SPACE_SM,
1052 SPACE_MD + safe.get_left(),
1053 ));
1054 n.set_style(st);
1055 tree.mark_dirty(top_hud_id, DIRTY_LAYOUT | DIRTY_PAINT);
1056 }
1057 if let Some(n) = tree.get_node_mut(bottom_hud_id) {
1058 let mut st: Style = n.get_style();
1059 st.get_mut_layout().set_padding(Edges::new(
1060 SPACE_SM,
1061 SPACE_MD + safe.get_right(),
1062 SPACE_SM + safe.get_bottom(),
1063 SPACE_MD + safe.get_left(),
1064 ));
1065 n.set_style(st);
1066 tree.mark_dirty(bottom_hud_id, DIRTY_LAYOUT | DIRTY_PAINT);
1067 }
1068 let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1069 tree.mark_dirty(portal, dirty_l | DIRTY_PAINT);
1070 },
1071 (),
1072 );
1073 })
1074 });
1075 ctx.get_scene().with_write(
1076 |tree: &mut SceneTree| {
1077 tree.attach_scope(portal, scope);
1078 },
1079 (),
1080 );
1081 portal
1082}