//! Shared typography, motion transitions, and the `"Hex is ready"` finale. use rune::{El, Spring, SpringPair, TextStyle, Transition, col, el, row, text}; use rune_kit::{Button, ButtonVariant}; use crate::desktop::i18n::tr; use super::super::controls::{KeySize, Paint, PushSize, key_tray, keycap}; use super::fixture::Language; use super::hex_meter::{hex_logo, hex_meter}; use super::pill::{FLY, PILL}; /// One display heading style across every onboarding step (`26 pt`, softened /// weight in dark mode so light ink on dark doesn't bloom). pub(crate) const TITLE: TextStyle = TextStyle::new(26.0, 580.0).lh(32.0).tracking(-0.35); pub(crate) fn title_font(p: Paint) -> TextStyle { TextStyle { weight: if p.k.dark { 550.0 } else { 600.0 }, ..TITLE } } /// Subtitle line under every step's heading. pub(crate) const LEAD: TextStyle = TextStyle::new(15.0, 410.0).lh(22.0); /// Product UI spring: `0.30 s`, zero bounce. pub(crate) const UI_SPRING: Spring = Spring::new(0.30, 0.0); const EXIT_SPRING: Spring = Spring::new(0.25, 0.0); /// The story's live motion controls. The real first run uses the same defaults. #[derive(Clone, Copy)] pub(crate) struct Motion { pub enter: f32, pub exit: f32, pub travel: f32, pub stagger: f32, pub keyboard: f32, } impl Default for Motion { fn default() -> Self { Self { enter: 0.34, exit: 0.26, travel: 8.0, stagger: 0.05, keyboard: 0.65, } } } impl Motion { pub fn roll(self, distance: f32) -> Transition { let fade = |y| Transition::offset(0.0, y).combined(Transition::opacity()); Transition::asymmetric(fade(distance), fade(-distance)).springs(SpringPair::new( Spring::new(self.enter, 0.0), Spring::new(self.exit, 0.0), )) } pub fn heading(self, child: El) -> El { child.transition(self.roll(self.travel)) } pub fn staggered(self, child: El, rank: f32, distance: f32) -> El { child .transition(self.roll(distance)) .enter_delay(rank * self.stagger) } /// One critically damped progress value for a clock-driven pose. pub fn keyboard_progress(self, elapsed: f64) -> f32 { Spring::new(self.keyboard, 0.0) .sample(0.0, 0.0, 1.0, elapsed.max(0.0) as f32) .0 } } /// Whole-state replacement in place, with a slightly shorter exit. pub(crate) fn arrives() -> Transition { Transition::scale(0.97) .combined(Transition::opacity()) .springs(SpringPair::new(UI_SPRING, EXIT_SPRING)) } /// Incoming words rise as outgoing words lift away, on one presence spring. pub(crate) fn step_replace() -> Transition { Motion::default().roll(Motion::default().travel) } /// A heading and the line under it, centred on the column spine. pub(crate) fn heading(p: Paint, key: &str, title: &str, lead: &str) -> El { col() .key(key) .gap(8.0) .items_center() .transition(step_replace()) .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) .wrap() .max_w(440.0), ) } /// Download English, or pick another language (used by the older option stories). pub(crate) fn language_pick(p: Paint, pick: fn(&mut S, Language)) -> El { row() .key("language-pick") .gap(10.0) .center_y() .child( Button::new("Download English") .variant(ButtonVariant::Contrast) .on_press(move |s: &mut S| pick(s, Language::English)) .build_push(p.k) .key(PILL) .matched(PILL) .motion(FLY) .default_button(), ) .child( Button::new("Other language") .variant(ButtonVariant::Neutral) .on_press(move |s: &mut S| pick(s, Language::Other)) .build_push(p.k) .key("other"), ) } /// The shortcut's keys in a recessed tray, `down` while held. pub(crate) fn keys(p: Paint, key: &str, caps: &[String], down: bool) -> El { key_tray( p, key, KeySize::Small, caps.iter() .enumerate() .map(|(i, cap)| keycap(p, i, cap, KeySize::Small, down)), ) } /// Where Hex lives once onboarding closes, under `"Hex is ready"`. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) enum Home { MenuBar, Tray, Launcher, } impl Home { fn copy(self) -> &'static str { match self { Self::MenuBar => tr("Lives quietly in your menu bar"), Self::Tray => tr("Lives quietly in your system tray"), Self::Launcher => tr("Open it again from your app launcher"), } } /// The launch-at-login ask's question: the Mac's own words on a Mac, and /// the computer's elsewhere. pub(super) fn ask_question(self) -> &'static str { match self { Self::MenuBar => tr("Open Hex when your Mac starts?"), Self::Tray | Self::Launcher => tr("Open Hex when your computer starts?"), } } /// The ask once the login item is on. pub(super) fn ask_started(self) -> &'static str { match self { Self::MenuBar => tr("Hex opens when your Mac starts."), Self::Tray | Self::Launcher => tr("Hex opens when your computer starts."), } } /// The ask's line under the button: tiny, and asleep where Hex lives. pub(super) fn ask_nap(self, toggle: bool) -> &'static str { match (self, toggle) { (Self::MenuBar, true) => { tr("It's tiny. It naps in your menu bar until you tap the key.") } (Self::MenuBar, false) => { tr("It's tiny. It naps in your menu bar until you hold the key.") } (Self::Tray, true) => { tr("It's tiny. It naps in your system tray until you tap the key.") } (Self::Tray, false) => { tr("It's tiny. It naps in your system tray until you hold the key.") } (Self::Launcher, true) => { tr("It's tiny. It naps in the background until you tap the key.") } (Self::Launcher, false) => { tr("It's tiny. It naps in the background until you hold the key.") } } } } /// Final `"Hex is ready"` landing: the Hex logo builds outside in (its /// outline arriving from the top pill when `matched`), followed by /// staggered copy and where Hex lives. `age`: seconds since the page /// appeared; `toggle`: the shortcut taps to start rather than holds. #[allow(clippy::too_many_arguments)] pub(crate) fn ready( p: Paint, caps: &[String], toggle: bool, matched: Option<&str>, age: f64, reduced: bool, motion: Motion, home: Home, ) -> El { let mark = hex_logo(p, "meter", 64.0, age, reduced, matched.is_some()); let mark = match matched { Some(id) => el().key(id).matched(id).motion(FLY).child(mark), None => motion.staggered(mark.key("mark"), 0.0, 8.0), }; col() .key("ready") .gap(24.0) .items_center() .child(mark) .child( motion.staggered( col() .key("ready-copy") .gap(10.0) .items_center() .child( text(tr("Hex is ready")) .key("title") .font(title_font(p)) .color(p.text()), ) .child(hold_anywhere(p, caps, toggle)), 1.0, 8.0, ), ) .child(motion.staggered(menubar_hint(p, home), 2.0, 8.0)) } /// `"Hold [⌥] anywhere, then talk."`, or `"Tap"` when the shortcut taps. pub(crate) fn hold_anywhere(p: Paint, caps: &[String], toggle: bool) -> El { let sentence = if toggle { tr("Tap {keys} anywhere, then talk.") } else { tr("Hold {keys} anywhere, then talk.") }; row() .key("hold-anywhere") .gap(8.0) .center_y() .children(around_keys( sentence, keys(p, "keys", caps, false), |words| text(words).font(LEAD).color(p.muted()), )) } /// A translated sentence with the shortcut's keycap `tray` where its /// `{keys}` is, so each language puts the keys where its grammar wants /// them: the words before (`"before"`), the tray, and the words after /// (`"after"`), each side left out when the sentence has none. pub(crate) fn around_keys(sentence: &str, tray: El, words: impl Fn(&str) -> El) -> Vec { let (before, after) = sentence.split_once("{keys}").unwrap_or((sentence, "")); let side = |copy: &str, key: &str| { let copy = copy.trim(); (!copy.is_empty()).then(|| words(copy).key(key)) }; side(before, "before") .into_iter() .chain(Some(tray)) .chain(side(after, "after")) .collect() } /// Quiet capsule previewing the single-hexagon icon where Hex lives: the /// macOS menu bar, the Windows tray, or the Linux app launcher. fn menubar_hint(p: Paint, home: Home) -> El { let k = p.k; let strip = row() .key("menubar-pill") .h(30.0) .px(12.0) .gap(10.0) .center_y() .radius(15.0) .fill(k.c.surface_raised) .border(p.hair, k.c.border_weak) .child(hex_meter(p, "menubar-hex", 14.0, 1.0, 1.0)) .child(el().key("sep").size(p.hair, 12.0).fill(k.c.border_base)) .child( text(home.copy()) .key("menubar-copy") .font(k.ty.small) .color(p.muted()), ); k.elevate(strip, &k.elevation.raised) }