//! The permission steps of `"Prototypes/Onboarding/First run"`: the //! microphone before the practice and Accessibility after it, featuring: //! //! - One `440 pt` column shared by Hex's setup card, System Settings, and the //! floating drag guide, with every app icon aligned on one vertical spine //! (`x = 26 pt`). //! - Calm, zero-bounce permission state pills (`Allow` -> `Asking…` -> //! `✓ Allowed`) with no harsh blinking or glow. //! - Escaping Accessibility panel: when Accessibility is requested, the helper //! panel inside Hex's card detaches, leaving a recessed outline socket //! behind, and floats down across the screen to dock underneath System //! Settings. Then the Hex row lifts cleanly out of that guide into an //! expanding slot in System Settings' Accessibility list. use rune::{ Anim, Color, El, MotionIntent, Spring, TextStyle, Transition, col, el, icon, row, text, }; use rune_kit::{Button, ButtonVariant, glyphs}; use super::super::controls::{Paint, PushSize}; use super::super::paste_access::PasteAccess; use super::flows::continue_button; use super::hex_meter::hex_meter; use super::landing::{LEAD, Motion, arrives, title_font}; use super::live::Live; use super::stories::{Onboard, Step}; use crate::desktop::i18n::tr; use crate::desktop::onboarding::{ItemStatus, SetupItem}; /// Total duration of the automated permissions step. pub(crate) const PERMISSIONS_SECS: f64 = 7.2; /// The automated microphone step. pub(crate) const MIC_SECS: f64 = MIC_FLOAT + FLOAT_OFF + 0.05; /// An allowed permission's check holds this long; then its card lets go /// and floats off upward for this long before the next page comes in. pub(crate) const GRANTED_BEAT: f64 = 0.6; pub(crate) const FLOAT_OFF: f64 = 0.7; const MIC_FLOAT: f64 = MIC_GRANT + GRANTED_BEAT; const AX_FLOAT: f64 = SETTINGS_CLOSE + 0.2; /// Where the Accessibility step starts on the shared timeline, and how /// long it then runs. pub(crate) const AX_SHIFT: f64 = AX_TRAY_OPEN - 0.6; pub(crate) const AX_SECS: f64 = PERMISSIONS_SECS - AX_SHIFT; const COL_W: f32 = 440.0; const STAGE_H: f32 = 424.0; const ACTION_H: f32 = 32.0; // Timeline beats (seconds since `permissions_from`). const MIC_ASK: f64 = 0.85; const MIC_PRESS: f64 = 1.75; pub(crate) const MIC_GRANT: f64 = 2.10; const AX_TRAY_OPEN: f64 = 2.25; pub(crate) const AX_ESCAPE: f64 = 2.85; const AX_DOCKED: f64 = 3.55; const DRAG: (f64, f64) = (3.85, 4.75); const SWITCH_ON: f64 = 4.90; pub(crate) const AX_GRANT: f64 = 5.15; const SETTINGS_CLOSE: f64 = 5.80; const CONTINUE_AT: f64 = 6.00; const MIC_CONTINUE: f64 = 2.45; // Unified geometry inside the `440 pt` stage. const ROW_H: f32 = 58.0; const SOCKET_TRAY_H: f32 = 52.0; const SOCKET_RECT: [f32; 4] = [12.0, 2.0 * ROW_H + 6.0, COL_W - 24.0, 38.0]; const SETTINGS_Y: f32 = 2.0 * ROW_H + SOCKET_TRAY_H + 14.0; // 182.0 const SETTINGS_H: f32 = 152.0; const LIST_INSET: f32 = 16.0; const LIST_Y: f32 = 54.0; const LIST_W: f32 = COL_W - 2.0 * LIST_INSET; // 408.0 const LIST_ROW_H: f32 = 28.0; const ROW_PX: f32 = 10.0; // App icons sit at `16.0 + 10.0 = 26.0` everywhere! const GUIDE_Y: f32 = SETTINGS_Y + SETTINGS_H + 10.0; // 344.0 const GUIDE_H: f32 = 70.0; const PROMPT_W: f32 = 276.0; const MIC_STAGE_H: f32 = ROW_H + 18.0 + 214.0; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) enum PermState { Allow { primary: bool }, Asking, Allowed, } pub(crate) fn state_at(e: f64, ask: f64, grant: f64, primary: bool) -> PermState { if e < ask { PermState::Allow { primary } } else if e < grant { PermState::Asking } else { PermState::Allowed } } /// How far an allowed card has floated off, `e` seconds into its page. fn float_u(e: f64, from: f64) -> f32 { ((e - from) / FLOAT_OFF).clamp(0.0, 1.0) as f32 } /// An allowed card letting go: a small dip as it detaches, then up and /// away, faster as it goes, shrinking and fading into the void. fn float_off(card: El, u: f32, reduced: bool) -> El { if u <= 0.0 { return card; } if reduced { return card.opacity(1.0 - u).opacity_motion(Anim::INSTANT); } const DIP: f32 = 0.16; let (y, scale) = if u < DIP { let d = (std::f32::consts::PI * u / DIP).sin(); (5.0 * d, 1.0 + 0.025 * d) } else { let v = (u - DIP) / (1.0 - DIP); (-460.0 * v * v - 40.0 * v, 1.0 - 0.14 * v) }; let v = ((u - DIP) / (1.0 - DIP)).max(0.0); card.offset(0.0, y) .offset_motion(Anim::INSTANT) .scale(scale) .scale_motion(Anim::INSTANT) .rotate(-0.05 * v * v) .rotate_motion(Anim::INSTANT) .blur(6.0 * v * v) .blur_motion(Anim::INSTANT) .opacity(1.0 - smoothstep((v - 0.25) / 0.75)) .opacity_motion(Anim::INSTANT) } fn smoothstep(t: f32) -> f32 { let t = t.clamp(0.0, 1.0); t * t * (3.0 - 2.0 * t) } fn lerp(a: f32, b: f32, t: f32) -> f32 { a + (b - a) * t } pub(super) fn page(p: Paint, s: &Onboard) -> El { let which = if s.step == Step::Accessibility { Perm::Accessibility } else { Perm::Microphone }; if let Some(live) = &s.live { return live_page(p, live, s, which); } let e = s.permissions_from.map_or(0.0, |from| s.now - from); let reduced = s.reduced.get(); let (stage, continue_at) = match which { Perm::Microphone => ( microphone_stage(p, e, state_at(e, MIC_ASK, MIC_GRANT, true), reduced), MIC_CONTINUE, ), // Accessibility joins the shared timeline where its tray opens. Perm::Accessibility => { let e = e + AX_SHIFT; let ax = state_at(e, AX_ESCAPE, AX_GRANT, true); ( stage(p, e, PermState::Allowed, ax, reduced), CONTINUE_AT - AX_SHIFT, ) } }; col() .key("permissions") .gap(22.0) .items_center() .child(heading(p, s.motion, which)) .child(s.motion.staggered(stage, 1.0, 8.0)) .child( row() .key("action") .h(ACTION_H) .center() .child(if e >= continue_at { continue_button(p, s) } else { el().key("none") }), ) } /// Which permission a page asks for: the microphone before the practice, /// Accessibility after it. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) enum Perm { Microphone, Accessibility, } fn heading(p: Paint, motion: Motion, which: Perm) -> El { let (title, lead) = match which { Perm::Microphone => ( tr("Let Hex hear you"), tr("Hex listens only while you hold your shortcut."), ), Perm::Accessibility => ( tr("Make it work everywhere"), tr("Let Hex notice your shortcut and type your words in any app."), ), }; heading_with(p, motion, which, title, lead) } fn heading_with(p: Paint, motion: Motion, which: Perm, title: &str, lead: &str) -> El { let key = match which { Perm::Microphone => "microphone-head", Perm::Accessibility => "accessibility-head", }; motion.heading( col() .key(key) .gap(8.0) .items_center() .child(text(title).key("title").font(title_font(p)).color(p.text())) .child( text(lead) .key("lead") .font(LEAD) .color(p.muted()) .align(rune::Align::Center), ), ) } /// The microphone alone: Hex's row, then macOS's prompt under it. fn microphone_stage(p: Paint, e: f64, mic: PermState, reduced: bool) -> El { let k = p.k; let card = col() .key("setup-card") .motion_intent(MotionIntent::BOUNCE) .absolute(0.0, 0.0) .w(COL_W) .radius(k.radius.lg) .fill(k.c.bg_base) .border(p.hair, k.c.border_weak) .child(perm_row( p, "mic-row", &glyphs::MIC, "Microphone", "Hears you while you hold the shortcut", perm_pill(p, "mic-pill", mic), )); let mut stage = el() .key("microphone-stage") .size(COL_W, MIC_STAGE_H) .child(float_off( k.elevate(card, &k.elevation.raised), float_u(e, MIC_FLOAT), reduced, )); if (MIC_ASK..MIC_GRANT).contains(&e) { stage = stage.child( microphone_prompt(p, e >= MIC_PRESS) .absolute((COL_W - PROMPT_W) * 0.5, ROW_H + 18.0) .transition(arrives()), ); } stage } /// The real first run's permissions: macOS's own prompt and System Settings /// with Hex's guide, and the rows follow what macOS reports. fn live_page(p: Paint, live: &Live, s: &Onboard, which: Perm) -> El { let motion = s.motion; if let Some(paste) = live.paste { return paste_page(p, paste, motion); } let k = p.k; let mic_ready = live.microphone == ItemStatus::Ready; let windows = !live.accessibility_row; let mic_desc = match live.microphone { ItemStatus::Denied | ItemStatus::Waiting if windows => { tr("Turn on “Let desktop apps access your microphone” in Windows Settings.") } ItemStatus::Denied => tr("Switch on Hex in System Settings"), _ if live.release_microphone => tr("Opens only while you dictate"), _ if windows => tr("Ready the moment you press the shortcut"), _ => tr( "Ready the moment you press the shortcut. macOS shows the mic in use while Hex runs; you can change that in Settings", ), }; let mic_row = perm_row( p, "mic-row", &glyphs::MIC, tr("Microphone"), mic_desc, live_pill( p, "mic-pill", live, live.microphone, true, SetupItem::Microphone, ), ); let card = card(p); // An allowed microphone has already floated off by Accessibility. let card = match which { Perm::Accessibility if mic_ready => card, _ => card.child(mic_row), }; let card = match which { Perm::Accessibility if live.accessibility_row => { let ax_desc = match live.accessibility { ItemStatus::Stale => tr("An older Hex entry can keep this off"), ItemStatus::Waiting => tr("Switch on Hex in System Settings"), ItemStatus::Restart => tr("Turns on when Hex restarts"), _ => tr("Notices the shortcut and pastes your words"), }; card.children((!mic_ready).then(|| separator(p, "sep0"))) .child(perm_row( p, "ax-row", &glyphs::CURSOR_TEXT, super::super::platform_settings::accessibility_name(live.accessibility_renamed), ax_desc, live_pill( p, "ax-pill", live, live.accessibility, mic_ready, SetupItem::Accessibility, ), )) } _ => card, }; let action = if live.restart { Button::new(tr("Restart Hex")) .variant(ButtonVariant::Contrast) .on_press(super::live::restart_hex) .build_push(k) .key("restart") .default_button() .transition(arrives()) } else { el().key("none") }; let head = if windows { heading_with( p, motion, which, tr("Let Hex hear you"), tr("Windows has the microphone turned off for desktop apps."), ) } else { heading(p, motion, which) }; let relaunch = live.relaunch_failed.then(|| { text(tr( "Quit and reopen Hex to finish setup. macOS applies some permissions only after a restart.", )) .key("relaunch-notice") .font(LEAD) .color(p.muted()) .align(rune::Align::Center) .wrap() .w(COL_W) .transition(arrives()) }); col() .key("permissions") .gap(22.0) .items_center() .child(head) .child(float_off( motion.staggered(k.elevate(card, &k.elevation.raised), 1.0, 8.0), live.floated(which == Perm::Accessibility, s.now), s.reduced.get(), )) .children(relaunch) .child(row().key("action").h(ACTION_H).center().child(action)) } /// GNOME and KDE on Wayland: Hex pastes through the desktop's /// RemoteDesktop portal, whose dialog asks once (#932). This page says what /// it is for before Allow opens it. fn paste_page(p: Paint, paste: PasteAccess, motion: Motion) -> El { let k = p.k; let desc = if paste == PasteAccess::Declined { tr("Without it, Hex copies your words and you press Ctrl+V.") } else { tr("Hex only sends the paste keystroke. It never sees your screen.") }; let allow = |label: &str, primary: bool| { Button::new(label) .variant(if primary { ButtonVariant::Contrast } else { ButtonVariant::Neutral }) .on_press(super::live::allow_paste) .build_push(k) .key("paste-pill-allow") .transition(arrives()) }; let control = match paste { PasteAccess::Ask | PasteAccess::Later => allow(tr("Allow"), true), PasteAccess::Asking => perm_pill(p, "paste-pill", PermState::Asking), PasteAccess::Allowed => perm_pill(p, "paste-pill", PermState::Allowed), PasteAccess::Declined => allow(tr("Try again"), false), }; let card = card(p).child(perm_row( p, "paste-row", &glyphs::CURSOR_TEXT, tr("Paste into apps"), desc, control, )); let action = if paste == PasteAccess::Declined { Button::new(tr("Continue")) .variant(ButtonVariant::Contrast) .on_press(super::live::paste_later) .build_push(k) .key("paste-later") .transition(arrives()) } else { el().key("none") }; col() .key("permissions") .gap(22.0) .items_center() .child(motion.heading( col() .key("permissions-head") .gap(8.0) .items_center() .child( text(tr("Let Hex paste for you")) .key("title") .font(title_font(p)) .color(p.text()), ) .child( text(tr("Hex needs this to type your words into your apps. Your desktop asks once, and may call it remote desktop.")) .key("lead") .font(LEAD) .color(p.muted()) .align(rune::Align::Center) .wrap() .w(COL_W), ), )) .child(motion.staggered(k.elevate(card, &k.elevation.raised), 1.0, 8.0)) .child(row().key("action").h(ACTION_H).center().child(action)) } fn live_pill( p: Paint, key: &str, live: &Live, status: ItemStatus, primary: bool, item: SetupItem, ) -> El { let k = p.k; let allow = |label: &str, primary: bool| { Button::new(label) .variant(if primary { ButtonVariant::Contrast } else { ButtonVariant::Neutral }) .on_press(super::live::allow(item)) .build_push(k) .key(format!("{key}-allow")) .transition(arrives()) }; let settings = if live.accessibility_row { tr("Open System Settings") } else { tr("Open Settings") }; match status { ItemStatus::Ready => perm_pill(p, key, PermState::Allowed), ItemStatus::Todo => allow(tr("Allow"), primary), ItemStatus::Denied => allow(settings, primary), // Pressing again reopens the prompt or Settings. ItemStatus::Waiting => allow(tr("Open"), false), ItemStatus::Stale => allow(tr("Still grey? Fix it"), false), ItemStatus::Restart => row() .key(format!("{key}-restart")) .h(28.0) .px(6.0) .center_y() .transition(arrives()) .child( text(tr("Needs a restart")) .key("lbl") .font(k.ty.small_medium) .color(p.muted()), ), ItemStatus::Downloading(_) | ItemStatus::Failed => el().key(format!("{key}-none")), } } fn stage(p: Paint, e: f64, mic: PermState, ax: PermState, reduced: bool) -> El { let tray_open = (AX_TRAY_OPEN..SETTINGS_CLOSE).contains(&e); let escaped = e >= AX_ESCAPE; let settings_open = (AX_ESCAPE..SETTINGS_CLOSE).contains(&e); let mut stage = el().key("permissions-stage").size(COL_W, STAGE_H); // 1. Hex's own permissions card at the top of the `440 pt` column. stage = stage.child(float_off( setup_card(p, mic, ax, tray_open, escaped), float_u(e, AX_FLOAT), reduced, )); // 2. System Settings (`Privacy & Security › Accessibility`). if settings_open { stage = stage.child( settings_window(p, e, reduced) .absolute(0.0, SETTINGS_Y) .transition(arrives()), ); } // 3. The Accessibility helper panel: sits inside Hex's card at `AX_TRAY_OPEN`, // then escapes out of the card at `AX_ESCAPE` and floats down to dock // underneath System Settings (`GUIDE_Y`), then launches the drag row! if tray_open { stage = stage.child(escaping_guide_and_drag(p, e, reduced)); } stage } fn setup_card(p: Paint, mic: PermState, ax: PermState, tray_open: bool, escaped: bool) -> El { let k = p.k; let ax_desc = if ax == PermState::Asking { "Drag Hex into System Settings below" } else { "Notices the shortcut and pastes your words" }; let mut card = col() .key("setup-card") .absolute(0.0, 0.0) .w(COL_W) .radius(k.radius.lg) .fill(k.c.bg_base) .border(p.hair, k.c.border_weak) .motion(Spring::new(0.30, 0.0)) .child(perm_row( p, "mic-row", &glyphs::MIC, "Microphone", "Hears you while you hold the shortcut", perm_pill(p, "mic-pill", mic), )) .child(separator(p, "sep0")) .child(perm_row( p, "ax-row", &glyphs::CURSOR_TEXT, "Accessibility", ax_desc, perm_pill(p, "ax-pill", ax), )); if tray_open { card = card.child( el().key("escape-socket-tray") .w(COL_W) .h(SOCKET_TRAY_H) .transition(Transition::opacity()) .child(socket_outline(p, escaped)), ); } k.elevate(card, &k.elevation.raised) } /// Recessed outline left behind inside Hex's card once the helper panel escapes. fn socket_outline(p: Paint, escaped: bool) -> El { let k = p.k; row() .key("socket-outline") .absolute(12.0, 5.0) .size(COL_W - 24.0, 38.0) .px(12.0) .center_y() .justify_between() .radius(8.0) .fill(k.c.bg_deep.mix(k.c.bg_base, 0.45)) .border(p.hair, k.c.border_base) .children(escaped.then(|| { text("Floating beside System Settings") .key("escaped-note") .font(k.ty.small) .color(p.faint()) .transition(Transition::opacity()) })) } /// Hex's setup card in the first run's column: the permissions, and the /// model step's found models. pub(super) fn card(p: Paint) -> El { let k = p.k; col() .key("setup-card") .w(COL_W) .radius(k.radius.lg) .fill(k.c.bg_base) .border(p.hair, k.c.border_weak) } pub(super) fn separator(p: Paint, key: &str) -> El { el().key(key).h(p.hair).mx(16.0).fill(p.k.c.border_muted) } fn perm_row( p: Paint, key: &str, glyph: &'static rune::Icon, title: &str, desc: &str, control: El, ) -> El { let k = p.k; // Longer copy (Windows' switch, other languages) wraps in the row. row() .key(key) .min_h(ROW_H) .py(8.0) .px(16.0) .gap(12.0) .center_y() .child(icon(glyph, 16.0).key("icon").color(k.c.icon_base)) .child( col() .key("copy") .grow(1.0) .w(0.0) .gap(2.0) .child( text(title) .key("title") .font(k.ty.ui_medium) .color(p.text()), ) .child( text(desc) .key("desc") .font(k.ty.small) .color(p.muted()) .wrap(), ), ) .child(control) } /// Calm, zero-bounce permission control: no frantic blinking dot or spring bounce. fn perm_pill(p: Paint, key: &str, state: PermState) -> El { let k = p.k; match state { PermState::Allow { primary } => Button::new("Allow") .variant(if primary { ButtonVariant::Contrast } else { ButtonVariant::Neutral }) .on_press(|_: &mut Onboard| {}) .build_push(k) .key(format!("{key}-allow")) .transition(arrives()), PermState::Asking => row() .key(format!("{key}-asking")) .h(28.0) .px(10.0) .gap(6.0) .center_y() .radius(k.radius.md) .fill(k.c.surface_raised) .border(p.hair, k.c.border_weak) .transition(arrives()) .child( el().key("dot") .size(6.0, 6.0) .radius(3.0) .fill(p.k.c.icon_muted), ) .child( text("Open") .key("lbl") .font(k.ty.small_medium) .color(p.muted()), ), PermState::Allowed => row() .key(format!("{key}-allowed")) .h(28.0) .px(6.0) .gap(5.0) .center_y() .transition(arrives()) .child( icon(k.glyph.check_small, 16.0) .key("check") .color(p.success()), ) .child( text("Allowed") .key("lbl") .font(k.ty.ui_medium) .color(p.success()), ), } } fn microphone_prompt(p: Paint, pressed: bool) -> El { let k = p.k; let button = |key: &str, label: &str, variant: ButtonVariant| { Button::new(label) .variant(variant) .on_press(|_: &mut Onboard| {}) .build_push(k) .key(key.to_string()) .grow(1.0) }; let badge = el() .key("app-badge") .size(40.0, 40.0) .radius(10.0) .continuous_corners() .center() .fill(k.c.surface_raised) .border(p.hair, k.c.border_weak) .child(hex_meter(p, "icon", 22.0, 1.0, 1.0)); let alert = col() .key("mic-prompt") .w(PROMPT_W) .padding(18.0) .gap(10.0) .items_center() .radius(18.0) .continuous_corners() .fill(k.c.bg_base) .border(p.hair, k.c.border_weak) .child(badge) .child( text("“Hex” would like to access the microphone.") .key("title") .font(TextStyle { weight: if k.dark { 560.0 } else { 600.0 }, ..k.ty.ui_medium }) .color(p.text()) .align(rune::Align::Center) .wrap() .w(PROMPT_W - 36.0), ) .child( text("Hex listens only while you hold your shortcut.") .key("body") .font(k.ty.small) .color(p.muted()) .align(rune::Align::Center) .wrap() .w(PROMPT_W - 36.0), ) .child( row() .key("buttons") .w_full() .gap(8.0) .pt(4.0) .child(button("deny", "Don't Allow", ButtonVariant::Neutral)) .child( button("allow", "Allow", ButtonVariant::Contrast) .scale(if pressed { 0.96 } else { 1.0 }) .opacity(if pressed { 0.84 } else { 1.0 }) .motion(Spring::new(0.12, 0.0)), ), ); k.elevate(alert, &k.elevation.floating) } /// System Settings' Accessibility pane (`w = 440 pt`), with its app icons at /// `x = 26 pt` (`LIST_INSET + ROW_PX`). fn settings_window(p: Paint, e: f64, reduced: bool) -> El { let k = p.k; let dark = k.dark; let drag_u = drag_progress(e, reduced); let slot_open = drag_u.is_some_and(|u| u >= 0.42) || e >= DRAG.1; let landed = e >= DRAG.1; let dot = |key: &str, color: Color| { el().key(key.to_string()) .size(9.0, 9.0) .radius(4.5) .fill(color) }; let bar = row() .key("title-bar") .absolute(0.0, 0.0) .w(COL_W) .h(28.0) .px(14.0) .gap(6.0) .center_y() .child(dot("close", rune_theme_opencode::ember(dark, 9))) .child(dot( "minimize", rune_theme_opencode::scale("amber", dark, 9), )) .child(dot("zoom", rune_theme_opencode::scale("apple", dark, 9))) .child( text("Privacy & Security › Accessibility") .key("title") .font(k.ty.small_medium) .color(p.muted()) .pl(10.0), ); let mut list = col() .key("list") .absolute(LIST_INSET, LIST_Y) .w(LIST_W) .radius(8.0) .clip_rounded(8.0) .fill(k.c.surface_raised) .border(p.hair, k.c.border_weak) .motion(Spring::new(0.26, 0.0)) .child(settings_app_row( p, "raycast", "Raycast", squircle_icon(rune_theme_opencode::ember(dark, 9)), true, )) .child( el().key("lsep0") .h(p.hair) .mx(ROW_PX) .fill(k.c.border_muted), ) .child(settings_app_row( p, "rectangle", "Rectangle", squircle_icon(rune_theme_opencode::scale("cobalt", dark, 9)), true, )); if slot_open { list = list.child( el().key("lsep1") .h(p.hair) .mx(ROW_PX) .fill(k.c.border_muted), ); if landed { list = list.child( settings_app_row(p, "hex-landed", "Hex", hex_app_icon(p), e >= SWITCH_ON) .transition(Transition::opacity()), ); } else { // Subtle drop-target highlight waiting to catch the dragged Hex row. list = list.child( row() .key("drop-slot") .h(LIST_ROW_H) .px(ROW_PX) .center_y() .fill(k.c.bg_deep.mix(k.c.surface_raised, 0.5)) .border(p.hair, k.c.border_focus), ); } } let win = el() .key("settings-window") .size(COL_W, SETTINGS_H) .radius(12.0) .continuous_corners() .fill(k.c.bg_base) .border(p.hair, k.c.border_weak) .child(bar) .child( text("Allow the applications below to control your computer.") .key("explain") .font(k.ty.small) .color(p.muted()) .absolute(LIST_INSET, 31.0), ) .child(list); k.elevate(win, &k.elevation.floating) } /// The panel that sits inside Hex's card, detaches at `AX_ESCAPE` leaving an /// outline behind, floats down underneath System Settings, and then launches /// the `Hex` drag row straight up the `x = 26 pt` spine into the list. fn escaping_guide_and_drag(p: Paint, e: f64, reduced: bool) -> El { let k = p.k; let esc_u = if e < AX_ESCAPE { 0.0 } else if reduced { 1.0 } else { smoothstep(((e - AX_ESCAPE) / (AX_DOCKED - AX_ESCAPE)) as f32) }; let x = lerp(SOCKET_RECT[0], 0.0, esc_u); let y = lerp(SOCKET_RECT[1], GUIDE_Y, esc_u) - 8.0 * (esc_u * std::f32::consts::PI).sin(); let w = lerp(SOCKET_RECT[2], COL_W, esc_u); let h = lerp(SOCKET_RECT[3], GUIDE_H, esc_u); let lift_scale = 1.0 + 0.025 * (esc_u * std::f32::consts::PI).sin(); let tilt = -0.018 * (esc_u * std::f32::consts::PI).sin(); let drag_u = drag_progress(e, reduced); let tile_taken = drag_u.is_some() || e >= DRAG.1; // Inside the panel: `tile_x` moves from `4` (at `x = 12`, putting the icon // at `12 + 4 + 10 = 26`) to `16` (at `x = 0`, putting the icon at `0 + 16 + 10 = 26`)! let tile_x = lerp(4.0, LIST_INSET, esc_u); let tile_y = lerp(4.0, 30.0, esc_u); let tile_w = LIST_W; let instruction = (esc_u > 0.35).then(|| { text("↑ Drag Hex into the Accessibility list above") .key("guide-instruction") .font(k.ty.small_medium) .color(p.text()) .absolute(LIST_INSET, 8.0) .opacity(((esc_u - 0.35) / 0.45).clamp(0.0, 1.0)) .opacity_motion(Anim::INSTANT) }); // When `tile_taken`, ONLY the empty recessed slot remains — zero duplicate // ghost `"Hex"` text underneath the lifted chip! let inner_slot = if tile_taken { el().key("guide-tile-empty") .absolute(tile_x, tile_y) .size(tile_w, 30.0) .radius(7.0) .fill(k.c.bg_deep.mix(k.c.bg_base, 0.5)) .border(p.hair, k.c.border_weak) } else { row() .key("guide-tile") .absolute(tile_x, tile_y) .size(tile_w, 30.0) .px(ROW_PX) .gap(8.0) .center_y() .radius(7.0) .fill(k.c.surface_raised) .border(p.hair, k.c.border_base) .offset_motion(Anim::INSTANT) .child(hex_app_icon(p)) .child( text("Hex") .key("name") .font(k.ty.small_medium) .color(p.text()), ) .child(el().key("sp").grow(1.0)) // It fades as the panel starts to escape rather than dropping // out in one frame; it sits last, so nothing moves into its place. .children((esc_u < 0.25).then(|| { text("Accessibility helper") .key("sub") .font(k.ty.small) .color(p.faint()) .opacity(1.0 - smoothstep(esc_u / 0.25)) .opacity_motion(Anim::INSTANT) })) }; let mut panel = el() .key("escaping-panel") .absolute(x, y) .size(w, h) .radius(lerp(8.0, 12.0, esc_u)) .continuous_corners() .fill(if esc_u < 0.05 { k.c.surface_raised } else { k.c.bg_base }) .border( p.hair, if esc_u > 0.05 && esc_u < 0.98 { k.c.border_focus } else { k.c.border_weak }, ) .scale(lift_scale) .rotate(tilt) .offset_motion(Anim::INSTANT) .rotate_motion(Anim::INSTANT) .children(instruction) .child(inner_slot); if esc_u > 0.02 { panel = k.elevate(panel, &k.elevation.floating); } let mut layer = el() .key("escape-layer") .absolute(0.0, 0.0) .size(COL_W, STAGE_H) .instant_changes() .transition(Transition::opacity()) .child(panel); if let Some(u) = drag_u { layer = layer.child(dragged_row(p, u)); } layer } fn drag_progress(e: f64, reduced: bool) -> Option { if reduced || !(DRAG.0..DRAG.1).contains(&e) { return None; } Some(smoothstep(((e - DRAG.0) / (DRAG.1 - DRAG.0)) as f32)) } /// The lifted `Hex` row travelling up the `x = 26 pt` icon spine from the /// docked guide into Row 3 of System Settings' Accessibility list. fn dragged_row(p: Paint, u: f32) -> El { let k = p.k; let from_y = GUIDE_Y + 30.0; let to_y = SETTINGS_Y + LIST_Y + 2.0 * LIST_ROW_H + 2.0 * p.hair; let y = lerp(from_y, to_y, u) - 8.0 * (u * std::f32::consts::PI).sin(); let lift = 1.0 + 0.03 * (u * std::f32::consts::PI).sin(); let chip = row() .key("drag-chip") .absolute(LIST_INSET, y) .size(LIST_W, LIST_ROW_H) .px(ROW_PX) .gap(8.0) .center_y() .radius(7.0) .fill(k.c.surface_raised) .border(p.hair, k.c.border_focus) .scale(lift) .offset_motion(Anim::INSTANT) .child(hex_app_icon(p)) .child( text("Hex") .key("name") .font(k.ty.small_medium) .color(p.text()), ); k.elevate(chip, &k.elevation.floating) } fn squircle_icon(color: Color) -> El { el().key("icon") .size(18.0, 18.0) .radius(4.5) .continuous_corners() .fill(color) } fn hex_app_icon(p: Paint) -> El { el().key("hex-app-icon") .size(18.0, 18.0) .radius(4.5) .continuous_corners() .center() .fill(p.k.c.bg_deep) .border(p.hair, p.k.c.border_base) .child(hex_meter(p, "hex", 12.0, 1.0, 1.0)) } fn settings_app_row(p: Paint, key: &str, name: &str, icon: El, on: bool) -> El { let k = p.k; row() .key(key.to_string()) .h(LIST_ROW_H) .px(ROW_PX) .gap(8.0) .center_y() .child(icon) .child( text(name) .key("name") .font(k.ty.small) .color(p.text()) .grow(1.0), ) .child(macos_switch(p, on)) } fn macos_switch(p: Paint, on: bool) -> El { let k = p.k; let knob = el() .key("knob") .absolute(if on { 12.5 } else { 1.5 }, 1.5) .size(12.0, 12.0) .radius(6.0) .fill(k.c.white) .motion(Spring::new(0.22, 0.0)); el().key("switch") .size(26.0, 15.0) .radius(7.5) .fill(if on { p.accent() } else { k.c.border_base }) .child(knob) } #[cfg(test)] mod tests { use super::*; #[test] fn each_permission_asks_then_is_granted_in_order() { assert_eq!( state_at(0.0, MIC_ASK, MIC_GRANT, true), PermState::Allow { primary: true } ); assert_eq!(state_at(1.2, MIC_ASK, MIC_GRANT, true), PermState::Asking); assert_eq!(state_at(2.5, MIC_ASK, MIC_GRANT, true), PermState::Allowed); const { assert!(MIC_GRANT < AX_ESCAPE && AX_DOCKED < DRAG.0 && DRAG.1 < AX_GRANT) }; const { assert!(AX_GRANT < CONTINUE_AT && CONTINUE_AT < PERMISSIONS_SECS) }; } #[test] fn settings_list_and_docked_guide_share_one_icon_spine() { let settings_icon_x = LIST_INSET + ROW_PX; let docked_guide_icon_x = 0.0 + LIST_INSET + ROW_PX; assert_eq!(settings_icon_x, 26.0); assert_eq!(settings_icon_x, docked_guide_icon_x); const { assert!(GUIDE_Y + GUIDE_H <= STAGE_H) }; } }