use super::*;
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! {
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 height_val: f32 = adaptive_viewport_height(vp_sig.get().get_height());
style! {
FlexDirection::Column
Width(Length::Percent(100.0))
Height(Length::Px(height_val))
Overflow::Hidden
Border::new(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, tokens);
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 column_seventh_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_MD)
};
let rail: NodeId = view! {
column {
style: column_seventh_style
{ 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
}
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);
if host_motion.is_paused() {
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 prev_visc_idx: Rc<Cell<usize>> = Rc::new(Cell::new(0));
let _: Effect = Effect::new(move || {
let idx: usize = visc_idx_sig.get();
let (visc, tension): (f32, f32) = match idx {
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);
if prev_visc_idx.replace(idx) != idx {
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
}
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());
}
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 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 hint_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
style! {
Width(Length::Percent(100.0))
FontSize(12.0)
FontFamily::Monospace
TextColor(live.get_palette().get_muted_foreground())
}
};
let column_sixth_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_MD)
Overflow::Hidden
};
view! {
EuvCard {
title: WATER_VESSEL_TITLE.to_string()
tokens: tokens
subtitle: WATER_VESSEL_SUB
column {
style: column_sixth_style
{ viewport_frame }
EuvActionRow {
EuvButton {
label: BTN_WATER_FULLSCREEN.to_string()
tokens: tokens
small()
on_click: on_open_fs
}
EuvButton {
label: BTN_WATER_ROTATE_90.to_string()
tokens: tokens
outline()
small()
on_click: on_rotate_90
}
}
text {
bind_style: hint_style
{ WATER_CONTROLS_HINT }
}
}
}
}
}
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! {
FlexDirection::Row
Padding(Edges::symmetric(SPACE_XS, SPACE_SM))
Radius(WATER_FS_PILL_RADIUS)
Background(bg)
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! {
FontSize(12.0)
FontWeight::SemiBold
TextColor(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! {
Width(Length::Percent(100.0))
FontSize(12.0)
TextColor(live.get_palette().get_muted_foreground())
}
};
let status_text = move || -> String { perm_status_sig.get() };
let column_fifth_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_SM)
Overflow::Hidden
};
let row_tertiary_style: Style = style! {
Width(Length::Percent(100.0))
FlexWrap::Wrap
AlignItems::Center
Gap(SPACE_SM)
};
view! {
EuvCard {
title: WATER_SENSOR_CARD_TITLE.to_string()
tokens: tokens
subtitle: WATER_SENSOR_CARD_SUB
column {
style: column_fifth_style
row {
style: row_tertiary_style
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()
small()
on_click: on_request_perm
}
}
text {
bind_style: status_style
{ status_text }
}
}
}
}
}
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;
let scene_flip: 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 key_hint_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
style! {
Width(Length::Percent(100.0))
FontSize(12.0)
FontFamily::Monospace
TextColor(live.get_palette().get_muted_foreground())
}
};
let column_quaternary_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_SM)
Overflow::Hidden
};
view! {
EuvCard {
title: WATER_MOTION_CARD_TITLE.to_string()
tokens: tokens
subtitle: WATER_MOTION_CARD_SUB
column {
style: column_quaternary_style
EuvActionRow {
EuvButton {
label: BTN_WATER_TILT_LEFT.to_string()
tokens: tokens
outline()
small()
on_click: on_tilt_left
}
EuvButton {
label: BTN_WATER_LEVEL.to_string()
tokens: tokens
outline()
small()
on_click: on_level
}
EuvButton {
label: BTN_WATER_TILT_RIGHT.to_string()
tokens: tokens
outline()
small()
on_click: on_tilt_right
}
}
EuvActionRow {
EuvButton {
label: BTN_WATER_ROT_CW.to_string()
tokens: tokens
outline()
small()
on_click: on_rot_cw
}
EuvButton {
label: BTN_WATER_ROT_CCW.to_string()
tokens: tokens
outline()
small()
on_click: on_rot_ccw
}
EuvButton {
label: BTN_WATER_FLIP_180.to_string()
tokens: tokens
outline()
small()
on_click: on_flip_180
}
}
text {
bind_style: key_hint_style
{ WATER_KEYBOARD_HINT }
}
}
}
}
}
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! {
Width(Length::Percent(100.0))
FontSize(12.5)
FontWeight::Medium
TextColor(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);
};
let column_secondary_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_MD)
Overflow::Hidden
};
let column_tertiary_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_XS)
};
view! {
EuvCard {
title: WATER_PHYSICS_CARD_TITLE.to_string()
tokens: tokens
subtitle: WATER_PHYSICS_CARD_SUB
column {
style: column_secondary_style
column {
style: column_tertiary_style
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()
small()
on_click: on_reset_params
}
}
}
}
}
}
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! {
Width(Length::Percent(100.0))
FontSize(12.5)
FontFamily::Monospace
FontWeight::SemiBold
TextColor(live.get_palette().get_card_foreground())
}
};
let mono_muted_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
style! {
Width(Length::Percent(100.0))
FontSize(12.0)
FontFamily::Monospace
TextColor(live.get_palette().get_muted_foreground())
}
};
let gravity_text = move || -> String {
let source_val: GyroLiquidStats = stats_sig.get();
format!(
"Gravity: ({:+.2}, {:+.2}, {:+.2}) m/s²",
source_val.get_gravity_x(),
source_val.get_gravity_y(),
source_val.get_gravity_z()
)
};
let tilt_text = move || -> String {
let scale_val: GyroLiquidStats = stats_sig.get();
format!(
"Tilt: {:+.1}° · Wave Peak: {:.1} mm",
scale_val.get_tilt_angle_deg(),
scale_val.get_peak_wave_height_m() * 1000.0
)
};
let counts_text = move || -> String {
let series_item: GyroLiquidStats = stats_sig.get();
format!(
"Particles: {} · Micro-Bubbles: {} · Bodies: {}",
series_item.get_particle_count(),
series_item.get_bubble_count(),
series_item.get_buoyant_body_count()
)
};
let perf_text = move || -> String {
let text_slice: GyroLiquidStats = stats_sig.get();
format!(
"Kinetic: {:.2} mJ · Sim: {:.2} ms · Render: {:.2} ms",
text_slice.get_kinetic_energy_mj(),
text_slice.get_sim_time_ms(),
text_slice.get_render_time_ms()
)
};
let pso_sig: Signal<Option<ShaderPrecompileReport>> = Signal::new(shader_precompile_status());
let on_precompile_ocean = move |_: &UiEvent| {
let report: ShaderPrecompileReport = precompile_shaders(default_native_gpu_backend());
let _: bool = pso_sig.set(Some(report));
};
let pso_text = move || -> String {
if let Some(report) = pso_sig.get()
&& let Some(entry) = report.entry_for(ShaderProgramId::FluidOceanOptical)
{
let hit_tag: &str = if report.get_cache_hit() {
"Warm Hit"
} else {
entry.get_state().label()
};
format!(
"Ocean PSO [{}] · {hit_tag} · LUTs Warm ({}/{})",
entry.get_language(),
report.get_ready_programs(),
report.get_total_programs(),
)
} else {
format!(
"Ocean PSO [{}] · Sky/ACES LUTs Warm · Verify GPU PSO below",
ShaderProgramId::language_for_backend(default_native_gpu_backend()),
)
}
};
let column_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_XS)
Overflow::Hidden
};
view! {
EuvCard {
title: WATER_TELEMETRY_CARD_TITLE.to_string()
tokens: tokens
subtitle: WATER_TELEMETRY_CARD_SUB
column {
style: column_style
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 }
}
text {
bind_style: mono_muted_style
{ pso_text }
}
EuvActionRow {
EuvButton {
label: BTN_WATER_PRECOMPILE_PSO.to_string()
tokens: tokens
outline()
small()
on_click: on_precompile_ocean
}
}
}
}
}
}
fn mount_water_fs_pill_button<CallbackFn>(
label: &str,
tokens: ThemeTokens,
on_click: CallbackFn,
) -> NodeId
where
CallbackFn: Fn(&UiEvent) + 'static,
{
let text_str: String = label.to_string();
let a11y_str: String = label.to_string();
let pill_style = move || -> Style {
let dark_tok: ThemeTokens =
ThemeTokens::resolve(use_live_tokens(tokens).get_scheme(), ThemeMode::Dark);
let dark_p: ThemePalette = dark_tok.get_palette();
let dark_g: ThemeGeometry = dark_tok.get_geometry();
style! {
FlexDirection::Row
Padding(Edges::symmetric(SPACE_XS, SPACE_MD))
Radius(WATER_FS_PILL_RADIUS)
Background(dark_p.get_card().with_alpha(232))
Border::new(dark_g.get_border_width(), dark_p.get_border())
AlignItems::Center
JustifyContent::Center
CursorIcon::Pointer
PointerEvents::Auto
}
};
let text_style = move || -> Style {
let dark_tok: ThemeTokens =
ThemeTokens::resolve(use_live_tokens(tokens).get_scheme(), ThemeMode::Dark);
style! {
FontSize(12.5)
FontWeight::SemiBold
TextColor(dark_tok.get_palette().get_foreground())
TextOverflow::Clip
}
};
view! {
row {
bind_style: pill_style
role: A11yRole::Button
a11y_label: a11y_str
on_click: on_click
text {
bind_style: text_style
{ text_str }
}
}
}
}
fn mount_water_fullscreen_portal(
state: &ShowcaseState,
scene: &GyroLiquidGameScene,
inline_viewport: NodeId,
tokens: ThemeTokens,
) -> 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 safe_sig: Signal<SafeAreaInsets> = ctx.get_safe_area();
let vp_sig: Signal<Size> = ctx.get_viewport_size();
let fs_viewport: NodeId = host.mount_viewport(style! {
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::Hidden
StopScrollPropagation(true)
StopEventPropagation(true)
});
let host_rot: GameEngineHost = host.clone();
let scene_rot: 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_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, tokens, on_fs_rot);
let fs_reset_btn: NodeId = mount_water_fs_pill_button(BTN_WATER_FS_RESET, tokens, on_fs_reset);
let fs_exit_btn: NodeId =
mount_water_fs_pill_button(BTN_WATER_EXIT_FS, tokens, on_fs_exit_bottom);
let hud_telemetry = move || -> String {
let source_val: GyroLiquidStats = stats_sig.get();
format!(
"{} · {:+.1}°",
WATER_FS_TITLE,
source_val.get_tilt_angle_deg()
)
};
let hud_chip_style = move || -> Style {
let dark_tok: ThemeTokens =
ThemeTokens::resolve(use_live_tokens(tokens).get_scheme(), ThemeMode::Dark);
let dark_p: ThemePalette = dark_tok.get_palette();
let dark_g: ThemeGeometry = dark_tok.get_geometry();
let fs_lay: FullscreenSafeLayout =
resolve_fullscreen_safe_layout(vp_sig.get(), safe_sig.get());
let hp: Edges = fs_lay.get_header_padding();
style! {
Position::Absolute
Inset(Some(hp.get_top()), None, None, Some(hp.get_left()))
FlexDirection::Row
Padding(Edges::symmetric(SPACE_XS, SPACE_MD))
Radius(WATER_FS_PILL_RADIUS)
Background(dark_p.get_card().with_alpha(232))
Border::new(dark_g.get_border_width(), dark_p.get_border())
AlignItems::Center
PointerEvents::None
}
};
let hud_chip_text_style = move || -> Style {
let dark_tok: ThemeTokens =
ThemeTokens::resolve(use_live_tokens(tokens).get_scheme(), ThemeMode::Dark);
style! {
FontSize(12.5)
FontWeight::SemiBold
TextColor(dark_tok.get_palette().get_foreground())
TextOverflow::Clip
}
};
let hud_exit_icon_btn_style = move || -> Style {
let dark_tok: ThemeTokens =
ThemeTokens::resolve(use_live_tokens(tokens).get_scheme(), ThemeMode::Dark);
let dark_p: ThemePalette = dark_tok.get_palette();
let dark_g: ThemeGeometry = dark_tok.get_geometry();
let fs_lay: FullscreenSafeLayout =
resolve_fullscreen_safe_layout(vp_sig.get(), safe_sig.get());
let hp: Edges = fs_lay.get_header_padding();
style! {
Position::Absolute
Inset(Some(hp.get_top()), Some(hp.get_right()), None, None)
FlexDirection::Row
Width(Length::Px(FS_EXIT_BTN_SIZE))
Height(Length::Px(FS_EXIT_BTN_SIZE))
JustifyContent::Center
AlignItems::Center
Radius(WATER_FS_PILL_RADIUS)
Background(dark_p.get_card().with_alpha(232))
Border::new(dark_g.get_border_width(), dark_p.get_border())
CursorIcon::Pointer
PointerEvents::Auto
StopEventPropagation(true)
ZIndex(2)
}
};
let paint_exit_icon = move |bounds: Rect, display_list: &mut DisplayList| {
let dark_tok: ThemeTokens =
ThemeTokens::resolve(live_tokens_untracked(tokens).get_scheme(), ThemeMode::Dark);
draw_euv_icon(
EuvIconName::Minimize,
bounds,
display_list,
dark_tok.get_palette().get_foreground(),
);
};
let portal_style: Style = style! {
FlexDirection::Column
Display::None
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::new(0.0, COLOR_TRANSPARENT)
Radius(0.0)
Overflow::Hidden
PointerEvents::None
StopScrollPropagation(true)
StopEventPropagation(true)
ZIndex(Z_INDEX_FULLSCREEN)
};
let canvas_style: Style = style! {
Width(Length::Px(WATER_FS_EXIT_ICON_SIZE))
Height(Length::Px(WATER_FS_EXIT_ICON_SIZE))
};
let bottom_hud_style = move || -> Style {
let vp: Size = vp_sig.get();
let fs_lay: FullscreenSafeLayout = resolve_fullscreen_safe_layout(vp, safe_sig.get());
let fp: Edges = fs_lay.get_footer_padding();
let avail_w: f32 = (vp.get_width() - fp.get_left() - fp.get_right()).max(120.0);
style! {
Position::Absolute
Inset(None, Some(fp.get_right()), Some(fp.get_bottom()), Some(fp.get_left()))
Width(Length::Px(avail_w))
JustifyContent::Center
AlignItems::Center
FlexWrap::Wrap
Gap(SPACE_SM)
Padding(Edges::all(0.0))
PointerEvents::Auto
ZIndex(2)
}
};
let portal: NodeId = view! {
portal {
style: portal_style
{ fs_viewport }
row {
bind_style: hud_chip_style
text {
bind_style: hud_chip_text_style
{ hud_telemetry }
}
}
row {
bind_style: hud_exit_icon_btn_style
role: A11yRole::Button
a11y_label: BTN_WATER_EXIT_FS.to_string()
on_click: on_fs_exit_top
canvas {
caching: CanvasCaching::RetainedStatic
style: canvas_style
painter: paint_exit_icon
}
}
row {
bind_style: bottom_hud_style
{ fs_rot_btn }
{ fs_reset_btn }
{ fs_exit_btn }
}
}
};
let handle: SceneHandle = ctx.get_scene().clone();
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();
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(item_count) = tree.get_node_mut(inline_viewport) {
let mut computed_style: Style = item_count.get_style();
computed_style.get_mut_layout().set_display(if is_open {
Display::None
} else {
Display::Flex
});
item_count.set_style(computed_style);
tree.mark_dirty(inline_viewport, DIRTY_LAYOUT | DIRTY_PAINT);
}
if let Some(node_entry) = tree.get_node_mut(portal) {
let mut element_style: Style = node_entry.get_style();
element_style.get_mut_layout().set_display(if is_open {
Display::Flex
} else {
Display::None
});
element_style
.get_mut_paint()
.set_pointer_events(if is_open {
PointerEvents::Auto
} else {
PointerEvents::None
})
.set_opacity(1.0)
.set_transform(Transform2D::default());
node_entry.set_style(element_style);
}
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
}