euv_example/pages/window/
fn.rs1use super::*;
2
3pub(crate) fn mount_window_viewport_card(
15 state: &ShowcaseState,
16 dpr_sig: Signal<f32>,
17 tokens: ThemeTokens,
18) -> NodeId {
19 let palette: ThemePalette = tokens.get_palette();
20 let ctx_win: Context = current_context();
21 let vp_sig: Signal<Size> = use_viewport_size();
22 let bp_sig: Signal<Breakpoint> = use_breakpoint();
23 let safe_area_sig: Signal<SafeAreaInsets> = use_safe_area();
24 let orient_sig: Signal<ScreenOrientation> = ctx_win.get_orientation();
25 let locale_sig: Signal<String> = ctx_win.get_locale();
26 let focus_sig: Signal<bool> = ctx_win.get_window_focused();
27 let fs_sig: Signal<bool> = state.get_fullscreen();
28 let clip_draft: Signal<String> = Signal::new(WINDOW_CLIPBOARD_DEFAULT.to_string());
29 let clip_status: Signal<String> = Signal::new(WINDOW_CLIPBOARD_READY.to_string());
30 let viewport_line = move || -> String {
31 let box_size: Size = vp_sig.get();
32 format!(
33 "Live Viewport: {:.0}x{:.0} @ {:.2}x DPR | Breakpoint: {:?}",
34 box_size.get_width(),
35 box_size.get_height(),
36 dpr_sig.get(),
37 bp_sig.get()
38 )
39 };
40 let safe_area_line = move || -> String {
41 let sa: SafeAreaInsets = safe_area_sig.get();
42 format!(
43 "SafeArea: T{:.0} R{:.0} B{:.0} L{:.0} | Orientation: {:?}",
44 sa.get_top(),
45 sa.get_right(),
46 sa.get_bottom(),
47 sa.get_left(),
48 orient_sig.get()
49 )
50 };
51 let locale_line = move || -> String {
52 format!(
53 "Locale: {} | Window Focused: {}",
54 locale_sig.get(),
55 focus_sig.get()
56 )
57 };
58 let clip_status_text = move || -> String { clip_status.get() };
59 let ctx_for_copy: Context = ctx_win.clone();
60 let on_copy = move |_: &UiEvent| {
61 let payload: String = clip_draft.get_untracked();
62 let accepted: bool = ctx_for_copy.copy_to_clipboard(&payload);
63 let tag: &str = if accepted {
64 WINDOW_CLIPBOARD_COPIED
65 } else {
66 WINDOW_CLIPBOARD_SIMULATED
67 };
68 let _: bool = clip_status.set(format!("Clipboard ({tag}): {} bytes", payload.len()));
69 };
70 let column_seventh_style: Style = style! {
71 Width(Length::Percent(100.0))
72 Gap(SPACE_SM)
73 };
74 let text_eleventh_style: Style = style! {
75 Width(Length::Percent(100.0))
76 FontSize(13.5)
77 FontWeight::SemiBold
78 TextColor(palette.get_primary())
79 };
80 let text_twelfth_style: Style = style! {
81 Width(Length::Percent(100.0))
82 FontSize(12.5)
83 FontFamily::Monospace
84 TextColor(palette.get_foreground())
85 };
86 let text_thirteenth_style: Style = style! {
87 Width(Length::Percent(100.0))
88 FontSize(12.5)
89 TextColor(palette.get_muted_foreground())
90 };
91 let text_fourteenth_style: Style = style! {
92 Width(Length::Percent(100.0))
93 FontSize(12.0)
94 FontFamily::Monospace
95 TextColor(palette.get_card_foreground())
96 };
97 view! {
98 EuvCard {
99 title: WINDOW_VIEWPORT_CARD_TITLE.to_string()
100 tokens: tokens
101 subtitle: WINDOW_VIEWPORT_CARD_SUB
102 column {
103 style: column_seventh_style
104 text {
105 style: text_eleventh_style
106 { viewport_line }
107 }
108 text {
109 style: text_twelfth_style
110 { safe_area_line }
111 }
112 text {
113 style: text_thirteenth_style
114 { locale_line }
115 }
116 EuvSwitch {
117 checked: fs_sig
118 label: SWITCH_FULLSCREEN.to_string()
119 tokens: tokens
120 }
121 EuvInput {
122 value: clip_draft
123 placeholder: WINDOW_CLIPBOARD_PLACEHOLDER.to_string()
124 tokens: tokens
125 }
126 EuvActionRow {
127 EuvButton {
128 label: WINDOW_BTN_COPY_CLIPBOARD.to_string()
129 tokens: tokens
130 small()
131 on_click: on_copy
132 }
133 }
134 text {
135 style: text_fourteenth_style
136 { clip_status_text }
137 }
138 }
139 }
140 }
141}
142
143pub(crate) fn mount_window_hardware_card(tokens: ThemeTokens) -> NodeId {
153 let palette: ThemePalette = tokens.get_palette();
154 let (font_info, gpu_info): (SystemFontInfo, GpuAdapterInfo) = cached_window_hardware_probe();
155 let platform: PlatformKind = current_platform();
156 let caps: PlatformCapabilities = PlatformCapabilities::for_platform(platform);
157 let summary: String = format!(
158 "Platform: {:?} | Font: {} ({:?})",
159 platform,
160 font_info.get_family_name(),
161 font_info.get_backend()
162 );
163 let gpu_line: String = format!(
164 "GPU Adapter: {} | Shader Compiled: {} | Haptics: {} | A11y Bridge: {}",
165 gpu_info.get_device_name(),
166 gpu_info.get_shader_compiled(),
167 caps.get_haptics(),
168 caps.get_accessibility_bridge()
169 );
170 let column_sixth_style: Style = style! {
171 Width(Length::Percent(100.0))
172 Gap(SPACE_SM)
173 };
174 let text_ninth_style: Style = style! {
175 Width(Length::Percent(100.0))
176 FontSize(13.5)
177 FontWeight::SemiBold
178 TextColor(palette.get_foreground())
179 };
180 let text_tenth_style: Style = style! {
181 Width(Length::Percent(100.0))
182 FontSize(12.5)
183 FontFamily::Monospace
184 TextColor(palette.get_muted_foreground())
185 };
186 view! {
187 EuvCard {
188 title: WINDOW_HARDWARE_CARD_TITLE.to_string()
189 tokens: tokens
190 subtitle: WINDOW_HARDWARE_CARD_SUB
191 column {
192 style: column_sixth_style
193 text {
194 style: text_ninth_style
195 { summary }
196 }
197 text {
198 style: text_tenth_style
199 { gpu_line }
200 }
201 EuvCodeBlock {
202 code: CODE_WINDOW_SNIPPET.to_string()
203 tokens: tokens
204 }
205 }
206 }
207 }
208}
209
210pub(crate) fn mount_window_fps_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
221 let palette: ThemePalette = tokens.get_palette();
222 let ctx_win: Context = current_context();
223 let fps_limit_sig: Signal<Option<u32>> = ctx_win.get_fps_limit();
224 let live_fps_sig: Signal<f32> = ctx_win.get_live_fps();
225 let native_hz_sig: Signal<f32> = ctx_win.get_display_refresh_rate();
226 let demo_fps_idx: Signal<usize> = state.get_demo_fps_cap_index();
227 let demo_fps_line = move || -> String {
228 let native_hz: f32 = native_hz_sig.get().max(24.0);
229 let (target_label, target_hz): (String, f32) = match demo_fps_idx.get() {
230 1 => (FPS_OPT_30.to_string(), 30.0),
231 2 => (FPS_OPT_60.to_string(), 60.0),
232 3 => (FPS_OPT_120.to_string(), 120.0),
233 4 => (FPS_OPT_144.to_string(), 144.0),
234 5 => (FPS_OPT_240.to_string(), 240.0),
235 6 => (FPS_OPT_360.to_string(), 360.0),
236 _ => (format!("{FPS_OPT_NATIVE} ({native_hz:.0} Hz)"), native_hz),
237 };
238 let budget_ms: f32 = 1_000.0 / target_hz;
239 format!("Demo Widget Pacing: {target_label} ({budget_ms:.2} ms/frame — Card-Scoped Only)")
240 };
241 let global_fps_line = move || -> String {
242 let native_hz: f32 = native_hz_sig.get();
243 let cap_txt: String = match fps_limit_sig.get() {
244 None => format!("{FPS_OPT_NATIVE} ({native_hz:.0} Hz)"),
245 Some(item_val) => format!("Capped at {item_val} FPS"),
246 };
247 let live_fps: f32 = live_fps_sig.get();
248 if !live_fps.is_finite() || live_fps <= 0.05 {
249 format!("Global App Policy (Read-Only): {cap_txt} | Status: {LABEL_FPS_IDLE} (0.0 FPS)")
250 } else {
251 format!("Global App Policy (Read-Only): {cap_txt} | Live Measured: {live_fps:.1} FPS")
252 }
253 };
254 let column_fifth_style: Style = style! {
255 Width(Length::Percent(100.0))
256 Gap(SPACE_SM)
257 };
258 let text_seventh_style: Style = style! {
259 Width(Length::Percent(100.0))
260 FontSize(13.0)
261 FontWeight::SemiBold
262 TextColor(palette.get_primary())
263 };
264 let text_eighth_style: Style = style! {
265 Width(Length::Percent(100.0))
266 FontSize(12.5)
267 FontWeight::Medium
268 TextColor(palette.get_muted_foreground())
269 };
270 view! {
271 EuvCard {
272 title: FPS_DEMO_CARD_TITLE.to_string()
273 tokens: tokens
274 subtitle: FPS_DEMO_CARD_SUB
275 column {
276 style: column_fifth_style
277 EuvSegmented {
278 options: vec![
279 FPS_OPT_NATIVE.to_string(),
280 FPS_OPT_30.to_string(),
281 FPS_OPT_60.to_string(),
282 FPS_OPT_120.to_string(),
283 FPS_OPT_144.to_string(),
284 FPS_OPT_240.to_string(),
285 FPS_OPT_360.to_string(),
286 ]
287 selected: demo_fps_idx
288 tokens: tokens
289 }
290 text {
291 style: text_seventh_style
292 { demo_fps_line }
293 }
294 text {
295 style: text_eighth_style
296 { global_fps_line }
297 }
298 }
299 }
300 }
301}
302
303pub(crate) fn mount_window_services_card(
315 state: &ShowcaseState,
316 native_feedback: Signal<String>,
317 tokens: ThemeTokens,
318) -> (NodeId, NodeId) {
319 let palette: ThemePalette = tokens.get_palette();
320 let platform: PlatformKind = current_platform();
321 let caps: PlatformCapabilities = PlatformCapabilities::for_platform(platform);
322 let hub: PlatformServiceHub = PlatformServiceHub::new(platform);
323 let cam_key: &'static str = SystemPermission::Camera.native_key(platform);
324 let island_active: Signal<bool> = state.get_island_active();
325 let island_progress: Signal<u8> = state.get_island_progress();
326 let cam_status: Signal<String> = state.get_camera_perm_status();
327 let proto_status: Signal<String> = state.get_protocol_status();
328 let a11y_count: Signal<u32> = state.get_a11y_announcements();
329 let haptic_count: Signal<u32> = state.get_haptic_pulses();
330 let feedback_text = move || -> String { native_feedback.get() };
331 let island_line = move || -> String {
332 format!(
333 "Dynamic Island: active={} ({}%) | Mode: {:?} | Biometrics: {:?}",
334 island_active.get(),
335 island_progress.get(),
336 PlatformServiceHub::default_island_mode(platform),
337 hub.biometric_kind()
338 )
339 };
340 let proto_cam_line = move || -> String {
341 format!(
342 "Protocol: {} | Camera: {} ({cam_key})",
343 proto_status.get(),
344 cam_status.get()
345 )
346 };
347 let a11y_haptic_line = move || -> String {
348 format!(
349 "A11y Bridge: {} (announcements={}) | Haptics: {} (pulses={})",
350 caps.get_accessibility_bridge(),
351 a11y_count.get(),
352 caps.get_haptics(),
353 haptic_count.get()
354 )
355 };
356 let on_toggle_island = move |_: &UiEvent| {
357 let next_active: bool = !island_active.get_untracked();
358 let _: bool = island_active.set_if_changed(next_active);
359 let next_pct: u8 = if next_active {
360 let cur: u8 = island_progress.get_untracked();
361 if cur >= 100 { 25 } else { (cur + 25).min(100) }
362 } else {
363 island_progress.get_untracked()
364 };
365 let _: bool = island_progress.set_if_changed(next_pct);
366 let mut svc: PlatformServiceHub = PlatformServiceHub::new(platform);
367 if next_active {
368 let mut content: LiveActivityContent = LiveActivityContent::new(
369 WINDOW_ISLAND_TITLE.to_string(),
370 format!("Active ({next_pct}%) on {platform:?}"),
371 );
372 content.set_progress_percent(Some(next_pct));
373 let _: LiveActivityHandle =
374 svc.start_live_activity(WINDOW_ISLAND_ID.to_string(), content);
375 let _: bool = native_feedback.set(format!(
376 "Dynamic Island LIVE ({next_pct}%) dispatched to {platform:?}"
377 ));
378 } else {
379 let _: bool = dispatch_native_action(
380 NATIVE_ACTION_ISLAND,
381 WINDOW_ISLAND_STOP_CMD,
382 WINDOW_ISLAND_STOP_MSG,
383 );
384 let _: bool = native_feedback.set(WINDOW_ISLAND_ENDED.to_string());
385 }
386 };
387 let on_register_proto = move |_: &UiEvent| {
388 let mut reg: ProtocolRegistry = ProtocolRegistry::new();
389 let spec: ProtocolRegistration = ProtocolRegistration::new(
390 "euv".to_string(),
391 WINDOW_PROTO_APP_NAME.to_string(),
392 SHOWCASE_BUNDLE_ID.to_string(),
393 );
394 let native_ok: bool =
395 dispatch_native_action(NATIVE_ACTION_PROTOCOL, "euv", SHOWCASE_BUNDLE_ID);
396 if let Ok(desc) = reg.register(spec, platform) {
397 let tag: &str = if native_ok {
398 WINDOW_PROTO_TAG_BRIDGED
399 } else {
400 WINDOW_PROTO_TAG_VERIFIED
401 };
402 let msg: String = format!("Registered euv:// via {} ({tag})", desc.get_mechanism());
403 let _: bool = proto_status.set_if_changed(msg.clone());
404 let _: bool = native_feedback.set(msg);
405 }
406 };
407 let on_request_cam = move |_: &UiEvent| {
408 let mut mgr: PermissionManager = PermissionManager::new();
409 let desc: PermissionDescriptor = mgr.request(
410 SystemPermission::Camera,
411 WINDOW_CAMERA_REASON.to_string(),
412 platform,
413 );
414 let msg: String = format!("{:?} ({})", desc.get_status(), desc.get_native_key());
415 let _: bool = cam_status.set_if_changed(msg.clone());
416 let _: bool = native_feedback.set(format!("Permission requested: {msg}"));
417 };
418 let on_a11y_haptic = move |_: &UiEvent| {
419 let mut svc: PlatformServiceHub = PlatformServiceHub::new(platform);
420 let fired: bool = svc.trigger_haptic(HapticStyle::Medium);
421 svc.announce_a11y(WINDOW_A11Y_PULSE_MSG.to_string(), A11yLiveRegion::Polite);
422 let _: bool = a11y_count.set(a11y_count.get_untracked() + 1);
423 let _: bool = haptic_count.set(haptic_count.get_untracked() + 1);
424 let _: bool = native_feedback.set(format!(
425 "Dispatched Haptic pulse (ok={fired}) + A11y announcement #{}",
426 a11y_count.get_untracked()
427 ));
428 };
429 let mut body_id: NodeId = NodeId::default();
430 let column_quaternary_style: Style = style! {
431 Width(Length::Percent(100.0))
432 Gap(SPACE_SM)
433 };
434 let text_quaternary_style: Style = style! {
435 Width(Length::Percent(100.0))
436 FontSize(13.0)
437 FontWeight::SemiBold
438 TextColor(palette.get_card_foreground())
439 };
440 let text_fifth_style: Style = style! {
441 Width(Length::Percent(100.0))
442 FontSize(13.0)
443 TextColor(palette.get_primary())
444 };
445 let text_sixth_style: Style = style! {
446 Width(Length::Percent(100.0))
447 FontSize(12.5)
448 TextColor(palette.get_muted_foreground())
449 };
450 let card: NodeId = view! {
451 EuvCard {
452 title: WINDOW_CARD_TITLE.to_string()
453 tokens: tokens
454 subtitle: WINDOW_CARD_SUB
455 column {
456 node_ref: body_id
457 role: A11yRole::Region
458 a11y_label: WINDOW_A11Y_TELEMETRY
459 style: column_quaternary_style
460 text {
461 style: text_quaternary_style
462 { feedback_text }
463 }
464 text {
465 style: text_fifth_style
466 { island_line }
467 }
468 text {
469 style: text_sixth_style
470 { proto_cam_line }
471 }
472 text {
473 style: text_sixth_style
474 { a11y_haptic_line }
475 }
476 EuvActionRow {
477 EuvButton {
478 label: WINDOW_BTN_TOGGLE_ISLAND.to_string()
479 tokens: tokens
480 on_click: on_toggle_island
481 }
482 EuvButton {
483 label: WINDOW_BTN_REGISTER_PROTO.to_string()
484 tokens: tokens
485 outline()
486 on_click: on_register_proto
487 }
488 EuvButton {
489 label: WINDOW_BTN_REQUEST_CAMERA.to_string()
490 tokens: tokens
491 outline()
492 on_click: on_request_cam
493 }
494 EuvButton {
495 label: WINDOW_BTN_A11Y_HAPTIC.to_string()
496 tokens: tokens
497 outline()
498 on_click: on_a11y_haptic
499 }
500 }
501 }
502 }
503 };
504 (card, body_id)
505}
506
507pub(crate) fn mount_window_island_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
518 let target_plat_idx: Signal<usize> = state.get_os_target_platform_idx();
519 let island_mode_idx: Signal<usize> = state.get_island_mode_idx();
520 let island_active: Signal<bool> = state.get_island_active();
521 let island_progress: Signal<u8> = state.get_island_progress();
522 let sys_notifs: Signal<Vec<(String, String)>> = state.get_system_notifications();
523 let pill_text = move || -> String {
524 let tp: PlatformKind = WINDOW_ALL_PLATFORMS[target_plat_idx.get() % 7];
525 let im: IslandPresentationMode = WINDOW_ALL_ISLAND_MODES[island_mode_idx.get() % 6];
526 let def_im: IslandPresentationMode = PlatformServiceHub::default_island_mode(tp);
527 let active: bool = island_active.get();
528 let pct: u8 = island_progress.get();
529 let state_tag: &str = if active {
530 WINDOW_ISLAND_STATE_LIVE
531 } else {
532 WINDOW_ISLAND_STATE_IDLE
533 };
534 format!(
535 "[{state_tag}] Dynamic Island ({tp:?}) | Mode: {im:?} (OS Default: {def_im:?}) | Progress: {pct}%"
536 )
537 };
538 let on_alert_notif = move |_: &UiEvent| {
539 let tp: PlatformKind = WINDOW_ALL_PLATFORMS[target_plat_idx.get_untracked() % 7];
540 let mut svc: PlatformServiceHub = PlatformServiceHub::new(tp);
541 let item_count: SystemNotification = SystemNotification::new(
542 WINDOW_NOTIF_ALERT_ID.to_string(),
543 format!("{tp:?} Alert Notification"),
544 WINDOW_NOTIF_ALERT_BODY.to_string(),
545 );
546 svc.send_notification(item_count.clone());
547 let _: bool = {
548 if let Some(mut updated_value) = sys_notifs.try_get_untracked() {
549 {
550 let text_value: &mut Vec<(String, String)> = &mut updated_value;
551 text_value.insert(
552 0,
553 (
554 item_count.get_title().clone(),
555 item_count.get_body().clone(),
556 ),
557 );
558 text_value.truncate(5);
559 }
560 sys_notifs.set(updated_value)
561 } else {
562 false
563 }
564 };
565 };
566 let on_silent_notif = move |_: &UiEvent| {
567 let tp: PlatformKind = WINDOW_ALL_PLATFORMS[target_plat_idx.get_untracked() % 7];
568 let mut svc: PlatformServiceHub = PlatformServiceHub::new(tp);
569 let mut node_entry: SystemNotification = SystemNotification::new(
570 WINDOW_NOTIF_SYNC_ID.to_string(),
571 format!("{tp:?} Silent Sync (Badge 3)"),
572 WINDOW_NOTIF_SYNC_BODY.to_string(),
573 );
574 node_entry.set_silent(true);
575 node_entry.set_badge_count(Some(3));
576 svc.send_notification(node_entry.clone());
577 let _: bool = {
578 if let Some(mut updated_value) = sys_notifs.try_get_untracked() {
579 {
580 let label_str: &mut Vec<(String, String)> = &mut updated_value;
581 label_str.insert(
582 0,
583 (
584 node_entry.get_title().clone(),
585 node_entry.get_body().clone(),
586 ),
587 );
588 label_str.truncate(5);
589 }
590 sys_notifs.set(updated_value)
591 } else {
592 false
593 }
594 };
595 };
596 let on_clear_notifs = move |_: &UiEvent| {
597 let _: bool = sys_notifs.set_if_changed(Vec::new());
598 };
599 let column_secondary_style: Style = style! {
600 Width(Length::Percent(100.0))
601 Gap(SPACE_SM)
602 };
603 let column_tertiary_style: Style = style! {
604 Width(Length::Percent(100.0))
605 Padding(Edges::all(SPACE_MD))
606 Gap(SPACE_XS)
607 Background(Color::hex(0x09090B))
608 Radius(20.0)
609 Overflow::Hidden
610 };
611 let text_tertiary_style: Style = style! {
612 Width(Length::Percent(100.0))
613 FontSize(12.0)
614 FontWeight::SemiBold
615 TextColor(Color::hex(0xF8FAFC))
616 };
617 view! {
618 EuvCard {
619 title: WINDOW_ISLAND_CARD_TITLE.to_string()
620 tokens: tokens
621 subtitle: WINDOW_ISLAND_CARD_SUB
622 column {
623 style: column_secondary_style
624 EuvSegmented {
625 options: vec![
626 WINDOW_PLAT_IOS.to_string(),
627 WINDOW_PLAT_IPADOS.to_string(),
628 LABEL_PLATFORM_ANDROID.to_string(),
629 LABEL_PLATFORM_MACOS.to_string(),
630 WINDOW_PLAT_WINDOWS.to_string(),
631 WINDOW_PLAT_LINUX.to_string(),
632 WINDOW_PLAT_WEB.to_string(),
633 ]
634 selected: target_plat_idx
635 tokens: tokens
636 }
637 EuvSegmented {
638 options: vec![
639 WINDOW_MODE_COMPACT.to_string(),
640 WINDOW_MODE_MINIMAL.to_string(),
641 WINDOW_MODE_EXPANDED.to_string(),
642 WINDOW_MODE_LOCKSCREEN.to_string(),
643 WINDOW_MODE_FALLBACK.to_string(),
644 WINDOW_MODE_STATUSBAR.to_string(),
645 ]
646 selected: island_mode_idx
647 tokens: tokens
648 }
649 column {
650 style: column_tertiary_style
651 text {
652 style: text_tertiary_style
653 { pill_text }
654 }
655 }
656 EuvActionRow {
657 EuvButton {
658 label: WINDOW_BTN_ALERT_NOTIF.to_string()
659 tokens: tokens
660 small()
661 on_click: on_alert_notif
662 }
663 EuvButton {
664 label: WINDOW_BTN_SILENT_NOTIF.to_string()
665 tokens: tokens
666 outline()
667 small()
668 on_click: on_silent_notif
669 }
670 EuvButton {
671 label: WINDOW_BTN_CLEAR_NOTIFS.to_string()
672 tokens: tokens
673 outline()
674 small()
675 on_click: on_clear_notifs
676 }
677 }
678 EuvSonner {
679 messages: sys_notifs
680 tokens: tokens
681 }
682 }
683 }
684 }
685}
686
687pub(crate) fn mount_window_permissions_card(
699 state: &ShowcaseState,
700 native_feedback: Signal<String>,
701 tokens: ThemeTokens,
702) -> NodeId {
703 let platform: PlatformKind = current_platform();
704 let target_plat_idx: Signal<usize> = state.get_os_target_platform_idx();
705 let perm_statuses: Signal<Vec<PermissionStatus>> = state.get_permission_statuses();
706 let vp_sig: Signal<Size> = use_viewport_size();
707 let matrix_grid_style = move || -> Style {
708 let cols: u16 = responsive_grid_columns(vp_sig.get().get_width(), 2);
709 style! {
710 GridColumns(cols)
711 Width(Length::Percent(100.0))
712 Gap(SPACE_SM)
713 }
714 };
715 let build_perm_cards = move || -> Vec<NodeId> {
716 let live: ThemeTokens = live_tokens_untracked(tokens);
717 let live_p: ThemePalette = live.get_palette();
718 let live_g: ThemeGeometry = live.get_geometry();
719 let tp: PlatformKind = WINDOW_ALL_PLATFORMS[target_plat_idx.get() % 7];
720 let statuses: Vec<PermissionStatus> = perm_statuses.get();
721 WINDOW_ALL_PERMS
722 .iter()
723 .copied()
724 .enumerate()
725 .map(|(idx, perm): (usize, SystemPermission)| {
726 let node_style: PermissionStatus = statuses
727 .get(idx)
728 .copied()
729 .unwrap_or(PermissionStatus::NotDetermined);
730 let native_key: &'static str = perm.native_key(tp);
731 let row_title: String = format!("{perm:?} [{node_style:?}]");
732 let key_line: String = native_key.to_string();
733 let on_req = move |_: &UiEvent| {
734 let mut mgr: PermissionManager = PermissionManager::new();
735 let desc: PermissionDescriptor =
736 mgr.request(perm, format!("Test {perm:?} access"), platform);
737 let _: bool = {
738 if let Some(mut updated_value) = perm_statuses.try_get_untracked() {
739 {
740 let vec: &mut Vec<PermissionStatus> = &mut updated_value;
741 if let Some(slot) = vec.get_mut(idx) {
742 *slot = desc.get_status();
743 }
744 }
745 perm_statuses.set(updated_value)
746 } else {
747 false
748 }
749 };
750 let _: bool = native_feedback.set(format!(
751 "Requested {perm:?} ({}) -> {:?}",
752 perm.native_key(platform),
753 desc.get_status()
754 ));
755 };
756 let on_deny = move |_: &UiEvent| {
757 let _: bool = {
758 if let Some(mut updated_value) = perm_statuses.try_get_untracked() {
759 {
760 let vec: &mut Vec<PermissionStatus> = &mut updated_value;
761 if let Some(slot) = vec.get_mut(idx) {
762 *slot = PermissionStatus::Denied;
763 }
764 }
765 perm_statuses.set(updated_value)
766 } else {
767 false
768 }
769 };
770 let _: bool = native_feedback.set(format!("Marked {perm:?} as Denied"));
771 };
772 let column_style: Style = style! {
773 Width(Length::Percent(100.0))
774 Padding(Edges::all(SPACE_MD))
775 Gap(SPACE_XS)
776 Background(live_p.get_card())
777 Border::new(live_g.get_border_width(), live_p.get_border())
778 Radius(live_g.get_radius_sm())
779 Overflow::Hidden
780 };
781 let text_style: Style = style! {
782 Width(Length::Percent(100.0))
783 FontSize(12.5)
784 FontWeight::SemiBold
785 TextColor(live_p.get_card_foreground())
786 };
787 let text_secondary_style: Style = style! {
788 Width(Length::Percent(100.0))
789 FontSize(11.5)
790 FontFamily::Monospace
791 TextColor(live_p.get_muted_foreground())
792 };
793 view! {
794 column {
795 style: column_style
796 text {
797 style: text_style
798 { row_title }
799 }
800 text {
801 style: text_secondary_style
802 { key_line }
803 }
804 EuvActionRow {
805 EuvButton {
806 label: WINDOW_BTN_PERM_REQUEST.to_string()
807 tokens: live
808 outline()
809 small()
810 on_click: on_req
811 }
812 EuvButton {
813 label: WINDOW_BTN_PERM_DENY.to_string()
814 tokens: live
815 destructive()
816 small()
817 on_click: on_deny
818 }
819 }
820 }
821 }
822 })
823 .collect()
824 };
825 view! {
826 EuvCard {
827 title: WINDOW_PERMS_CARD_TITLE.to_string()
828 tokens: tokens
829 subtitle: WINDOW_PERMS_CARD_SUB
830 grid {
831 bind_style: matrix_grid_style
832 bind_children: build_perm_cards
833 }
834 }
835 }
836}
837
838pub fn mount_window_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
849 let ctx_win: Context = current_context();
850 let native_feedback: Signal<String> = Signal::new(WINDOW_READY_FEEDBACK.to_string());
851 let dpr_sig: Signal<f32> = Signal::new(1.0);
852 let fs_sig: Signal<bool> = state.get_fullscreen();
853 let prev_fs: Rc<Cell<bool>> = Rc::new(Cell::new(fs_sig.get_untracked()));
854 let (win_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
855 let _: SystemEventSubscription = on_system_event(move |system_event: &SystemEvent| {
856 if let SystemEvent::Resize { scale_factor, .. } = system_event {
857 let _: bool = dpr_sig.set_if_changed(*scale_factor);
858 }
859 });
860 Effect::new(move || {
861 let now_fs: bool = fs_sig.get();
862 if prev_fs.replace(now_fs) != now_fs {
863 let arg: &str = if now_fs { "on" } else { "off" };
864 let _: bool = dispatch_native_action(NATIVE_ACTION_FULLSCREEN, arg, "");
865 let _: bool = native_feedback.set(format!("Immersive fullscreen mode: {arg}"));
866 }
867 })
868 });
869 let viewport_card: NodeId = mount_window_viewport_card(state, dpr_sig, tokens);
870 let hardware_card: NodeId = mount_window_hardware_card(tokens);
871 let fps_card: NodeId = mount_window_fps_card(state, tokens);
872 let (services_card, body_id): (NodeId, NodeId) =
873 mount_window_services_card(state, native_feedback, tokens);
874 let island_card: NodeId = mount_window_island_card(state, tokens);
875 let perms_card: NodeId = mount_window_permissions_card(state, native_feedback, tokens);
876 let top_grid: NodeId = mount_responsive_grid(vec![viewport_card, services_card], 2);
877 let mid_grid: NodeId = mount_responsive_grid(vec![fps_card, hardware_card], 2);
878 let page: NodeId = view! {
879 EuvPage {
880 title: WINDOW_TITLE.to_string()
881 subtitle: WINDOW_SUBTITLE.to_string()
882 tokens: tokens
883 { top_grid }
884 { mid_grid }
885 { island_card }
886 { perms_card }
887 }
888 };
889 ctx_win.get_scene().with_write(
890 |tree: &mut SceneTree| {
891 tree.attach_scope(body_id, win_scope);
892 },
893 (),
894 );
895 page
896}