diff --git a/Cargo.lock b/Cargo.lock index 7da098a..2226ce9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4246,6 +4246,8 @@ dependencies = [ name = "tempo-ui" version = "0.5.0" dependencies = [ + "libloading", + "roxmltree", "slint", ] diff --git a/Cargo.toml b/Cargo.toml index 4a34f5c..ececf9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,10 +25,14 @@ publish = false [features] default = [] -cjk-font-fallback = ["dep:slint"] +cjk-font-fallback = ["dep:slint", "dep:libloading", "dep:roxmltree"] [dependencies] slint = { workspace = true, optional = true, features = ["std", "unstable-fontique-012", "compat-1-2"] } +[target.'cfg(target_os = "android")'.dependencies] +libloading = { version = "0.8", optional = true } +roxmltree = { version = "0.21", optional = true } + [profile.dev] debug = 0 diff --git a/README.md b/README.md index 5cabc38..c1ab3e8 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ - **Restrained Geometry & Soft Layered Surfaces**: Compact `4px / 6px / 8px / 10px` radii and crisp hairline borders. Both light and dark themes avoid harsh pure white (`#FFFFFF`) and pure black (`#000000`), separating canvas, navigation rail, cards, and elevated overlays cleanly. - **Unified Desktop & Mobile Adaptation**: `TempoNavigationShell` seamlessly adapts between an expanded desktop sidebar, a compact navigation rail (with bottom-pinned unified `footer-destinations`), and a mobile bottom bar. `TempoToastHost` renders as a top-right notification card on desktop and a compact bottom bar on mobile; pickers and `TempoTransfer` automatically adapt to narrow viewports. - **Cohesive Motion System**: Standardized decelerated easing across transitions, drawers, dialogs, dropdowns, and sliding controls, with `TempoRouteTransition` (`none` / `fade-through` / `shared-axis-x` / `shared-axis-y`) and global `TempoMotionSettings.reduced` support. -- **Cross-Platform CJK Font Fallbacks**: Built-in `tempo_ui::fonts::configure_cjk_fallbacks()` configures locale-aware Simplified/Traditional Chinese, Japanese, and Korean fallback chains plus `GenericFamily::SansSerif` for Slint/fontique across Linux, Windows, macOS, and Android. +- **System Fonts and CJK Fallbacks**: Follow Android and Linux desktop font preferences, with missing-glyph fallbacks for Simplified and Traditional Chinese, Japanese, and Korean. ### Dark Theme & Mobile Layouts @@ -66,16 +66,20 @@ fn main() { } ``` -Enable CJK font fallbacks before constructing your Slint window (with the `cjk-font-fallback` feature): +Enable the `cjk-font-fallback` feature and configure fonts on the UI thread before initializing Slint: ```rust fn main() -> Result<(), Box> { - tempo_ui::fonts::configure_cjk_fallbacks()?; + tempo_ui::fonts::configure_system_fonts()?; // Create and run your Slint window... Ok(()) } ``` +On Android, call this inside `android_main` **before** `slint::android::init(app)` (or before `slint::platform::set_platform(...)` when setting up the backend manually). TempoUI uses the Android 10+ system matcher and also follows a readable vendor font redirect when the ROM exposes one. If neither is available, it falls back to discoverable system fonts. On Linux, TempoUI reads the KDE or supported GNOME-family desktop preference when available, and otherwise uses Fontconfig. + +The choice is read at startup. To override it, set `TEMPO_UI_FONT_FAMILY` to an installed family or `SLINT_DEFAULT_FONT` to a readable font file before launch. A window's explicit `default-font-family` or a control's `font-family` still takes precedence. Existing calls to `configure_cjk_fallbacks()` get the same behavior. + Import components directly in `.slint`: ```slint @@ -94,6 +98,29 @@ export component App inherits Window { } ``` +### Mobile safe area + +Use `TempoWindow` to read the live system insets and pass them to the top-level layout. + +```slint +import { TempoWindow, TempoSafeArea } from "@tempo-ui"; + +export component App inherits TempoWindow { + TempoSafeArea { + insets: root.content-insets; + Text { text: "Hello Tempo UI"; } + } +} +``` + +Use either this wrapper for standalone content or `insets: root.content-insets;` on a top-level `TempoNavigationShell`. Do not inset both. For explicitly sized children, use the wrapper’s `content-width` and `content-height`. The window background stays full-bleed and the insets are normally zero on desktop. + +### Mobile navigation and rendering + +Wrap the window content in `TempoBackHandler`, forward the window’s focus to it, and handle `go-back` with your route stack. Return `false` at the root to allow the platform’s default action. Keep modal focus in the popup so it closes first. + +Mobile defaults to `TempoMotionSettings.lightweight`: sheets, dialogs, toasts and route changes retain short transitions without animating full-window opacity. Android typography uses the system font scale via `TempoTokens.text-scale(1rem)`; desktop font sizes are unchanged. + ## Verification ```sh diff --git a/README.zh-CN.md b/README.zh-CN.md index 49d17c7..381e88c 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -11,7 +11,7 @@ - **克制圆角与柔和配色**:采用 `4px / 6px / 8px / 10px` 克制圆角与清晰 `1px` 描边;亮/暗两套主题均避免刺眼的纯白(`#FFFFFF`)与纯黑(`#000000`),通过画布、侧边栏、卡片与浮层四级表面色自然拉开空间层次。 - **桌面与移动一体化适配**:`TempoNavigationShell` 自动在桌面展开侧边栏、窄 Rail(含贴底统一页面切换的 `footer-destinations`)与移动端底部导航栏之间切换;`TempoToastHost` 在桌面端以右上角通知卡片展示,在移动端以底部居中紧凑条展示;`TempoTransfer`、`TempoDatePicker`、`TempoTimePicker` 均内置窄屏布局与视口边界防溢出。 - **统一动效体系**:全库统一使用快速响应、平滑落位的减速缓动曲线,提供 `TempoRouteTransition`(`none` / `fade-through` / `shared-axis-x` / `shared-axis-y`)及全局 `TempoMotionSettings.reduced` 减弱动态开关。 -- **跨平台 CJK 字体回退**:内置 `tempo_ui::fonts::configure_cjk_fallbacks()`,为 Slint/fontique 补全简体/繁体中文、日文、韩文的多区域与通用无衬线回退链,解决 Linux / Windows / macOS / Android 上的汉字豆腐块与混排错字问题。 +- **跟随系统字体与 CJK 回退**:支持 Android 和 Linux 桌面选择的系统界面字体,遇到缺字时保留简繁中文、日文和韩文回退。 ### 暗色桌面与移动端布局 @@ -66,16 +66,20 @@ fn main() { } ``` -在 `main.rs` 创建窗口前启用 CJK 字体回退(开启 `cjk-font-fallback` feature): +开启 `cjk-font-fallback` feature,在 UI 线程初始化 Slint 之前配置字体: ```rust fn main() -> Result<(), Box> { - tempo_ui::fonts::configure_cjk_fallbacks()?; + tempo_ui::fonts::configure_system_fonts()?; // 创建并运行 Slint 窗口... Ok(()) } ``` +Android 应在 `android_main` 中、`slint::android::init(app)` 之前调用。手动设置后端时,请在 `slint::platform::set_platform(...)` 之前调用。TempoUI 会使用 Android 10 及以上的系统匹配器,也会识别 ROM 公开的、可读取的自定义字体重定向。读不到设置时会回退到可发现的系统字体。Linux 会读取 KDE 或支持的 GNOME 系桌面配置,读不到时回退到 Fontconfig。 + +字体在启动时读取。需要手动指定时,可以在启动前将 `TEMPO_UI_FONT_FAMILY` 设为已安装的字体族,或将 `SLINT_DEFAULT_FONT` 设为可读取的字体文件路径。窗口显式设置的 `default-font-family` 或控件的 `font-family` 仍然优先。已有的 `configure_cjk_fallbacks()` 调用也会自动使用这套逻辑。 + 在 `.slint` 中直接导入组件: ```slint @@ -94,6 +98,29 @@ export component App inherits Window { } ``` +### 移动端安全区 + +用 `TempoWindow` 读取实时系统安全区,并传给最外层布局。 + +```slint +import { TempoWindow, TempoSafeArea } from "@tempo-ui"; + +export component App inherits TempoWindow { + TempoSafeArea { + insets: root.content-insets; + Text { text: "Hello Tempo UI"; } + } +} +``` + +独立页面用这一层包装;如果最外层是 `TempoNavigationShell`,直接设置 `insets: root.content-insets;`,不要重复套用。子组件如需显式设置尺寸,请绑定安全区容器的 `content-width` 和 `content-height`。背景仍可铺到边缘,桌面端安全区通常为零。 + +### 移动端返回与渲染 + +用 `TempoBackHandler` 包住窗口内容,把窗口焦点转给它,在 `go-back` 中处理路由退栈。到根页时返回 `false`,交给系统默认处理。弹窗保留自己的焦点,可优先关闭。 + +移动端默认使用 `TempoMotionSettings.lightweight`,底部面板、弹窗、提示条和页面切换仍有短过渡,但不对整窗做透明度动画。Android 字体通过 `TempoTokens.text-scale(1rem)` 跟随系统字号,桌面字号保持不变。 + ## 验证与测试 ```sh diff --git a/examples/showcase/src/main.rs b/examples/showcase/src/main.rs index 05cf637..13cba0f 100644 --- a/examples/showcase/src/main.rs +++ b/examples/showcase/src/main.rs @@ -48,7 +48,7 @@ fn options() -> Result { "--smoke" => options.smoke = true, "--help" | "-h" => { println!( - "tempo-ui-showcase [--compact] [--dark] [--layout|--lists] [--wide] [--screenshot PATH] [--smoke|--motion-smoke]" + "tempo-ui-showcase [--compact] [--dark] [--layout|--lists] [--wide] [--screenshot PATH] [--smoke|--motion-smoke|--lightweight-smoke]" ); std::process::exit(0); } @@ -312,17 +312,39 @@ fn catalog_smoke_start( return Err("tab marker or localized refresh strings did not resolve".into()); } let original_origin = ui.get_heading_origin(); - ui.set_extra_insets(TempoInsets { + let original_safe_origin = ui.get_safe_area_origin(); + let original_safe_width = ui.get_safe_area_width(); + let original_safe_height = ui.get_safe_area_height(); + ui.set_test_insets(TempoInsets { top: 21.0, left: 10.0, right: 9.0, bottom: 18.0, }); let safe_origin = ui.get_heading_origin(); - if (safe_origin.y - original_origin.y - 21.0).abs() > 1.0 { - return Err("heading was not padded by the injected safe area".into()); + let area_origin = ui.get_safe_area_origin(); + if (safe_origin.y - original_origin.y - 21.0).abs() > 1.0 + || (area_origin.x - original_safe_origin.x - 10.0).abs() > 1.0 + || (area_origin.y - original_safe_origin.y - 21.0).abs() > 1.0 + || (original_safe_width - ui.get_safe_area_width() - 19.0).abs() > 1.0 + || (original_safe_height - ui.get_safe_area_height() - 39.0).abs() > 1.0 + { + return Err(format!( + "safe area did not update: heading y {} -> {}, origin ({}, {}) -> ({}, {}), size {}x{} -> {}x{}", + original_origin.y, + safe_origin.y, + original_safe_origin.x, + original_safe_origin.y, + area_origin.x, + area_origin.y, + original_safe_width, + original_safe_height, + ui.get_safe_area_width(), + ui.get_safe_area_height(), + ) + .into()); } - ui.set_extra_insets(TempoInsets::default()); + ui.set_test_insets(TempoInsets::default()); let group = ui.get_group_origin(); click_in(ui.window(), group.x + 131.0, group.y + 23.0); if ui.get_group_index() != 1 { @@ -370,14 +392,6 @@ fn catalog_smoke_start( ) .into()); } - ui.invoke_show_dialog(); - if !ui.get_dialog_open() { - return Err("dialog did not open".into()); - } - press(ui.window(), Key::Escape); - if ui.get_dialog_open() { - return Err("Escape did not dismiss dialog".into()); - } ui.set_tab(1); if ui.get_wide_split() == compact || ui.get_three_pane() != wide { return Err("adaptive split did not match the viewport".into()); @@ -408,6 +422,16 @@ fn catalog_smoke_start( if !ui.get_toast_visible() { return Err("toast did not open".into()); } + // Popup teardown runs on the next event-loop tick; do not click underlying + // controls in the same synchronous test callback after requesting close. + ui.invoke_show_dialog(); + if !ui.get_dialog_open() { + return Err("dialog did not open".into()); + } + press(ui.window(), Key::Escape); + if ui.get_dialog_open() { + return Err("Escape did not dismiss dialog".into()); + } Ok(()) } @@ -658,7 +682,64 @@ fn run_motion_smoke(ui: &TempoCatalogWindow, screenshot: Option) -> Resu Ok(()) } +fn run_lightweight_smoke() -> Result<()> { + let ui = TempoDialogSmokeWindow::new()?; + ui.show()?; + let saw_dialog_motion = Rc::new(Cell::new(false)); + let saw_route_motion = Rc::new(Cell::new(false)); + let (dialog_sample, route_sample) = (saw_dialog_motion.clone(), saw_route_motion.clone()); + let weak = ui.as_weak(); + Timer::single_shot(Duration::from_millis(100), move || { + let ui = weak.unwrap(); + ui.invoke_switch_route(); + ui.invoke_show_dialog(); + let weak = ui.as_weak(); + let start = Instant::now(); + let sample = Timer::default(); + let keep_alive = Rc::new(sample); + let stop = Rc::downgrade(&keep_alive); + keep_alive.start( + slint::TimerMode::Repeated, + Duration::from_millis(20), + move || { + let ui = weak.unwrap(); + let mid = |value: f32| value > 0.0 && value < 1.0; + dialog_sample.set(dialog_sample.get() || mid(ui.get_motion_progress())); + route_sample.set(route_sample.get() || mid(ui.get_route_progress())); + if start.elapsed() >= Duration::from_millis(250) { + stop.upgrade().unwrap().stop(); + click_in(ui.window(), 320.0, 610.0); + } + }, + ); + Timer::single_shot(Duration::from_millis(470), move || { + keep_alive.stop(); + let _ = slint::quit_event_loop(); + }); + }); + slint::run_event_loop()?; + if !saw_dialog_motion.get() + || !saw_route_motion.get() + || ui.get_confirmations() != 1 + || ui.get_presented() + { + return Err(format!( + "mobile dialog motion={}, route motion={}, confirmations={}, still presented={}", + saw_dialog_motion.get(), + saw_route_motion.get(), + ui.get_confirmations(), + ui.get_presented() + ) + .into()); + } + println!("Tempo UI lightweight confirmation smoke check passed"); + Ok(()) +} + fn main() -> Result<()> { - tempo_ui::fonts::configure_cjk_fallbacks()?; + tempo_ui::fonts::configure_system_fonts()?; + if std::env::args().any(|arg| arg == "--lightweight-smoke") { + return run_lightweight_smoke(); + } run_catalog(options()?) } diff --git a/examples/showcase/ui/catalog.slint b/examples/showcase/ui/catalog.slint index eb32a4b..cce0279 100644 --- a/examples/showcase/ui/catalog.slint +++ b/examples/showcase/ui/catalog.slint @@ -1,5 +1,5 @@ import { - TempoTheme, TempoIcons, TempoInsets, TempoNavigationShell, TempoPage, TempoPageHead, TempoAppBar, + TempoTheme, TempoIcons, TempoInsets, TempoWindow, TempoSafeArea, TempoNavigationShell, TempoPage, TempoPageHead, TempoAppBar, TempoSection, TempoCard, TempoInfoBar, TempoExpander, TempoPagination, TempoStepBar, TempoBreadcrumb, TempoAvatar, TempoStatCard, TempoProgressRing, TempoTimeline, TempoKeyValue, TempoBanner, TempoTabBar, TempoTable, TempoTreeView, TempoTreeNode, TempoColorPicker, TempoCalendar, TempoCarousel, TempoTransfer, TempoDivider, TempoButton, TempoIconButton, TempoFloatingActionButton, TempoButtonGroupTabBar, TempoComboBox, TempoDialog, TempoDrawer, TempoPopover, TempoDatePicker, TempoTimePicker, TempoImageViewer, TempoToastHost, TempoTextField, TempoTextArea, TempoCheckBox, TempoRadioButton, TempoSpinBox, TempoBadge, TempoChip, TempoRate, TempoSkeleton, TempoSplitButton, TempoLink, TempoKeyCap, TempoStatusDot, TempoRadioTile, TempoSwitchTile, TempoSlider, TempoRangeSlider, TempoProgressBar, TempoRefresh, TempoRefreshText, TempoSurface, TempoClickableSurface, TempoAdaptiveSplit, TempoDetailPresentation, TempoSplitPane, @@ -7,7 +7,7 @@ import { TempoMenuButton, TempoIndexedStack, TempoStackPage } from "@tempo-ui"; -export component TempoCatalogWindow inherits Window { +export component TempoCatalogWindow inherits TempoWindow { title: "Tempo UI · Components"; preferred-width: 1180px; preferred-height: 820px; @@ -30,13 +30,8 @@ export component TempoCatalogWindow inherits Window { changed detail => { if root.detail >= 0 { root.last-detail = root.detail; } } out property detail-progress: route-motion.progress; in-out property presentation: page; - in property extra-insets; - private property insets: { - left: root.safe-area-insets.left + root.extra-insets.left, - top: root.safe-area-insets.top + root.extra-insets.top, - right: root.safe-area-insets.right + root.extra-insets.right, - bottom: root.safe-area-insets.bottom + root.extra-insets.bottom, - }; + in property test-insets; + extra-insets: root.test-insets; out property dialog-open: modal.opened; out property dialog-presented: modal.presented; out property dialog-progress: modal.motion-progress; @@ -76,6 +71,9 @@ export component TempoCatalogWindow inherits Window { out property radio-focus-ring: local-radio.focus-ring-visible; out property field-center: { x: field.absolute-position.x + 80px, y: field.absolute-position.y + field.height - 22px }; out property heading-origin: catalog-head.absolute-position; + out property safe-area-origin: safe-probe.absolute-position; + out property safe-area-width: safe-probe.width; + out property safe-area-height: safe-probe.height; out property refresh-origin: refresh-pane.absolute-position; out property group-origin: group.absolute-position; in-out property refresh-count; @@ -92,8 +90,13 @@ export component TempoCatalogWindow inherits Window { public function open-combo() { selector.open(); } public function refresh-language-is-chinese() -> bool { return TempoRefreshText.for-language("zh").pull == "下拉刷新"; } + safe-area := TempoSafeArea { + insets: root.content-insets; + safe-probe := Rectangle { width: safe-area.content-width; height: safe-area.content-height; } + } + shell := TempoNavigationShell { - insets: root.insets; + insets: root.content-insets; selected <=> root.tab; show-bottom-bar: !(root.tab == 1 && root.detail >= 0); destinations: [ @@ -152,7 +155,7 @@ export component TempoCatalogWindow inherits Window { TempoTextField { label: "Input with validation"; error: "A name is required."; } selector := TempoComboBox { sheet-width: root.width; sheet-height: root.height; - sheet-origin: root.absolute-position; bottom-inset: root.insets.bottom; + sheet-origin: root.absolute-position; bottom-inset: root.content-insets.bottom; label: "Quality"; placeholder: "Choose a format"; selected <=> root.selected-choice; items: [{label: "Original", enabled: true}, {label: "FLAC (unavailable)", enabled: false}, {label: "MP3", enabled: true}]; } @@ -530,7 +533,7 @@ export component TempoCatalogWindow inherits Window { TempoDatePicker { horizontal-stretch: 1; sheet-width: root.width; sheet-height: root.height; - sheet-origin: root.absolute-position; bottom-inset: root.insets.bottom; + sheet-origin: root.absolute-position; bottom-inset: root.content-insets.bottom; label: "Release date"; value-text: "2026-11-" + (self.selected-day < 10 ? "0" : "") + self.selected-day; day-selected(d) => { toasts.show("DatePicker", "Picked Nov " + d, info, 1.5s); } @@ -538,7 +541,7 @@ export component TempoCatalogWindow inherits Window { TempoTimePicker { horizontal-stretch: 1; sheet-width: root.width; sheet-height: root.height; - sheet-origin: root.absolute-position; bottom-inset: root.insets.bottom; + sheet-origin: root.absolute-position; bottom-inset: root.content-insets.bottom; label: "Scheduled sync"; hour: 22; minute: 30; time-changed(h, m) => { toasts.show("TimePicker", "Set " + h + ":" + m, info, 1.5s); } @@ -774,8 +777,8 @@ export component TempoCatalogWindow inherits Window { exit-time: 180ms; } if root.tab == 0 : TempoFloatingActionButton { - x: parent.width - self.width - 20px - root.insets.right; - y: parent.height - self.height - 20px - root.insets.bottom - (shell.compact ? 58px : 0px); + x: parent.width - self.width - 20px - root.content-insets.right; + y: parent.height - self.height - 20px - root.content-insets.bottom - (shell.compact ? 58px : 0px); label: "Add sample"; activated => { root.show-dialog(); } } modal := TempoDialog { @@ -803,7 +806,7 @@ export component TempoCatalogWindow inherits Window { height: root.height; title: "Artwork Lightbox Preview"; } - toasts := TempoToastHost { bottom-inset: root.insets.bottom; left-inset: root.insets.left; right-inset: root.insets.right; } + toasts := TempoToastHost { bottom-inset: root.content-insets.bottom; left-inset: root.content-insets.left; right-inset: root.content-insets.right; } refresh-finish := Timer { interval: 250ms; running: false; triggered => { @@ -813,3 +816,31 @@ export component TempoCatalogWindow inherits Window { } changed tab => { if root.tab == 1 { layout-tab.focus(); } } } + +// Fixed geometry for exercising a real popup button with mobile motion policy. +export component TempoDialogSmokeWindow inherits TempoWindow { + width: 420px; + height: 640px; + in-out property confirmations; + out property presented: dialog.presented; + out property motion-progress: dialog.motion-progress; + out property route-progress: routes.progress; + private property route; + public function switch-route() { root.route += 1; } + routes := TempoRouteMotion { + route-key: root.route; + transition: fade-through; + Rectangle { width: 64px; height: 64px; background: TempoTheme.primary; } + } + public function show-dialog() { dialog.show(); } + init => { TempoMotionSettings.lightweight = true; } + dialog := TempoDialog { + width: root.width; height: root.height; + title: "Sign out?"; + panel-width: 320px; + bottom-sheet: true; + confirm-label: "Sign out"; + cancel-label: "Cancel"; + confirmed => { root.confirmations += 1; } + } +} diff --git a/scripts/check.sh b/scripts/check.sh index df41bcf..1d16100 100755 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -20,4 +20,5 @@ for renderer in "${renderers[@]}"; do "$showcase" --layout --wide --smoke "$showcase" --motion-smoke "$showcase" --motion-smoke --compact --dark + "$showcase" --lightweight-smoke done diff --git a/src/fonts.rs b/src/fonts.rs index 2c2bdbe..59404dc 100644 --- a/src/fonts.rs +++ b/src/fonts.rs @@ -1,8 +1,15 @@ -use std::sync::OnceLock; +use std::cell::Cell; use slint::fontique_012::{fontique, set_shared_collection}; -static CONFIGURED: OnceLock<()> = OnceLock::new(); +#[cfg(target_os = "android")] +mod android; +#[cfg(target_os = "linux")] +mod linux; + +thread_local! { + static CONFIGURED: Cell = const { Cell::new(false) }; +} const HANI_SC_PREFERENCES: &[&str] = &[ "Microsoft YaHei UI", @@ -99,31 +106,61 @@ fn apply_script_fallbacks( script: [u8; 4], locales: &[Option<&str>], preferred: &[fontique::FamilyId], + system_first: Option, ) { - if preferred.is_empty() { + if preferred.is_empty() && system_first.is_none() { return; } let script = fontique::Script::from_bytes(script); for locale in locales { let parsed = locale.and_then(|tag| fontique::Language::parse(tag).ok()); let key = fontique::FallbackKey::new(script, parsed.as_ref()); - let mut merged = preferred.to_vec(); - let existing: Vec<_> = collection.fallback_families(key).collect(); - for id in existing { - if !merged.contains(&id) { - merged.push(id); - } - } + let merged = unique( + system_first + .into_iter() + .chain(preferred.iter().copied()) + .chain(collection.fallback_families(key)), + ); collection.set_fallbacks(key, merged.into_iter()); } } -/// Configure reliable cross-platform CJK font fallbacks for Slint/fontique -/// across Linux, Windows, macOS, and Android without bundling font files. +fn unique(ids: impl IntoIterator) -> Vec { + let mut result = Vec::new(); + for id in ids { + if !result.contains(&id) { + result.push(id); + } + } + result +} + +fn set_default_families(collection: &mut fontique::Collection, preferred: &[fontique::FamilyId]) { + if preferred.is_empty() { + return; + } + // Slint tries SystemUi before SansSerif. Fontique keeps the built-in + // families after these overrides. Keep CJK additions in script fallback + // so a generic Simplified Chinese face doesn't preempt other locales. + for generic in [ + fontique::GenericFamily::SystemUi, + fontique::GenericFamily::SansSerif, + ] { + collection.set_generic_families(generic, preferred.iter().copied()); + } +} + +/// Follow the system UI font and supplement the system's missing-glyph fallback. /// -/// Safe to call more than once; call before constructing a Slint window. -pub fn configure_cjk_fallbacks() -> Result<(), slint::PlatformError> { - if CONFIGURED.get().is_some() { +/// Call on the Slint UI thread before initializing its platform or constructing +/// any components. Repeated calls on that thread do nothing. On Android 10+ +/// uses the native system font matcher. On Linux, reads supported desktop +/// settings and falls back to Fontconfig. +/// +/// An installed family in `TEMPO_UI_FONT_FAMILY` or a readable font file in +/// `SLINT_DEFAULT_FONT` can override automatic detection. +pub fn configure_system_fonts() -> Result<(), slint::PlatformError> { + if CONFIGURED.get() { return Ok(()); } let mut collection = fontique::Collection::new(fontique::CollectionOptions { @@ -136,6 +173,23 @@ pub fn configure_cjk_fallbacks() -> Result<(), slint::PlatformError> { let jp = resolve_preferred_ids(&mut collection, JP_PREFERENCES); let kr = resolve_preferred_ids(&mut collection, KR_PREFERENCES); + let system = SystemFonts::detect(&mut collection); + + let file_override = std::env::var_os("SLINT_DEFAULT_FONT") + .and_then(|path| std::fs::read(path).ok()) + .map(|bytes| collection.register_fonts(bytes.into(), None)) + .unwrap_or_default(); + let family_override = std::env::var("TEMPO_UI_FONT_FAMILY") + .ok() + .and_then(|name| collection.family_by_name(name.trim())) + .map(|family| family.id()); + let primary = unique( + family_override + .into_iter() + .chain(file_override.into_iter().map(|(id, _)| id)) + .chain(system.primary), + ); + // Register both locale-less and locale-qualified keys so Slint/parley // resolves Simplified/Traditional Chinese, Japanese, and Korean reliably. apply_script_fallbacks( @@ -149,45 +203,93 @@ pub fn configure_cjk_fallbacks() -> Result<(), slint::PlatformError> { Some("zh-SG"), ], &sc, + system.sc, ); apply_script_fallbacks( &mut collection, *b"Hani", &[Some("zh-Hant"), Some("zh-TW"), Some("zh-HK"), Some("zh-MO")], if tc.is_empty() { &sc } else { &tc }, + system.tc, + ); + apply_script_fallbacks( + &mut collection, + *b"Hani", + &[Some("ja"), Some("ja-JP")], + &jp, + system.ja_han, + ); + apply_script_fallbacks( + &mut collection, + *b"Hani", + &[Some("ko"), Some("ko-KR")], + &kr, + system.ko_han, ); apply_script_fallbacks( &mut collection, *b"Hira", &[None, Some("ja"), Some("ja-JP")], &jp, + system.hira, ); apply_script_fallbacks( &mut collection, *b"Kana", &[None, Some("ja"), Some("ja-JP")], &jp, + system.kana, ); apply_script_fallbacks( &mut collection, *b"Hang", &[None, Some("ko"), Some("ko-KR")], &kr, + system.hang, ); - // Append CJK families to GenericFamily::SansSerif so mixed Latin + CJK runs - // always have an explicit CJK fallback in the default sans-serif chain. - if !sc.is_empty() { - collection.append_generic_families(fontique::GenericFamily::SansSerif, sc.into_iter()); - } + set_default_families(&mut collection, &primary); let result = set_shared_collection(collection); if result.is_ok() { - let _ = CONFIGURED.set(()); + CONFIGURED.set(true); } result } +#[derive(Default)] +struct SystemFonts { + primary: Option, + sc: Option, + tc: Option, + ja_han: Option, + ko_han: Option, + hira: Option, + kana: Option, + hang: Option, +} + +impl SystemFonts { + fn detect(_collection: &mut fontique::Collection) -> Self { + #[cfg(target_os = "android")] + return android::detect(_collection); + + #[cfg(target_os = "linux")] + return Self { + primary: linux::preferred_family(_collection), + ..Self::default() + }; + + #[cfg(not(any(target_os = "android", target_os = "linux")))] + Self::default() + } +} + +/// Compatibility entry point. Also follows the system UI font. +pub fn configure_cjk_fallbacks() -> Result<(), slint::PlatformError> { + configure_system_fonts() +} + #[cfg(test)] mod tests { use super::*; @@ -195,8 +297,39 @@ mod tests { #[test] fn configure_cjk_fallbacks_is_idempotent() { let first = configure_cjk_fallbacks(); - let second = configure_cjk_fallbacks(); + let second = configure_system_fonts(); assert!(first.is_ok()); assert!(second.is_ok()); } + + #[test] + fn system_face_precedes_extra_script_fallbacks() { + use fontique::{FamilyId, GenericFamily}; + let mut collection = fontique::Collection::new(fontique::CollectionOptions { + system_fonts: false, + ..Default::default() + }); + let [custom, system, fallback] = std::array::from_fn(|_| FamilyId::new()); + set_default_families(&mut collection, &[custom]); + apply_script_fallbacks( + &mut collection, + *b"Hani", + &[None], + &[fallback, system], + Some(system), + ); + assert_eq!( + collection.generic_families(GenericFamily::SystemUi).next(), + Some(custom) + ); + assert_eq!( + collection.generic_families(GenericFamily::SansSerif).next(), + Some(custom) + ); + let han = fontique::Script::from_bytes(*b"Hani"); + assert_eq!( + collection.fallback_families(han).collect::>(), + [system, fallback] + ); + } } diff --git a/src/fonts/android.rs b/src/fonts/android.rs new file mode 100644 index 0000000..51384c6 --- /dev/null +++ b/src/fonts/android.rs @@ -0,0 +1,225 @@ +// AFontMatcher is available from API 29. Resolve it at runtime so the same +// library can still load on older Android releases. +use std::{ + collections::HashMap, + ffi::{CStr, OsStr, c_char, c_void}, + os::unix::ffi::OsStrExt, + path::{Path, PathBuf}, + ptr, +}; + +use libloading::{Library, Symbol}; + +use super::{SystemFonts, fontique}; + +type Handle = *mut c_void; +type FontKey = (PathBuf, u32); + +pub(super) fn detect(collection: &mut fontique::Collection) -> SystemFonts { + let samples = native_fonts().unwrap_or_default(); + let [native_ui, sc, tc, ja_han, ko_han, hira, kana, hang] = samples; + let root = + std::env::var_os("ANDROID_ROOT").map_or_else(|| PathBuf::from("/system"), PathBuf::from); + let configured = configured_ui_font(&root); + + let mut known = HashMap::new(); + for id in collection.family_ids().collect::>() { + if let Some(family) = collection.family(id) { + for font in family.fonts() { + if let fontique::SourceKind::Path(path) = &font.source().kind { + known.insert(((**path).to_owned(), font.index()), id); + } + } + } + } + + let mut resolve = |key: FontKey| { + if let Some(id) = known.get(&key) { + return Some(*id); + } + // OEM or updated fonts can live outside Fontique's /system/fonts scan. + // One TTC can contain several different language variants. + let bytes = std::fs::read(&key.0).ok()?; + for (id, fonts) in collection.register_fonts(bytes.into(), None) { + for font in fonts { + known.insert((key.0.clone(), font.index()), id); + } + } + known.get(&key).copied() + }; + + // Some ROMs swap the configured face through a symlink, but still return + // the stock face from AFontMatcher. Respect that explicit redirect unless + // the native matcher already identifies a font outside the system scan. + let redirected = configured.as_ref().filter(|(path, _)| { + path.is_symlink() + && native_ui + .as_ref() + .is_none_or(|(native, _)| native.starts_with(root.join("fonts"))) + }); + let primary = redirected + .cloned() + .into_iter() + .chain(native_ui) + .chain(configured) + .find_map(&mut resolve); + let [sc, tc, ja_han, ko_han, hira, kana, hang] = + [sc, tc, ja_han, ko_han, hira, kana, hang].map(|key| key.and_then(&mut resolve)); + SystemFonts { + primary, + sc, + tc, + ja_han, + ko_han, + hira, + kana, + hang, + } +} + +fn configured_ui_font(root: &Path) -> Option { + // Legacy Android/OEM configuration is best-effort. On systems that don't + // expose it, use the native matcher or Fontique's built-in discovery. + let xml = std::fs::read_to_string(root.join("etc/fonts.xml")).ok()?; + let (file, index) = configured_ui_face(&xml)?; + Some((root.join("fonts").join(file), index)) +} + +fn configured_ui_face(xml: &str) -> Option<(String, u32)> { + let document = roxmltree::Document::parse(xml).ok()?; + let root = document.root_element(); + if !root.has_tag_name("familyset") { + return None; + } + let families = || root.children().filter(|node| node.has_tag_name("family")); + let family = families() + .find(|node| node.attribute("name") == Some("sans-serif")) + .or_else(|| { + let alias = root.children().find(|node| { + node.has_tag_name("alias") + && node.attribute("name") == Some("sans-serif") + && node.attribute("weight").is_none() + })?; + let target = alias.attribute("to")?; + families().find(|node| node.attribute("name") == Some(target)) + })?; + let regular = family + .children() + .filter(|node| { + node.has_tag_name("font") + && match node.attribute("style") { + None | Some("normal") => true, + _ => false, + } + }) + .filter(|node| node.attribute("fallbackFor").is_none()) + .min_by_key(|node| { + node.attribute("weight") + .and_then(|weight| weight.parse::().ok()) + .unwrap_or(400) + .abs_diff(400) + })?; + let file = regular.text()?.trim(); + let index = regular.attribute("index").unwrap_or("0").parse().ok()?; + (!file.is_empty()).then(|| (file.to_owned(), index)) +} + +fn native_fonts() -> Option<[Option; 8]> { + // Android initializes the native matcher in app processes. It can crash + // in a standalone shell executable, where Minikin has no font collection. + unsafe extern "C" { + fn getuid() -> u32; + } + if unsafe { getuid() } % 100_000 < 10_000 { + return None; + } + // SAFETY: libandroid.so is a public platform library. The function + // signatures below match and . + unsafe { detect_native() } +} + +unsafe fn detect_native() -> Option<[Option; 8]> { + // Resolve every entry point before allocating any NDK handles. + let library = unsafe { Library::new("libandroid.so") }.ok()?; + let create: Symbol Handle> = + unsafe { library.get(b"AFontMatcher_create") }.ok()?; + let destroy: Symbol = + unsafe { library.get(b"AFontMatcher_destroy") }.ok()?; + let locales: Symbol = + unsafe { library.get(b"AFontMatcher_setLocales") }.ok()?; + let find: Symbol< + unsafe extern "C" fn(Handle, *const c_char, *const u16, u32, *mut u32) -> Handle, + > = unsafe { library.get(b"AFontMatcher_match") }.ok()?; + let file: Symbol *const c_char> = + unsafe { library.get(b"AFont_getFontFilePath") }.ok()?; + let index: Symbol usize> = + unsafe { library.get(b"AFont_getCollectionIndex") }.ok()?; + let close: Symbol = + unsafe { library.get(b"AFont_close") }.ok()?; + + let matcher = unsafe { create() }; + if matcher.is_null() { + return None; + } + let probe = |character: char, locale: &CStr| -> Option { + let mut units = [0; 2]; + let text = character.encode_utf16(&mut units); + // SAFETY: the matcher is live, the strings are NUL-terminated and the + // UTF-16 slice has the declared length. Copy the path before closing. + unsafe { + locales(matcher, locale.as_ptr()); + let font = find( + matcher, + c"sans-serif".as_ptr(), + text.as_ptr(), + text.len() as u32, + ptr::null_mut(), + ); + if font.is_null() { + return None; + } + let path = file(font); + let key = (!path.is_null()).then(|| { + let path = OsStr::from_bytes(CStr::from_ptr(path).to_bytes()); + (PathBuf::from(path), index(font) as u32) + }); + close(font); + key + } + }; + + let samples = [ + probe('A', c""), + probe('骨', c"zh-CN"), + probe('骨', c"zh-TW"), + probe('骨', c"ja-JP"), + probe('骨', c"ko-KR"), + probe('あ', c"ja-JP"), + probe('ア', c"ja-JP"), + probe('한', c"ko-KR"), + ]; + unsafe { destroy(matcher) }; + + Some(samples) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn configured_sans_serif_uses_normal_regular_face_and_ttc_index() { + let xml = r#" + + + Italic.ttf + Bold.ttf + Vendor.ttc + + + + "#; + assert_eq!(configured_ui_face(xml), Some(("Vendor.ttc".into(), 2))); + assert_eq!(configured_ui_face(""), None); + } +} diff --git a/src/fonts/linux.rs b/src/fonts/linux.rs new file mode 100644 index 0000000..97325bf --- /dev/null +++ b/src/fonts/linux.rs @@ -0,0 +1,80 @@ +use std::process::Command; + +use super::fontique::{Collection, FamilyId}; + +fn command_value(program: &str, args: &[&str]) -> Option { + let output = Command::new(program).args(args).output().ok()?; + let value = String::from_utf8(output.stdout).ok()?.trim().to_owned(); + (output.status.success() && !value.is_empty()).then_some(value) +} + +// Pango descriptions can contain a multi-word family followed by style and size. +// Match the longest installed family instead of guessing where the style starts. +fn pango_family<'a>(description: &str, names: impl Iterator) -> Option<&'a str> { + names + .filter(|name| { + description + .get(..name.len()) + .is_some_and(|prefix| prefix.eq_ignore_ascii_case(name)) + && description[name.len()..] + .chars() + .next() + .is_none_or(|next| next.is_whitespace() || next == ',') + }) + .max_by_key(|name| name.len()) +} + +pub(super) fn preferred_family(collection: &mut Collection) -> Option { + let desktop = std::env::var("XDG_CURRENT_DESKTOP") + .or_else(|_| std::env::var("XDG_SESSION_DESKTOP")) + .unwrap_or_default(); + if desktop + .split(':') + .any(|name| name.eq_ignore_ascii_case("kde") || name.eq_ignore_ascii_case("plasma")) + { + let args = [ + "--file", + "kdeglobals", + "--group", + "General", + "--key", + "font", + ]; + let value = command_value("kreadconfig6", &args) + .or_else(|| command_value("kreadconfig5", &args))?; + return collection + .family_by_name(value.split(',').next()?.trim()) + .map(|family| family.id()); + } + + let schema = desktop.split(':').find_map(|name| { + if name.eq_ignore_ascii_case("gnome") || name.eq_ignore_ascii_case("unity") { + Some("org.gnome.desktop.interface") + } else if name.eq_ignore_ascii_case("x-cinnamon") { + Some("org.cinnamon.desktop.interface") + } else if name.eq_ignore_ascii_case("mate") { + Some("org.mate.interface") + } else { + None + } + })?; + let value = command_value("gsettings", &["get", schema, "font-name"])?; + let description = value.trim_matches(['\'', '"']).replace("\\'", "'"); + let name = pango_family(&description, collection.family_names())?.to_owned(); + collection.family_by_name(&name).map(|family| family.id()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn desktop_font_description_prefers_longest_whole_family() { + let names = ["Noto Sans", "Noto Sans CJK SC", "Noto Sans CJK", "Inter"]; + assert_eq!( + pango_family("Noto Sans CJK SC Semi-Bold 11.5", names.into_iter()), + Some("Noto Sans CJK SC") + ); + assert_eq!(pango_family("Interstate 10", names.into_iter()), None); + } +} diff --git a/src/lib.rs b/src/lib.rs index b226f42..c5041c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -//! Rust host helpers for Tempo UI (route stacks and cross-platform CJK font fallbacks). +//! Rust host helpers for Tempo UI (route stacks and system typography). #[cfg(feature = "cjk-font-fallback")] pub mod fonts; diff --git a/ui/auxiliary.slint b/ui/auxiliary.slint index c5216ff..425ebc4 100644 --- a/ui/auxiliary.slint +++ b/ui/auxiliary.slint @@ -12,9 +12,14 @@ export component TempoFloatingActionButton inherits TempoAction { border-radius: TempoTokens.radius-md; background: !root.enabled ? TempoTheme.border : root.pressed ? TempoTheme.primary-pressed : root.hovered ? TempoTheme.primary-hover : TempoTheme.primary; - drop-shadow-blur: root.hovered ? 6px : 4px; - drop-shadow-offset-y: 2px; + drop-shadow-blur: root.pressed ? 2px : root.hovered ? 8px : 4px; + drop-shadow-offset-y: root.pressed ? 1px : root.hovered ? 3px : 2px; drop-shadow-color: #0004; + animate background, drop-shadow-blur, drop-shadow-offset-y { + enabled: !TempoMotionSettings.reduced; + duration: TempoTokens.fast; + easing: ease-out; + } TempoIcon { source: root.icon; tint: root.enabled ? TempoTheme.text-inverse : TempoTheme.text-disabled; width: root.small ? TempoTokens.icon-md : TempoTokens.icon-lg; height: self.width; @@ -41,6 +46,7 @@ component TempoGroupTabButton inherits TempoAction { preferred-width: max(42px, inner.preferred-width); border-radius: TempoTokens.radius-sm; background: !root.active && root.hovered ? TempoTheme.surface-pressed : transparent; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } init => { if root.active { root.marker(root.x, root.width); } } changed active => { if root.active { root.marker(root.x, root.width); } } changed marker-x => { if root.active { root.marker(root.x, root.width); } } @@ -50,7 +56,10 @@ component TempoGroupTabButton inherits TempoAction { padding-left: root.show-label ? 12px : 0px; padding-right: self.padding-left; spacing: TempoTokens.gap6; if root.item.icon.width > 0 : TempoIcon { source: root.item.icon; tint: root.ink; width: 18px; height: 18px; } - if root.show-label : Text { text: root.item.label; color: root.ink; font-size: 12px; font-weight: root.active ? 800 : 700; } + if root.show-label : Text { + text: root.item.label; color: root.ink; font-size: (12px) * TempoTokens.text-scale(1rem); font-weight: root.active ? 800 : 700; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + } } Tooltip { Text { text: root.item.tooltip != "" ? root.item.tooltip : root.item.label; } } } @@ -65,6 +74,7 @@ export component TempoButtonGroupTabBar inherits Rectangle { callback selected-index(int); private property target-x; private property target-width; + private property measured: false; height: 46px; background: TempoTheme.surface-alt; border-width: 1px; border-color: TempoTheme.border; border-radius: TempoTokens.radius-sm; @@ -82,14 +92,18 @@ export component TempoButtonGroupTabBar inherits Rectangle { height: 36px; border-radius: TempoTokens.radius-sm; background: TempoTheme.primary; - animate x, width { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.motion-medium; easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); } + animate x, width { + enabled: root.measured && !TempoMotionSettings.reduced; + duration: TempoTokens.normal; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); + } } tab-row := HorizontalLayout { spacing: TempoTokens.gap4; alignment: root.alignment; for item[i] in root.items : TempoGroupTabButton { item: item; active: i == root.selected; show-label: root.show-labels; - marker(x, w) => { root.target-x = x; root.target-width = w; } + marker(x, w) => { root.target-x = x; root.target-width = w; root.measured = true; } activated => { root.selected = i; root.selected-index(i); } } } @@ -168,29 +182,44 @@ export component TempoRefresh inherits Rectangle { } } settle := Timer { interval: 550ms; running: false; triggered => { self.running = false; if root.ready { root.state = idle; } } } - header-motion := TempoPresence { active: root.state == refreshing || root.refresh-result; } + header-motion := TempoPresence { + active: root.state == refreshing || root.refresh-result; + enter-time: TempoTokens.normal; + exit-time: TempoTokens.fast; + } footer-motion := TempoPresence { active: root.state == loading || root.state == loaded || root.state == load-failed || (root.state == no-more && !root.no-more-dismissed); + enter-time: TempoTokens.normal; + exit-time: TempoTokens.fast; } VerticalLayout { Rectangle { height: root.pulling ? min(44px, root.pull-offset * 0.55) : 44px * header-motion.progress; clip: true; - visible: root.pulling || header-motion.present; + visible: self.height > 0.5px || root.pulling || header-motion.present; + animate height { + enabled: !root.pulling && !TempoMotionSettings.reduced; + duration: TempoTokens.normal; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); + } HorizontalLayout { y: parent.height - 44px; height: 44px; - opacity: root.pulling ? min(1.0, root.pull-offset / 35px) : header-motion.progress; + opacity: root.pulling ? clamp((root.pull-offset - 8px) / 16px, 0.0, 1.0) : header-motion.progress; alignment: center; cross-axis-alignment: center; spacing: TempoTokens.gap8; TempoIcon { width: 20px; height: 20px; source: root.state == refreshed ? TempoIcons.check : root.state == refresh-failed ? TempoIcons.error : TempoIcons.refresh; tint: root.state == refreshed ? TempoTheme.success : root.state == refresh-failed ? TempoTheme.danger : TempoTheme.primary; + transform-rotation: root.state == refreshing && !TempoMotionSettings.reduced + ? 360deg * mod(animation-tick(), 850ms) / 850ms + : root.pulling ? 180deg * clamp(root.pull-offset / max(1px, root.trigger-distance), 0.0, 1.0) + : 0deg; } Text { text: root.state == refreshing ? root.labels.refreshing : root.state == refreshed ? root.labels.refresh-success : root.state == refresh-failed ? root.labels.refresh-failed : root.pull-offset >= root.trigger-distance ? root.labels.release : root.labels.pull; - color: TempoTheme.text-secondary; font-size: 14px; + color: TempoTheme.text-secondary; font-size: (14px) * TempoTokens.text-scale(1rem); } } } @@ -220,7 +249,7 @@ export component TempoRefresh inherits Rectangle { alignment: center; cross-axis-alignment: center; Text { text: root.state == loading ? root.labels.loading : root.state == loaded ? root.labels.load-success : root.state == load-failed ? root.labels.load-failed : root.labels.no-more; - color: root.state == load-failed ? TempoTheme.danger : root.state == loaded ? TempoTheme.success : TempoTheme.text-secondary; font-size: 14px; + color: root.state == load-failed ? TempoTheme.danger : root.state == loaded ? TempoTheme.success : TempoTheme.text-secondary; font-size: (14px) * TempoTokens.text-scale(1rem); } } } diff --git a/ui/controls.slint b/ui/controls.slint index 3fef036..9fd6acf 100644 --- a/ui/controls.slint +++ b/ui/controls.slint @@ -51,10 +51,11 @@ export component TempoAction inherits Rectangle { clicked => { keys.focus-from-pointer(); root.activated(); } } Rectangle { - visible: root.focus-ring-visible; + opacity: root.focus-ring-visible ? 1.0 : 0.0; border-radius: root.border-radius; border-width: 2px; border-color: TempoTheme.primary; + animate opacity { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } @@ -62,6 +63,7 @@ export component TempoIcon inherits Image { in property tint: TempoTheme.text-secondary; colorize: root.tint; image-fit: contain; + animate colorize { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } export enum TempoButtonVariant { primary, secondary, outline, ghost, success, warning, danger } @@ -99,7 +101,7 @@ export component TempoButton inherits TempoAction { : root.variant == outline ? (root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : TempoTheme.surface) : root.variant == secondary ? (root.pressed || root.hovered ? TempoTheme.primary-subtle : TempoTheme.primary-soft) : root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.primary-soft : transparent; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } inner := HorizontalLayout { alignment: center; cross-axis-alignment: center; @@ -116,8 +118,9 @@ export component TempoButton inherits TempoAction { if !root.icon-only : Text { text: root.label; color: root.ink; - font-size: root.compact ? 13px : 15px; + font-size: (root.compact ? 13px : 15px) * TempoTokens.text-scale(1rem); font-weight: 600; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } } @@ -141,7 +144,7 @@ export component TempoIconButton inherits TempoAction { : root.variant == outline ? (root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : TempoTheme.surface) : root.variant == danger ? (root.pressed || root.hovered ? TempoTheme.danger-subtle : TempoTheme.danger-soft) : root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : transparent; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } if root.loading : Spinner { width: root.icon-size; height: root.icon-size; indeterminate: true; } if !root.loading : TempoIcon { source: root.icon; @@ -197,7 +200,7 @@ export component TempoTag inherits Rectangle { tint: root.foreground; width: 12px; height: 12px; } - Text { text: root.label; color: root.foreground; font-size: 11px; font-weight: 600; } + Text { text: root.label; color: root.foreground; font-size: (11px) * TempoTokens.text-scale(1rem); font-weight: 600; } } } @@ -219,7 +222,7 @@ export component TempoTextField inherits VerticalLayout { forward-focus: input; spacing: TempoTokens.gap6; if root.label != "" : Text { - text: root.label; color: TempoTheme.text-secondary; font-size: 12px; font-weight: 600; + text: root.label; color: TempoTheme.text-secondary; font-size: (12px) * TempoTokens.text-scale(1rem); font-weight: 600; } Rectangle { height: root.field-height; @@ -228,7 +231,7 @@ export component TempoTextField inherits VerticalLayout { border-color: root.error != "" ? TempoTheme.danger : input.has-focus ? TempoTheme.border-strong : TempoTheme.border; border-width: 1px; clip: true; - animate border-color, background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate border-color, background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } HorizontalLayout { padding-left: 12px; padding-right: 12px; spacing: 8px; if root.icon.width > 0 : TempoIcon { @@ -241,13 +244,13 @@ export component TempoTextField inherits VerticalLayout { visible: input.text == ""; text: root.placeholder; x: 0px; width: parent.width; height: parent.height; horizontal-alignment: left; vertical-alignment: center; - color: TempoTheme.text-tertiary; font-size: root.field-height == 44px ? 13px : 15px; + color: TempoTheme.text-tertiary; font-size: (root.field-height == 44px ? 13px : 15px) * TempoTokens.text-scale(1rem); } input := TextInput { enabled: root.enabled; input-type: root.input-type == InputType.password && root.revealed ? InputType.text : root.input-type; input-method-hints: root.input-hints; - single-line: true; font-size: root.field-height == 44px ? 13px : 15px; + single-line: true; font-size: (root.field-height == 44px ? 13px : 15px) * TempoTokens.text-scale(1rem); color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; selection-background-color: TempoTheme.primary; selection-foreground-color: TempoTheme.text-inverse; @@ -279,17 +282,22 @@ export component TempoTextField inherits VerticalLayout { } @children } - // Bottom accent focus bar + // Bottom accent focus bar expanding smoothly from center Rectangle { - x: 0px; + x: (parent.width - self.width) / 2; y: parent.height - 2px; - width: parent.width; - height: input.has-focus || root.error != "" ? 2px : 0px; + width: input.has-focus || root.error != "" ? parent.width : 0px; + height: 2px; background: root.error != "" ? TempoTheme.danger : TempoTheme.primary; - animate height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate width { + enabled: !TempoMotionSettings.reduced; + duration: TempoTokens.normal; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); + } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } - if root.error != "" : Text { text: root.error; color: TempoTheme.danger; font-size: 12px; wrap: word-wrap; } + if root.error != "" : Text { text: root.error; color: TempoTheme.danger; font-size: (12px) * TempoTokens.text-scale(1rem); wrap: word-wrap; } } export component TempoSearch inherits TempoTextField { @@ -315,7 +323,7 @@ export component TempoSwitch inherits TempoAction { : root.checked ? (root.pressed ? TempoTheme.primary-pressed : root.hovered ? TempoTheme.primary-hover : TempoTheme.primary) : root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : TempoTheme.surface; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.checked = !root.checked; root.toggled(root.checked); @@ -328,10 +336,15 @@ export component TempoSwitch inherits TempoAction { border-radius: TempoTokens.radius-full; background: root.checked ? TempoTheme.text-inverse : root.enabled ? TempoTheme.text-secondary : TempoTheme.text-disabled; - animate x, width, background { + animate x, width { enabled: !TempoMotionSettings.reduced; - duration: TempoTokens.motion-short; - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); + duration: TempoTokens.normal; + easing: cubic-bezier(0.34, 1.35, 0.64, 1.0); + } + animate background { + enabled: !TempoMotionSettings.reduced; + duration: TempoTokens.fast; + easing: ease-out; } } } @@ -387,8 +400,9 @@ export component TempoSlider inherits Rectangle { height: 18px; border-radius: 9px; border-width: keys.ring-visible ? 2px : 1.5px; - border-color: keys.ring-visible ? TempoTheme.primary : TempoTheme.border-strong; + border-color: keys.ring-visible || touch.has-hover ? TempoTheme.primary : TempoTheme.border-strong; background: TempoTheme.surface-elevated; + animate border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } Rectangle { width: touch.pressed ? 8px : touch.has-hover ? 12px : 10px; height: self.width; @@ -396,7 +410,7 @@ export component TempoSlider inherits Rectangle { y: (parent.height - self.height) / 2; border-radius: self.width / 2; background: root.enabled ? TempoTheme.primary : TempoTheme.text-disabled; - animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: cubic-bezier(0.34, 1.35, 0.64, 1.0); } } } keys := TempoControlFocus { @@ -422,9 +436,10 @@ export component TempoSlider inherits Rectangle { export component TempoClickableSurface inherits TempoAction { background: root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : TempoTheme.surface; - border-color: TempoTheme.border; + border-color: root.hovered ? TempoTheme.border-strong : TempoTheme.border; border-width: TempoTokens.border-width; border-radius: TempoTokens.radius-lg; + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } @children } @@ -439,7 +454,7 @@ export component TempoTextArea inherits VerticalLayout { forward-focus: input; spacing: TempoTokens.gap6; if root.label != "" : Text { - text: root.label; color: TempoTheme.text-secondary; font-size: TempoTokens.text-sm; font-weight: 600; + text: root.label; color: TempoTheme.text-secondary; font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; } Rectangle { height: root.area-height; @@ -448,7 +463,7 @@ export component TempoTextArea inherits VerticalLayout { border-color: root.error != "" ? TempoTheme.danger : input.has-focus ? TempoTheme.border-strong : TempoTheme.border; border-width: 1px; clip: true; - animate border-color, background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate border-color, background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } ScrollView { x: 10px; y: 8px; width: parent.width - 20px; @@ -460,7 +475,7 @@ export component TempoTextArea inherits VerticalLayout { width: parent.width; text: root.placeholder; color: TempoTheme.text-tertiary; - font-size: TempoTokens.text-md; + font-size: (TempoTokens.text-md) * TempoTokens.text-scale(1rem); wrap: word-wrap; } input := TextInput { @@ -470,7 +485,7 @@ export component TempoTextArea inherits VerticalLayout { enabled: root.enabled; single-line: false; wrap: word-wrap; - font-size: TempoTokens.text-md; + font-size: (TempoTokens.text-md) * TempoTokens.text-scale(1rem); color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; selection-background-color: TempoTheme.primary; selection-foreground-color: TempoTheme.text-inverse; @@ -479,14 +494,20 @@ export component TempoTextArea inherits VerticalLayout { } } Rectangle { - x: 0px; y: parent.height - 2px; - width: parent.width; - height: input.has-focus || root.error != "" ? 2px : 0px; + x: (parent.width - self.width) / 2; + y: parent.height - 2px; + width: input.has-focus || root.error != "" ? parent.width : 0px; + height: 2px; background: root.error != "" ? TempoTheme.danger : TempoTheme.primary; - animate height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate width { + enabled: !TempoMotionSettings.reduced; + duration: TempoTokens.normal; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); + } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } - if root.error != "" : Text { text: root.error; color: TempoTheme.danger; font-size: TempoTokens.text-sm; wrap: word-wrap; } + if root.error != "" : Text { text: root.error; color: TempoTheme.danger; font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); wrap: word-wrap; } } export component TempoCheckBox inherits TempoAction { @@ -514,16 +535,22 @@ export component TempoCheckBox inherits TempoAction { : root.checked ? (root.pressed ? TempoTheme.primary-pressed : root.hovered ? TempoTheme.primary-hover : TempoTheme.primary) : root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : TempoTheme.surface; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } - if root.checked : TempoIcon { + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + TempoIcon { source: TempoIcons.checkmark-small; tint: TempoTheme.text-inverse; - width: 13px; height: 13px; + width: root.checked ? 13px : 0px; + height: self.width; + x: (parent.width - self.width) / 2; + y: (parent.height - self.height) / 2; + opacity: root.checked ? 1.0 : 0.0; + animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: cubic-bezier(0.34, 1.4, 0.64, 1.0); } + animate opacity { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } if root.label != "" : Text { text: root.label; - font-size: TempoTokens.text-md; + font-size: (TempoTokens.text-md) * TempoTokens.text-scale(1rem); color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; vertical-alignment: center; } @@ -557,16 +584,22 @@ export component TempoRadioButton inherits TempoAction { : root.checked ? TempoTheme.primary : root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : TempoTheme.surface; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } - if root.checked : Rectangle { - width: 7px; height: 7px; + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + Rectangle { + width: root.checked ? 7px : 0px; + height: self.width; + x: (parent.width - self.width) / 2; + y: (parent.height - self.height) / 2; border-radius: TempoTokens.radius-full; background: TempoTheme.text-inverse; + opacity: root.checked ? 1.0 : 0.0; + animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: cubic-bezier(0.34, 1.4, 0.64, 1.0); } + animate opacity { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } if root.label != "" : Text { text: root.label; - font-size: TempoTokens.text-md; + font-size: (TempoTokens.text-md) * TempoTokens.text-scale(1rem); color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; vertical-alignment: center; } @@ -592,7 +625,7 @@ export component TempoSpinBox inherits VerticalLayout { } } if root.label != "" : Text { - text: root.label; color: TempoTheme.text-secondary; font-size: TempoTokens.text-sm; font-weight: 600; + text: root.label; color: TempoTheme.text-secondary; font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; } Rectangle { height: 36px; @@ -602,7 +635,7 @@ export component TempoSpinBox inherits VerticalLayout { border-color: spin-keys.has-focus ? TempoTheme.primary : TempoTheme.border; background: root.enabled ? TempoTheme.surface : TempoTheme.surface-alt; clip: true; - animate border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } spin-keys := TempoControlFocus { enabled: root.enabled; handle-key(e) => { @@ -617,11 +650,11 @@ export component TempoSpinBox inherits VerticalLayout { width: 34px; enabled: root.enabled && root.value > root.minimum; background: self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.step-by(-root.step); } Text { text: "−"; - font-size: 16px; font-weight: 600; + font-size: (16px) * TempoTokens.text-scale(1rem); font-weight: 600; color: parent.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; horizontal-alignment: center; vertical-alignment: center; } @@ -630,7 +663,7 @@ export component TempoSpinBox inherits VerticalLayout { Text { horizontal-stretch: 1; text: root.value; - font-size: TempoTokens.text-md; + font-size: (TempoTokens.text-md) * TempoTokens.text-scale(1rem); font-weight: 600; color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; horizontal-alignment: center; @@ -642,11 +675,11 @@ export component TempoSpinBox inherits VerticalLayout { width: 34px; enabled: root.enabled && root.value < root.maximum; background: self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.step-by(root.step); } Text { text: "+"; - font-size: 16px; font-weight: 600; + font-size: (16px) * TempoTokens.text-scale(1rem); font-weight: 600; color: parent.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; horizontal-alignment: center; vertical-alignment: center; } @@ -686,7 +719,7 @@ export component TempoBadge inherits Rectangle { visible: !root.dot-only; text: root.dot-only ? "" : root.badge-text; color: #F8FAFC; - font-size: 10px; + font-size: (10px) * TempoTokens.text-scale(1rem); font-weight: 700; horizontal-alignment: center; vertical-alignment: center; @@ -711,7 +744,7 @@ export component TempoChip inherits TempoAction { : root.selected ? (root.pressed || root.hovered ? TempoTheme.primary-subtle : TempoTheme.primary-soft) : root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : TempoTheme.surface; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { if root.selectable { root.selected = !root.selected; @@ -730,10 +763,11 @@ export component TempoChip inherits TempoAction { } Text { text: root.label; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: root.selected ? 600 : 500; color: !root.enabled ? TempoTheme.text-disabled : root.selected ? TempoTheme.primary : TempoTheme.text-primary; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } if root.closable : TempoIconButton { label: "Remove " + root.label; @@ -764,18 +798,22 @@ export component TempoRate inherits HorizontalLayout { height: 26px; border-radius: TempoTokens.radius-xs; background: self.hovered && root.enabled ? TempoTheme.surface-alt : transparent; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.value = rank; root.changed-value(rank); } Path { - width: 18px; height: 18px; + width: star.pressed ? 16px : filled ? 19px : 18px; + height: self.width; x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; viewbox-width: 24; viewbox-height: 24; fill: filled ? TempoTheme.warning : transparent; stroke: filled ? TempoTheme.warning : TempoTheme.border-strong; stroke-width: 1.6px; + animate fill, stroke { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: cubic-bezier(0.34, 1.4, 0.64, 1.0); } MoveTo { x: 12; y: 2.5; } LineTo { x: 14.9; y: 8.4; } LineTo { x: 21.4; y: 9.3; } @@ -794,10 +832,14 @@ export component TempoRate inherits HorizontalLayout { export component TempoSkeleton inherits Rectangle { in property bar-height: 14px; in property circle: false; + in property animated: true; height: root.bar-height; width: root.circle ? root.bar-height : 120px; border-radius: root.circle ? TempoTokens.radius-full : TempoTokens.radius-xs; background: TempoTheme.surface-pressed; + opacity: root.animated && !TempoMotionSettings.reduced + ? 0.55 + 0.45 * (0.5 + 0.5 * sin(360deg * mod(animation-tick(), 1.6s) / 1.6s)) + : 1.0; } export component TempoSplitButton inherits Rectangle { @@ -821,7 +863,7 @@ export component TempoSplitButton inherits Rectangle { background: !root.enabled ? transparent : root.primary-style ? (self.pressed ? TempoTheme.primary-pressed : self.hovered ? TempoTheme.primary-hover : transparent) : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.activated(); } HorizontalLayout { padding-left: 12px; padding-right: 12px; @@ -834,7 +876,7 @@ export component TempoSplitButton inherits Rectangle { } Text { text: root.label; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: 600; color: !root.enabled ? TempoTheme.text-disabled : root.primary-style ? TempoTheme.text-inverse : TempoTheme.text-primary; } @@ -851,7 +893,7 @@ export component TempoSplitButton inherits Rectangle { background: !root.enabled ? transparent : root.primary-style ? (self.pressed ? TempoTheme.primary-pressed : self.hovered ? TempoTheme.primary-hover : transparent) : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.menu-requested(); } TempoIcon { source: TempoIcons.chevron-down; @@ -868,18 +910,20 @@ export component TempoLink inherits TempoAction { preferred-width: inner.preferred-width; border-radius: TempoTokens.radius-xs; background: self.pressed ? TempoTheme.primary-soft : transparent; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } inner := HorizontalLayout { padding-left: 4px; padding-right: 4px; spacing: TempoTokens.gap4; cross-axis-alignment: center; Text { text: root.label; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: 600; color: !root.enabled ? TempoTheme.text-disabled : root.pressed ? TempoTheme.primary-pressed : root.hovered ? TempoTheme.primary-hover : TempoTheme.primary; vertical-alignment: center; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } if root.external : TempoIcon { source: TempoIcons.open; @@ -900,7 +944,7 @@ export component TempoKeyCap inherits Rectangle { lbl := Text { text: root.text; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-xs; + font-size: (TempoTokens.text-xs) * TempoTokens.text-scale(1rem); font-weight: 700; horizontal-alignment: center; vertical-alignment: center; @@ -962,7 +1006,7 @@ export component TempoRangeSlider inherits Rectangle { y: (parent.height - self.height) / 2; border-radius: self.width / 2; background: root.enabled ? TempoTheme.primary : TempoTheme.text-disabled; - animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: cubic-bezier(0.34, 1.35, 0.64, 1.0); } } } // High thumb @@ -981,7 +1025,7 @@ export component TempoRangeSlider inherits Rectangle { y: (parent.height - self.height) / 2; border-radius: self.width / 2; background: root.enabled ? TempoTheme.primary : TempoTheme.text-disabled; - animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: cubic-bezier(0.34, 1.35, 0.64, 1.0); } } } touch := TouchArea { @@ -1020,7 +1064,7 @@ export component TempoStatusDot inherits HorizontalLayout { if root.label != "" : Text { text: root.label; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; } } diff --git a/ui/index.slint b/ui/index.slint index 3e7e891..a6f3aec 100644 --- a/ui/index.slint +++ b/ui/index.slint @@ -5,6 +5,6 @@ export { TempoDivider, TempoCard, TempoInfoBar, TempoExpander, TempoPagination, export { TempoIcons } from "icons.slint"; export { TempoChoice, TempoComboBox, TempoDialog, TempoDialogAction, TempoSheet, TempoDrawer, TempoPopover, TempoDatePicker, TempoTimePicker, TempoImageViewer, TempoToastHost, TempoToastType } from "overlays.slint"; export { TempoFloatingActionButton, TempoGroupTab, TempoButtonGroupTabBar, TempoRefresh, TempoRefreshState, TempoRefreshText, TempoRefreshLabels } from "auxiliary.slint"; -export { TempoInsets, TempoNavigationContent, TempoAppBar, TempoPageHead, TempoPage, TempoNavigationShell, TempoAdaptiveSplit, TempoDetailPresentation, TempoSplitPane } from "layout.slint"; +export { TempoInsets, TempoWindow, TempoSafeArea, TempoBackHandler, TempoNavigationContent, TempoAppBar, TempoPageHead, TempoPage, TempoNavigationShell, TempoAdaptiveSplit, TempoDetailPresentation, TempoSplitPane } from "layout.slint"; export { TempoVirtualList, TempoIndexedStack, TempoStackPage, TempoMenuEntry, TempoMenuButton, TempoReorderItem, TempoReorderList } from "primitives.slint"; export { TempoMotionSettings, TempoPresence, TempoRouteMotion, TempoRouteTransition } from "motion.slint"; diff --git a/ui/layout.slint b/ui/layout.slint index fdbd2a0..d5aec93 100644 --- a/ui/layout.slint +++ b/ui/layout.slint @@ -1,49 +1,83 @@ import { ScrollView } from "std-widgets.slint"; import { TempoMotionSettings } from "motion.slint"; import { TempoTheme, TempoTokens } from "theme.slint"; -import { TempoIconButton } from "controls.slint"; +import { TempoIconButton, TempoIconButtonVariant } from "controls.slint"; import { TempoIcons } from "icons.slint"; import { TempoNav, TempoDestination } from "navigation.slint"; export struct TempoInsets { left: length, top: length, right: length, bottom: length } -export component TempoNavigationContent inherits Rectangle { - in property insets; +// Bridge the platform's live window insets to TempoUI's layout components. +export component TempoWindow inherits Window { + in property extra-insets; + out property content-insets: { + left: root.safe-area-insets.left + max(0px, root.extra-insets.left), + top: root.safe-area-insets.top + max(0px, root.extra-insets.top), + right: root.safe-area-insets.right + max(0px, root.extra-insets.right), + bottom: root.safe-area-insets.bottom + max(0px, root.extra-insets.bottom), + }; background: TempoTheme.background; +} + +export component TempoSafeArea inherits Rectangle { + in property insets; + out property content-width: max(0px, root.width - root.insets.left - root.insets.right); + out property content-height: max(0px, root.height - root.insets.top - root.insets.bottom); Rectangle { x: root.insets.left; y: root.insets.top; - width: max(0px, root.width - root.insets.left - root.insets.right); - height: max(0px, root.height - root.insets.top - root.insets.bottom); + width: root.content-width; + height: root.content-height; @children } } +export component TempoNavigationContent inherits TempoSafeArea { + background: TempoTheme.background; +} + +// Back is delivered through Slint's key pipeline on Android. Put the scope +// around page content so focused descendants can give popups first refusal. +export component TempoBackHandler inherits FocusScope { + callback go-back() -> bool; + key-pressed(event) => { + if (event.text == Key.Back || event.text == Key.Escape) && root.go-back() { + return accept; + } + return reject; + } + @children +} + export component TempoAppBar inherits Rectangle { in property title; in property subtitle; in property show-back; + in property show-divider: false; in property back-label: "Back"; + in property back-variant: ghost; callback back(); - height: 58px; - background: TempoTheme.surface; + height: 68px; + background: transparent; accessible-role: banner; HorizontalLayout { padding-left: root.show-back ? 10px : TempoTokens.page-padding; - padding-right: TempoTokens.gap8; + padding-right: TempoTokens.gap10; + padding-top: 8px; + padding-bottom: 6px; spacing: TempoTokens.gap8; cross-axis-alignment: center; if root.show-back : TempoIconButton { - icon: TempoIcons.chevron-left; variant: outline; label: root.back-label; + icon: TempoIcons.chevron-left; variant: root.back-variant; label: root.back-label; activated => { root.back(); } } VerticalLayout { horizontal-stretch: 1; spacing: 2px; - Text { text: root.title; color: TempoTheme.text-primary; font-size: 16px; font-weight: 700; overflow: elide; } - if root.subtitle != "" : Text { text: root.subtitle; color: TempoTheme.text-secondary; font-size: 12px; overflow: elide; } + Text { text: root.title; color: TempoTheme.text-primary; font-size: (19px) * TempoTokens.text-scale(1rem); font-weight: 800; overflow: elide; } + if root.subtitle != "" : Text { text: root.subtitle; color: TempoTheme.text-secondary; font-size: (12px) * TempoTokens.text-scale(1rem); overflow: elide; } } @children } - Rectangle { y: parent.height - 1px; height: 1px; background: TempoTheme.border; } + if root.show-divider : Rectangle { y: parent.height - 1px; height: 1px; background: TempoTheme.border; } } export component TempoPageHead inherits HorizontalLayout { @@ -51,17 +85,18 @@ export component TempoPageHead inherits HorizontalLayout { in property subtitle; in property show-navigation; in property close-instead; + in property back-variant: ghost; callback navigate(); spacing: TempoTokens.gap8; cross-axis-alignment: center; if root.show-navigation : TempoIconButton { icon: root.close-instead ? TempoIcons.close : TempoIcons.chevron-left; - variant: outline; label: root.close-instead ? "Close" : "Back"; + variant: root.back-variant; label: root.close-instead ? "Close" : "Back"; activated => { root.navigate(); } } VerticalLayout { horizontal-stretch: 1; spacing: TempoTokens.gap4; - Text { text: root.title; color: TempoTheme.text-primary; font-size: 22px; font-weight: 800; overflow: elide; } - if root.subtitle != "" : Text { text: root.subtitle; color: TempoTheme.text-secondary; font-size: 12px; font-weight: 500; overflow: elide; } + Text { text: root.title; color: TempoTheme.text-primary; font-size: (22px) * TempoTokens.text-scale(1rem); font-weight: 800; overflow: elide; } + if root.subtitle != "" : Text { text: root.subtitle; color: TempoTheme.text-secondary; font-size: (12px) * TempoTokens.text-scale(1rem); font-weight: 500; overflow: elide; } } @children } @@ -105,7 +140,7 @@ export component TempoNavigationShell inherits Rectangle { animate rail-width { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.motion-medium; - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } callback selected-index(int); callback footer-selected(int); @@ -259,13 +294,14 @@ export component TempoSplitPane inherits Rectangle { width: root.handle-width; height: parent.height; background: handle-touch.pressed || handle-touch.has-hover ? TempoTheme.primary-soft : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } Rectangle { x: (parent.width - self.width) / 2; y: 0px; width: 1px; height: parent.height; background: handle-touch.pressed || handle-touch.has-hover ? TempoTheme.primary : TempoTheme.border; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } Rectangle { x: (parent.width - self.width) / 2; @@ -274,6 +310,7 @@ export component TempoSplitPane inherits Rectangle { height: 28px; border-radius: TempoTokens.radius-full; background: handle-touch.pressed || handle-touch.has-hover ? TempoTheme.primary : TempoTheme.border-strong; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } handle-touch := TouchArea { mouse-cursor: col-resize; diff --git a/ui/motion.slint b/ui/motion.slint index 4705218..77a047e 100644 --- a/ui/motion.slint +++ b/ui/motion.slint @@ -3,6 +3,9 @@ import { TempoTokens } from "theme.slint"; export global TempoMotionSettings { // Slint also respects the native reduced-motion setting on supported backends. in-out property reduced: false; + // On mobile, favor cached layer rendering and shorter travel over heavy shadows. + out property mobile: Platform.os == OperatingSystemType.android || Platform.os == OperatingSystemType.ios; + in-out property lightweight: self.mobile; } /// Page transition presets supporting sibling fade, shared-axis hierarchy, @@ -24,15 +27,30 @@ export component TempoPresence inherits Rectangle { in property active; in property enter-time: TempoTokens.motion-medium; in property exit-time: TempoTokens.motion-short; - out property progress: root.active ? 1.0 : 0.0; + out property progress: 0.0; out property present: root.active || root.progress > 0.0; callback exited(); - animate progress { - enabled: !TempoMotionSettings.reduced; - duration: root.active ? root.enter-time : root.exit-time; - // Emphasized decelerate curve. - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); - } + + states [ + shown when root.active : { + progress: 1.0; + in { + animate progress { + duration: TempoMotionSettings.reduced ? 0ms : root.enter-time; + // Smooth ease-out-cubic deceleration for crisp, gliding entries. + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); + } + } + out { + animate progress { + duration: TempoMotionSettings.reduced ? 0ms : root.exit-time; + // Quick accelerate exit so overlays dismiss cleanly without lingering. + easing: cubic-bezier(0.4, 0.0, 1.0, 1.0); + } + } + } + ] + changed present => { if !root.present { root.exited(); } } } @@ -48,8 +66,9 @@ export component TempoRouteMotion inherits Rectangle { in property direction: 1; in property enabled: true; in property travel: TempoTokens.motion-axis-distance; - in property enter-time: TempoTokens.motion-medium; + in property enter-time: 220ms; private property active-motion: root.enabled && !TempoMotionSettings.reduced && root.transition != TempoRouteTransition.none; + private property effective-travel: min(root.travel, 32px); private property moving: false; private property enter-direction: 1; private property enter-transition: TempoRouteTransition.shared-axis-x; @@ -58,8 +77,8 @@ export component TempoRouteMotion inherits Rectangle { animate enter-progress { enabled: !root.moving && root.active-motion; duration: root.enter-time; - // Emphasized decelerate curve: fast initial response, smooth settle. - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); + // Ease-out-cubic glide matching FinUI/Fluent spatial rhythm. + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } changed route-key => { if root.active-motion { @@ -70,22 +89,28 @@ export component TempoRouteMotion inherits Rectangle { } } kickoff := Timer { - // Give Slint one frame to apply the reset before easing in. + // Give Slint one frame to commit the reset before easing in. interval: 16ms; running: false; triggered => { self.running = false; root.moving = false; } } clip: true; Rectangle { + cache-rendering-hint: root.progress < 0.999; x: root.enter-transition == TempoRouteTransition.shared-axis-x - ? (1.0 - root.progress) * root.travel * root.enter-direction + ? (1.0 - root.progress) * root.effective-travel * root.enter-direction : 0px; y: root.enter-transition == TempoRouteTransition.shared-axis-y - ? (1.0 - root.progress) * root.travel * root.enter-direction + ? (1.0 - root.progress) * root.effective-travel * root.enter-direction : 0px; width: root.width; height: root.height; - opacity: root.active-motion ? root.progress : 1.0; + // Start from subtle non-zero opacity on axis transitions to prevent a white flash. + opacity: root.active-motion + ? (root.enter-transition == TempoRouteTransition.fade-through + ? root.progress + : (TempoMotionSettings.lightweight ? 0.35 + 0.65 * root.progress : 0.15 + 0.85 * root.progress)) + : 1.0; @children } } diff --git a/ui/navigation.slint b/ui/navigation.slint index d06ad0f..1f99833 100644 --- a/ui/navigation.slint +++ b/ui/navigation.slint @@ -50,28 +50,46 @@ export component TempoNavItem inherits TempoAction { : root.active && root.hovered ? TempoTheme.primary-subtle : root.active ? TempoTheme.primary-soft : root.hovered ? TempoTheme.surface-alt : transparent; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } - // Mobile Bottom Bar: clean icon + label (no oval pill background or border) - if root.bottom : VerticalLayout { - alignment: center; - spacing: 4px; - HorizontalLayout { - alignment: center; - TempoNavIcon { - icon: root.visible-icon; - ink: root.icon-ink; - badge: root.badge; - size: 22px; + // Mobile Bottom Bar: Fluent top pill indicator + icon + label + if root.bottom : Rectangle { + // Top pill indicator matching FinUI's FUIBottomTabBar + Rectangle { + x: (parent.width - self.width) / 2; + y: 3px; + width: root.active ? 26px : 0px; + height: 3px; + border-radius: TempoTokens.radius-full; + background: TempoTheme.primary; + opacity: root.active ? 1.0 : 0.0; + animate width, opacity { + enabled: !TempoMotionSettings.reduced; + duration: TempoTokens.fast; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } } - Text { - text: root.label; - color: root.label-ink; - font-size: 11px; - font-weight: root.active ? 700 : 500; - horizontal-alignment: center; - overflow: elide; + VerticalLayout { + alignment: center; + spacing: 4px; + HorizontalLayout { + alignment: center; + TempoNavIcon { + icon: root.visible-icon; + ink: root.icon-ink; + badge: root.badge; + size: 22px; + } + } + Text { + text: root.label; + color: root.label-ink; + font-size: (11px) * TempoTokens.text-scale(1rem); + font-weight: root.active ? 700 : 500; + horizontal-alignment: center; + overflow: elide; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + } } } @@ -90,12 +108,13 @@ export component TempoNavItem inherits TempoAction { y: (parent.height - self.height) / 2; width: 3px; height: root.active ? 18px : 0px; + opacity: root.active ? 1.0 : 0.0; border-radius: TempoTokens.radius-full; background: TempoTheme.primary; - animate height { + animate height, opacity { enabled: !TempoMotionSettings.reduced; - duration: TempoTokens.motion-short; - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); + duration: TempoTokens.fast; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } } } @@ -103,10 +122,11 @@ export component TempoNavItem inherits TempoAction { Text { text: root.label; color: root.label-ink; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: root.active ? 700 : 500; overflow: elide; horizontal-stretch: 1; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } @@ -118,12 +138,13 @@ export component TempoNavItem inherits TempoAction { y: (parent.height - self.height) / 2; width: 3px; height: root.active ? 20px : 0px; + opacity: root.active ? 1.0 : 0.0; border-radius: TempoTokens.radius-full; background: TempoTheme.primary; - animate height { + animate height, opacity { enabled: !TempoMotionSettings.reduced; - duration: TempoTokens.motion-short; - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); + duration: TempoTokens.fast; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } } VerticalLayout { @@ -135,10 +156,11 @@ export component TempoNavItem inherits TempoAction { Text { text: root.label; color: root.label-ink; - font-size: 10px; + font-size: (10px) * TempoTokens.text-scale(1rem); font-weight: root.active ? 700 : 500; horizontal-alignment: center; overflow: elide; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } } diff --git a/ui/overlays.slint b/ui/overlays.slint index bbc9835..9422891 100644 --- a/ui/overlays.slint +++ b/ui/overlays.slint @@ -18,8 +18,10 @@ export component TempoComboBox inherits VerticalLayout { in property sheet-origin; in property bottom-inset; callback selected-index(int); - out property opened: popup.is-open; + out property opened: root.open-state || open-kickoff.running; private property highlighted: -1; + private property open-state: false; + private property popup-open: popup.is-open; in property use-bottom-sheet: false; out property is-bottom-sheet: root.use-bottom-sheet && root.sheet-width > 0px && root.sheet-height > 0px; private property popup-gap: TempoTokens.gap4; @@ -38,52 +40,102 @@ export component TempoComboBox inherits VerticalLayout { spacing: TempoTokens.gap6; public function open() { if root.enabled && root.items.length > 0 { + close-timer.running = false; root.highlighted = root.valid ? root.selected : 0; - popup.show(); + if !popup.is-open { + popup.show(); + if TempoMotionSettings.reduced { + root.open-state = true; + } else { + open-kickoff.running = true; + } + } else { + root.open-state = true; + } + } + } + public function close() { + open-kickoff.running = false; + if root.is-bottom-sheet && root.open-state { + root.open-state = false; + if !entry-motion.present { close-timer.running = true; } + } else { + root.open-state = false; + if popup.is-open { popup.close(); } } } - public function close() { popup.close(); } function move(delta: int) { if root.items.length > 0 { root.highlighted = clamp(root.highlighted + delta, 0, root.items.length - 1); } } function choose(index: int) { if index >= 0 && index < root.items.length && root.items[index].enabled { root.selected = index; - popup.close(); + root.close(); root.selected-index(index); } } + changed popup-open => { + if !root.popup-open { + open-kickoff.running = false; + root.open-state = false; + } + } if root.label != "" : Text { - text: root.label; color: TempoTheme.text-secondary; font-size: 12px; font-weight: 600; + text: root.label; color: TempoTheme.text-secondary; font-size: (12px) * TempoTokens.text-scale(1rem); font-weight: 600; } trigger := TempoAction { label: root.label != "" ? root.label : root.placeholder; enabled: root.enabled; accessible-role: combobox; accessible-expandable: true; - accessible-expanded: popup.is-open; + accessible-expanded: root.opened; accessible-action-expand => { root.open(); } accessible-value: root.valid ? root.items[root.selected].label : ""; height: TempoTokens.input-height; background: self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : TempoTheme.surface; border-radius: TempoTokens.radius-md; border-width: 1px; - border-color: popup.is-open ? TempoTheme.primary : self.hovered ? TempoTheme.border-strong : TempoTheme.border; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } - activated => { if popup.is-open { root.close(); } else { root.open(); } } + border-color: root.opened ? TempoTheme.primary : self.hovered ? TempoTheme.border-strong : TempoTheme.border; + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + activated => { if root.opened { root.close(); } else { root.open(); } } HorizontalLayout { padding-left: 12px; padding-right: 12px; spacing: 8px; cross-axis-alignment: center; Text { text: root.valid ? root.items[root.selected].label : root.placeholder; - horizontal-stretch: 1; font-size: 14px; overflow: elide; + horizontal-stretch: 1; font-size: (14px) * TempoTokens.text-scale(1rem); overflow: elide; color: !root.enabled ? TempoTheme.text-disabled : root.valid ? TempoTheme.text-primary : TempoTheme.text-tertiary; } - TempoIcon { source: popup.is-open ? TempoIcons.chevron-up : TempoIcons.chevron-down; width: 18px; height: 18px; } + TempoIcon { + source: TempoIcons.chevron-down; + width: 18px; height: 18px; + tint: root.opened ? TempoTheme.primary : TempoTheme.text-secondary; + transform-rotation: root.opened ? 180deg : 0deg; + animate transform-rotation { + enabled: !TempoMotionSettings.reduced; + duration: TempoTokens.normal; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); + } + } + } + entry-motion := TempoPresence { + active: root.open-state; + enter-time: root.is-bottom-sheet ? 220ms : TempoTokens.motion-short; + exit-time: root.is-bottom-sheet ? 160ms : 110ms; + exited => { if !root.open-state { close-timer.running = true; } } + open-kickoff := Timer { + interval: 16ms; + running: false; + triggered => { self.running = false; if popup.is-open { root.open-state = true; } } + } + close-timer := Timer { + interval: 1ms; + running: false; + triggered => { self.running = false; if !root.open-state && popup.is-open { popup.close(); } } + } } } - entry-motion := TempoPresence { active: popup.is-open; enter-time: root.is-bottom-sheet ? 240ms : TempoTokens.motion-short; } popup := PopupWindow { x: root.is-bottom-sheet ? root.sheet-origin.x - root.absolute-position.x : 0px; y: root.is-bottom-sheet ? root.sheet-origin.y - root.absolute-position.y @@ -106,6 +158,7 @@ export component TempoComboBox inherits VerticalLayout { } TempoSurface { elevated: true; + cache-rendering-hint: entry-motion.progress < 0.999; width: parent.width; height: root.panel-height; x: 0px; @@ -138,7 +191,7 @@ export component TempoComboBox inherits VerticalLayout { : self.highlighted ? TempoTheme.surface-alt : self.pressed && item.enabled ? TempoTheme.surface-pressed : self.hovered && item.enabled ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.choose(i); } // Left accent pill on selected item if i == root.selected : Rectangle { @@ -151,7 +204,7 @@ export component TempoComboBox inherits VerticalLayout { } Text { x: 14px; width: parent.width - 26px; height: parent.height; - vertical-alignment: center; overflow: elide; text: item.label; font-size: 13px; + vertical-alignment: center; overflow: elide; text: item.label; font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: i == root.selected ? 600 : 400; color: !item.enabled ? TempoTheme.text-disabled : i == root.selected ? TempoTheme.primary : TempoTheme.text-primary; } @@ -175,9 +228,16 @@ export component TempoDialog inherits Rectangle { in property panel-width: 520px; in property bottom-sheet; in property bottom-inset; + in property sheet-width; + in property sheet-height; + in property sheet-origin; in property <[TempoDialogAction]> actions; + private property has-sheet-bounds: root.sheet-width > 0px && root.sheet-height > 0px; + private property overlay-width: root.has-sheet-bounds ? root.sheet-width : root.width; + private property overlay-height: root.has-sheet-bounds ? root.sheet-height : root.height; private property has-actions: root.actions.length > 0 || root.confirm-label != "" || root.cancel-label != ""; - out property opened: false; + private property open-state: false; + out property opened: root.open-state || open-kickoff.running; out property presented: modal.is-open; out property motion-progress: presence.progress; callback action-selected(int); @@ -185,30 +245,63 @@ export component TempoDialog inherits Rectangle { callback cancelled(); callback dismissed(); public function show() { - if !modal.is-open { modal.show(); } - root.opened = true; + close-timer.running = false; + if !modal.is-open { + modal.show(); + if TempoMotionSettings.reduced { + root.open-state = true; + } else { + open-kickoff.running = true; + } + } else { + root.open-state = true; + } } public function close() { - if root.opened { - root.opened = false; - if !presence.present { modal.close(); } + open-kickoff.running = false; + if root.open-state { + root.open-state = false; + if !presence.present { close-timer.running = true; } + } else if modal.is-open { + close-timer.running = true; + } + } + open-kickoff := Timer { + interval: 16ms; + running: false; + triggered => { + self.running = false; + if modal.is-open { root.open-state = true; } } } changed presented => { if !root.presented { - root.opened = false; + open-kickoff.running = false; + root.open-state = false; root.dismissed(); } } presence := TempoPresence { - active: root.opened; - enter-time: root.bottom-sheet ? 240ms : 200ms; - exit-time: root.bottom-sheet ? 170ms : 130ms; - exited => { if !root.opened { modal.close(); } } + active: root.open-state; + enter-time: root.bottom-sheet ? 230ms : TempoTokens.motion-medium; + exit-time: root.bottom-sheet ? 160ms : TempoTokens.motion-short; + exited => { if !root.open-state { close-timer.running = true; } } } + // Tear down outside the child button's activation callback. + close-timer := Timer { + interval: 1ms; + running: false; + triggered => { + self.running = false; + if !root.open-state && modal.is-open { modal.close(); } + } + } modal := PopupWindow { - x: 0px; y: 0px; width: root.width; height: root.height; + x: root.has-sheet-bounds ? root.sheet-origin.x - root.absolute-position.x : 0px; + y: root.has-sheet-bounds ? root.sheet-origin.y - root.absolute-position.y : 0px; + width: root.overlay-width; + height: root.overlay-height; close-policy: no-auto-close; forward-focus: keys; keys := FocusScope { @@ -221,20 +314,26 @@ export component TempoDialog inherits Rectangle { Rectangle { background: #0007.with-alpha(0.47 * presence.progress); } TouchArea { clicked => { if root.dismiss-on-backdrop { root.close(); } } } TempoSurface { - elevated: true; + elevated: !TempoMotionSettings.lightweight; + cache-rendering-hint: presence.progress < 0.999; opacity: root.bottom-sheet ? 1 : presence.progress; - width: min(root.panel-width, max(0px, root.width - 32px)); - x: (root.width - self.width) / 2; - height: min(root.height - 32px, panel.preferred-height); + width: root.bottom-sheet + ? min(root.panel-width, root.overlay-width) + : min(root.panel-width, max(0px, root.overlay-width - 32px)); + x: (root.overlay-width - self.width) / 2; + height: root.bottom-sheet + ? min(max(0px, root.overlay-height - 32px), panel.preferred-height + root.bottom-inset) + : min(max(0px, root.overlay-height - 32px), panel.preferred-height); y: root.bottom-sheet - ? root.height - (self.height + 12px + root.bottom-inset) * presence.progress - : (root.height - self.height) / 2 + 12px * (1.0 - presence.progress); + ? root.overlay-height - self.height + (1.0 - presence.progress) * (TempoMotionSettings.lightweight ? min(self.height, 160px) : self.height) + : (root.overlay-height - self.height) / 2 + 12px * (1.0 - presence.progress); border-radius: root.bottom-sheet ? TempoTokens.radius-xl : TempoTokens.radius-lg; clip: true; accessible-role: groupbox; accessible-label: root.title; // Intercept backdrop presses below the panel without blocking its controls. TouchArea {} panel := VerticalLayout { + padding-bottom: root.bottom-sheet ? root.bottom-inset : 0px; if root.bottom-sheet : HorizontalLayout { alignment: center; padding-top: 8px; @@ -267,14 +366,14 @@ export component TempoDialog inherits Rectangle { Text { text: root.title; color: TempoTheme.text-primary; - font-size: 16px; + font-size: (16px) * TempoTokens.text-scale(1rem); font-weight: 700; wrap: word-wrap; } if root.subtitle != "" : Text { text: root.subtitle; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); wrap: word-wrap; } } @@ -289,7 +388,7 @@ export component TempoDialog inherits Rectangle { } ScrollView { vertical-stretch: 1; - preferred-height: min(260px, inner.preferred-height); + preferred-height: min(max(260px, root.overlay-height * 0.58), inner.preferred-height); content-width: self.visible-width; content-height: inner.preferred-height; inner := VerticalLayout { @@ -327,10 +426,52 @@ export component TempoDialog inherits Rectangle { } } -export component TempoSheet inherits TempoDialog { - bottom-sheet: true; - confirm-label: ""; - cancel-label: ""; +export component TempoSheet inherits Rectangle { + in property title; + in property subtitle; + in property icon; + in property confirm-label: ""; + in property cancel-label: ""; + in property destructive; + in property dismiss-on-backdrop: true; + in property panel-width: 520px; + in property bottom-inset; + in property sheet-width; + in property sheet-height; + in property sheet-origin; + in property <[TempoDialogAction]> actions; + out property opened: dialog.opened; + out property presented: dialog.presented; + out property motion-progress: dialog.motion-progress; + callback action-selected(int); + callback confirmed(); + callback cancelled(); + callback dismissed(); + public function show() { dialog.show(); } + public function close() { dialog.close(); } + dialog := TempoDialog { + width: root.width; + height: root.height; + title: root.title; + subtitle: root.subtitle; + icon: root.icon; + confirm-label: root.confirm-label; + cancel-label: root.cancel-label; + destructive: root.destructive; + dismiss-on-backdrop: root.dismiss-on-backdrop; + panel-width: root.panel-width; + bottom-sheet: true; + bottom-inset: root.bottom-inset; + sheet-width: root.sheet-width; + sheet-height: root.sheet-height; + sheet-origin: root.sheet-origin; + actions: root.actions; + action-selected(i) => { root.action-selected(i); } + confirmed => { root.confirmed(); } + cancelled => { root.cancelled(); } + dismissed => { root.dismissed(); } + @children + } } export enum TempoToastType { info, success, warning, error } @@ -363,15 +504,20 @@ export component TempoToastHost inherits Rectangle { root.showing = false; } expiry := Timer { running: false; interval: 2s; triggered => { root.dismiss(); } } - presence := TempoPresence { active: root.showing; } - private property desktop-growl: root.width >= TempoTokens.rail-breakpoint; + presence := TempoPresence { + active: root.showing; + enter-time: TempoTokens.normal; + exit-time: TempoTokens.fast; + } + private property desktop-growl: !TempoMotionSettings.mobile && root.width >= TempoTokens.rail-breakpoint; // Desktop: top-right notification card if presence.present && root.desktop-growl : TempoSurface { elevated: true; clip: true; + cache-rendering-hint: presence.progress < 0.999; width: min(360px, max(240px, root.width - 32px - root.left-inset - root.right-inset)); height: max(46px, desktop-body.preferred-height); - x: root.width - root.right-inset - self.width - 16px + (1.0 - presence.progress) * 16px; + x: root.width - root.right-inset - self.width - 16px + (1.0 - presence.progress) * 18px; y: 16px; border-radius: TempoTokens.radius-md; opacity: presence.progress; @@ -403,14 +549,14 @@ export component TempoToastHost inherits Rectangle { if root.headline != "" : Text { text: root.headline; color: TempoTheme.text-primary; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: 700; overflow: elide; } if root.message != "" : Text { text: root.message; color: root.headline != "" ? TempoTheme.text-secondary : TempoTheme.text-primary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: root.headline != "" ? 400 : 600; wrap: word-wrap; } @@ -423,12 +569,13 @@ export component TempoToastHost inherits Rectangle { } // Mobile / compact: concise bottom-centered bar with restrained radius if presence.present && !root.desktop-growl : TempoSurface { - elevated: true; + elevated: !TempoMotionSettings.lightweight; clip: true; + cache-rendering-hint: presence.progress < 0.999; width: max(0px, min(420px, mobile-body.preferred-width, root.width - 28px - root.left-inset - root.right-inset)); height: 42px; x: root.left-inset + (parent.width - self.width - root.left-inset - root.right-inset) / 2; - y: root.height - root.bottom-inset - self.height - 76px + (1.0 - presence.progress) * 16px; + y: root.height - root.bottom-inset - self.height - 76px + (1.0 - presence.progress) * 22px; border-radius: TempoTokens.radius-md; opacity: presence.progress; accessible-role: region; accessible-live-region: polite; @@ -451,7 +598,7 @@ export component TempoToastHost inherits Rectangle { horizontal-stretch: 1; text: root.headline != "" ? root.headline + " · " + root.message : root.message; color: TempoTheme.text-primary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; overflow: elide; } @@ -470,30 +617,61 @@ export component TempoDrawer inherits Rectangle { in property drawer-width: 340px; in property from-left: false; in property dismiss-on-backdrop: true; - out property opened: false; + private property open-state: false; + out property opened: root.open-state || open-kickoff.running; out property presented: modal.is-open; callback dismissed(); public function show() { - if !modal.is-open { modal.show(); } - root.opened = true; + close-timer.running = false; + if !modal.is-open { + modal.show(); + if TempoMotionSettings.reduced { + root.open-state = true; + } else { + open-kickoff.running = true; + } + } else { + root.open-state = true; + } } public function close() { - if root.opened { - root.opened = false; - if !presence.present { modal.close(); } + open-kickoff.running = false; + if root.open-state { + root.open-state = false; + if !presence.present { close-timer.running = true; } + } else if modal.is-open { + close-timer.running = true; + } + } + open-kickoff := Timer { + interval: 16ms; + running: false; + triggered => { + self.running = false; + if modal.is-open { root.open-state = true; } } } changed presented => { if !root.presented { - root.opened = false; + open-kickoff.running = false; + root.open-state = false; root.dismissed(); } } presence := TempoPresence { - active: root.opened; + active: root.open-state; enter-time: TempoTokens.motion-medium; exit-time: TempoTokens.motion-short; - exited => { if !root.opened { modal.close(); } } + exited => { if !root.open-state { close-timer.running = true; } } + } + // Tear down outside the child button's activation callback. + close-timer := Timer { + interval: 1ms; + running: false; + triggered => { + self.running = false; + if !root.open-state && modal.is-open { modal.close(); } + } } modal := PopupWindow { x: 0px; y: 0px; width: root.width; height: root.height; @@ -507,6 +685,7 @@ export component TempoDrawer inherits Rectangle { Rectangle { background: #0B0E14.with-alpha(0.45 * presence.progress); } TouchArea { clicked => { if root.dismiss-on-backdrop { root.close(); } } } Rectangle { + cache-rendering-hint: presence.progress < 0.999; width: min(root.drawer-width, max(0px, root.width - 40px)); height: root.height; x: root.from-left @@ -535,14 +714,14 @@ export component TempoDrawer inherits Rectangle { if root.title != "" : Text { text: root.title; color: TempoTheme.text-primary; - font-size: 16px; + font-size: (16px) * TempoTokens.text-scale(1rem); font-weight: 700; overflow: elide; } if root.subtitle != "" : Text { text: root.subtitle; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); overflow: elide; } } @@ -578,11 +757,50 @@ export component TempoPopover inherits Rectangle { in property title; in property subtitle; in property popover-width: 260px; - out property opened: popup.is-open; - public function show() { popup.show(); } - public function close() { popup.close(); } - public function toggle() { if popup.is-open { popup.close(); } else { popup.show(); } } - presence := TempoPresence { active: popup.is-open; enter-time: TempoTokens.motion-short; } + out property opened: root.open-state || open-kickoff.running; + private property open-state: false; + private property popup-open: popup.is-open; + public function show() { + close-timer.running = false; + if !popup.is-open { + popup.show(); + if TempoMotionSettings.reduced { + root.open-state = true; + } else { + open-kickoff.running = true; + } + } else { + root.open-state = true; + } + } + public function close() { + open-kickoff.running = false; + root.open-state = false; + if popup.is-open { popup.close(); } + } + public function toggle() { if root.opened { root.close(); } else { root.show(); } } + changed popup-open => { + if !root.popup-open { + open-kickoff.running = false; + root.open-state = false; + } + } + open-kickoff := Timer { + interval: 16ms; + running: false; + triggered => { self.running = false; if popup.is-open { root.open-state = true; } } + } + close-timer := Timer { + interval: 1ms; + running: false; + triggered => { self.running = false; if !root.open-state && popup.is-open { popup.close(); } } + } + presence := TempoPresence { + active: root.open-state; + enter-time: TempoTokens.motion-short; + exit-time: 110ms; + exited => { if !root.open-state { close-timer.running = true; } } + } popup := PopupWindow { x: 0px; y: root.height + 6px; @@ -591,6 +809,7 @@ export component TempoPopover inherits Rectangle { close-policy: close-on-click-outside; TempoSurface { elevated: true; + cache-rendering-hint: presence.progress < 0.999; width: parent.width; height: content.preferred-height; y: -6px * (1.0 - presence.progress); @@ -602,13 +821,13 @@ export component TempoPopover inherits Rectangle { if root.title != "" : Text { text: root.title; color: TempoTheme.text-primary; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: 700; } if root.subtitle != "" : Text { text: root.subtitle; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); wrap: word-wrap; } @children @@ -649,7 +868,27 @@ export component TempoDatePicker inherits VerticalLayout { : 0px; spacing: TempoTokens.gap6; if root.label != "" : Text { - text: root.label; color: TempoTheme.text-secondary; font-size: TempoTokens.text-sm; font-weight: 600; + text: root.label; color: TempoTheme.text-secondary; font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; + } + private property open-state: false; + private property popup-open: popup.is-open; + private property is-open: root.open-state || open-kickoff.running; + function open-popup() { + close-timer.running = false; + if !popup.is-open { + popup.show(); + if TempoMotionSettings.reduced { root.open-state = true; } else { open-kickoff.running = true; } + } else { + root.open-state = true; + } + } + function close-popup() { + open-kickoff.running = false; + root.open-state = false; + if popup.is-open { popup.close(); } + } + changed popup-open => { + if !root.popup-open { open-kickoff.running = false; root.open-state = false; } } trigger := TempoAction { label: root.label != "" ? root.label : "Select date"; @@ -657,26 +896,45 @@ export component TempoDatePicker inherits VerticalLayout { height: TempoTokens.input-height; border-radius: TempoTokens.radius-sm; border-width: TempoTokens.border-width; - border-color: popup.is-open ? TempoTheme.primary : self.hovered ? TempoTheme.border-strong : TempoTheme.border; + border-color: root.is-open ? TempoTheme.primary : self.hovered ? TempoTheme.border-strong : TempoTheme.border; background: self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : TempoTheme.surface; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } - activated => { if popup.is-open { popup.close(); } else { popup.show(); } } + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + activated => { if root.is-open { root.close-popup(); } else { root.open-popup(); } } HorizontalLayout { padding-left: 12px; padding-right: 12px; spacing: TempoTokens.gap8; cross-axis-alignment: center; - TempoIcon { source: TempoIcons.calendar; tint: popup.is-open ? TempoTheme.primary : TempoTheme.text-secondary; width: 18px; height: 18px; } + TempoIcon { source: TempoIcons.calendar; tint: root.is-open ? TempoTheme.primary : TempoTheme.text-secondary; width: 18px; height: 18px; } Text { horizontal-stretch: 1; text: root.value-text; color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; - font-size: TempoTokens.text-md; + font-size: (TempoTokens.text-md) * TempoTokens.text-scale(1rem); overflow: elide; } - TempoIcon { source: popup.is-open ? TempoIcons.chevron-up : TempoIcons.chevron-down; width: 16px; height: 16px; } + TempoIcon { + source: TempoIcons.chevron-down; + width: 16px; height: 16px; + tint: root.is-open ? TempoTheme.primary : TempoTheme.text-secondary; + transform-rotation: root.is-open ? 180deg : 0deg; + animate transform-rotation { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.normal; easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } + } + } + motion := TempoPresence { + active: root.open-state; + enter-time: TempoTokens.motion-short; + exit-time: 110ms; + exited => { if !root.open-state { close-timer.running = true; } } + open-kickoff := Timer { + interval: 16ms; running: false; + triggered => { self.running = false; if popup.is-open { root.open-state = true; } } + } + close-timer := Timer { + interval: 1ms; running: false; + triggered => { self.running = false; if !root.open-state && popup.is-open { popup.close(); } } + } } } - motion := TempoPresence { active: popup.is-open; enter-time: TempoTokens.motion-short; } popup := PopupWindow { x: root.clamped-x; y: root.opens-above ? trigger.y - cal.preferred-height - 4px : trigger.y + trigger.height + 4px; @@ -685,6 +943,7 @@ export component TempoDatePicker inherits VerticalLayout { close-policy: close-on-click-outside; cal := TempoCalendar { elevated: true; + cache-rendering-hint: motion.progress < 0.999; width: parent.width; y: (root.opens-above ? 6px : -6px) * (1.0 - motion.progress); opacity: motion.progress; @@ -694,7 +953,7 @@ export component TempoDatePicker inherits VerticalLayout { today: root.today; selected-day <=> root.selected-day; day-selected(d) => { - popup.close(); + root.close-popup(); root.day-selected(d); } prev-month => { root.prev-month(); } @@ -729,7 +988,27 @@ export component TempoTimePicker inherits VerticalLayout { : 0px; spacing: TempoTokens.gap6; if root.label != "" : Text { - text: root.label; color: TempoTheme.text-secondary; font-size: TempoTokens.text-sm; font-weight: 600; + text: root.label; color: TempoTheme.text-secondary; font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; + } + private property open-state: false; + private property popup-open: popup.is-open; + private property is-open: root.open-state || open-kickoff.running; + function open-popup() { + close-timer.running = false; + if !popup.is-open { + popup.show(); + if TempoMotionSettings.reduced { root.open-state = true; } else { open-kickoff.running = true; } + } else { + root.open-state = true; + } + } + function close-popup() { + open-kickoff.running = false; + root.open-state = false; + if popup.is-open { popup.close(); } + } + changed popup-open => { + if !root.popup-open { open-kickoff.running = false; root.open-state = false; } } trigger := TempoAction { label: root.label != "" ? root.label : "Select time"; @@ -737,26 +1016,45 @@ export component TempoTimePicker inherits VerticalLayout { height: TempoTokens.input-height; border-radius: TempoTokens.radius-sm; border-width: TempoTokens.border-width; - border-color: popup.is-open ? TempoTheme.primary : self.hovered ? TempoTheme.border-strong : TempoTheme.border; + border-color: root.is-open ? TempoTheme.primary : self.hovered ? TempoTheme.border-strong : TempoTheme.border; background: self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : TempoTheme.surface; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } - activated => { if popup.is-open { popup.close(); } else { popup.show(); } } + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + activated => { if root.is-open { root.close-popup(); } else { root.open-popup(); } } HorizontalLayout { padding-left: 12px; padding-right: 12px; spacing: TempoTokens.gap8; cross-axis-alignment: center; - TempoIcon { source: TempoIcons.schedule; tint: popup.is-open ? TempoTheme.primary : TempoTheme.text-secondary; width: 18px; height: 18px; } + TempoIcon { source: TempoIcons.schedule; tint: root.is-open ? TempoTheme.primary : TempoTheme.text-secondary; width: 18px; height: 18px; } Text { horizontal-stretch: 1; text: root.formatted; color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; - font-size: TempoTokens.text-md; + font-size: (TempoTokens.text-md) * TempoTokens.text-scale(1rem); font-weight: 600; } - TempoIcon { source: popup.is-open ? TempoIcons.chevron-up : TempoIcons.chevron-down; width: 16px; height: 16px; } + TempoIcon { + source: TempoIcons.chevron-down; + width: 16px; height: 16px; + tint: root.is-open ? TempoTheme.primary : TempoTheme.text-secondary; + transform-rotation: root.is-open ? 180deg : 0deg; + animate transform-rotation { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.normal; easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } + } + } + motion := TempoPresence { + active: root.open-state; + enter-time: TempoTokens.motion-short; + exit-time: 110ms; + exited => { if !root.open-state { close-timer.running = true; } } + open-kickoff := Timer { + interval: 16ms; running: false; + triggered => { self.running = false; if popup.is-open { root.open-state = true; } } + } + close-timer := Timer { + interval: 1ms; running: false; + triggered => { self.running = false; if !root.open-state && popup.is-open { popup.close(); } } + } } } - motion := TempoPresence { active: popup.is-open; enter-time: TempoTokens.motion-short; } popup := PopupWindow { x: root.clamped-x; y: root.opens-above ? trigger.y - panel.preferred-height - 4px : trigger.y + trigger.height + 4px; @@ -765,6 +1063,7 @@ export component TempoTimePicker inherits VerticalLayout { close-policy: close-on-click-outside; TempoSurface { elevated: true; + cache-rendering-hint: motion.progress < 0.999; width: parent.width; height: panel.preferred-height; y: (root.opens-above ? 6px : -6px) * (1.0 - motion.progress); @@ -794,7 +1093,7 @@ export component TempoTimePicker inherits VerticalLayout { TempoButton { label: "Done"; compact: true; - activated => { popup.close(); } + activated => { root.close-popup(); } } } } @@ -805,24 +1104,57 @@ export component TempoTimePicker inherits VerticalLayout { export component TempoImageViewer inherits Rectangle { in property source; in property title; - out property opened: false; + private property open-state: false; + out property opened: root.open-state || open-kickoff.running; private property zoom: 1.0; + private property animated-zoom: root.zoom; + animate animated-zoom { + enabled: !TempoMotionSettings.reduced; + duration: TempoTokens.normal; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); + } public function show() { root.zoom = 1.0; - if !modal.is-open { modal.show(); } - root.opened = true; + close-timer.running = false; + if !modal.is-open { + modal.show(); + if TempoMotionSettings.reduced { + root.open-state = true; + } else { + open-kickoff.running = true; + } + } else { + root.open-state = true; + } } public function close() { - if root.opened { - root.opened = false; - if !presence.present { modal.close(); } + open-kickoff.running = false; + if root.open-state { + root.open-state = false; + if !presence.present { close-timer.running = true; } + } else if modal.is-open { + close-timer.running = true; } } + open-kickoff := Timer { + interval: 16ms; + running: false; + triggered => { self.running = false; if modal.is-open { root.open-state = true; } } + } presence := TempoPresence { - active: root.opened; + active: root.open-state; enter-time: TempoTokens.motion-medium; exit-time: TempoTokens.motion-short; - exited => { if !root.opened { modal.close(); } } + exited => { if !root.open-state { close-timer.running = true; } } + } + // Tear down outside the child button's activation callback. + close-timer := Timer { + interval: 1ms; + running: false; + triggered => { + self.running = false; + if !root.open-state && modal.is-open { modal.close(); } + } } modal := PopupWindow { x: 0px; y: 0px; width: root.width; height: root.height; @@ -837,6 +1169,7 @@ export component TempoImageViewer inherits Rectangle { TouchArea { clicked => { root.close(); } } TempoSurface { elevated: true; + cache-rendering-hint: presence.progress < 0.999; opacity: presence.progress; width: min(640px, max(240px, root.width - 48px)); height: min(480px, max(220px, root.height - 64px)); @@ -854,7 +1187,7 @@ export component TempoImageViewer inherits Rectangle { horizontal-stretch: 1; text: root.title != "" ? root.title : "Image preview"; color: TempoTheme.text-primary; - font-size: 14px; + font-size: (14px) * TempoTokens.text-scale(1rem); font-weight: 700; overflow: elide; } @@ -868,7 +1201,7 @@ export component TempoImageViewer inherits Rectangle { Text { text: round(root.zoom * 100) + "%"; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; min-width: 40px; horizontal-alignment: center; @@ -896,8 +1229,8 @@ export component TempoImageViewer inherits Rectangle { clip: true; if root.source.width > 0 : Image { source: root.source; - width: parent.width * 0.8 * root.zoom; - height: parent.height * 0.8 * root.zoom; + width: parent.width * 0.8 * root.animated-zoom; + height: parent.height * 0.8 * root.animated-zoom; x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; image-fit: contain; @@ -905,8 +1238,8 @@ export component TempoImageViewer inherits Rectangle { if root.source.width == 0 : TempoIcon { source: TempoIcons.apps; tint: TempoTheme.primary; - width: 72px * root.zoom; - height: 72px * root.zoom; + width: 72px * root.animated-zoom; + height: 72px * root.animated-zoom; } } } diff --git a/ui/patterns.slint b/ui/patterns.slint index 1971cbc..bc8893a 100644 --- a/ui/patterns.slint +++ b/ui/patterns.slint @@ -1,4 +1,4 @@ -import { TempoMotionSettings } from "motion.slint"; +import { TempoMotionSettings, TempoPresence, TempoRouteMotion, TempoRouteTransition } from "motion.slint"; import { ProgressIndicator, ScrollView } from "std-widgets.slint"; import { TempoIcons } from "icons.slint"; import { TempoTheme, TempoTokens } from "theme.slint"; @@ -15,7 +15,7 @@ export component TempoDivider inherits Rectangle { Text { text: root.label; color: TempoTheme.text-tertiary; - font-size: TempoTokens.text-xs; + font-size: (TempoTokens.text-xs) * TempoTokens.text-scale(1rem); font-weight: 600; } Rectangle { horizontal-stretch: 1; height: TempoTokens.border-width; background: TempoTheme.border; } @@ -38,14 +38,14 @@ export component TempoCard inherits TempoSurface { if root.title != "" : Text { text: root.title; color: TempoTheme.text-primary; - font-size: TempoTokens.text-md; + font-size: (TempoTokens.text-md) * TempoTokens.text-scale(1rem); font-weight: 700; overflow: elide; } if root.subtitle != "" : Text { text: root.subtitle; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); overflow: elide; } } @@ -102,14 +102,14 @@ export component TempoInfoBar inherits Rectangle { if root.title != "" : Text { text: root.title; color: TempoTheme.text-primary; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: 700; wrap: word-wrap; } if root.message != "" : Text { text: root.message; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); wrap: word-wrap; } } @@ -129,7 +129,7 @@ export component TempoSection inherits VerticalLayout { if root.title != "" : Text { text: root.title; color: TempoTheme.text-secondary; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: 700; } TempoSurface { @@ -147,7 +147,7 @@ export component TempoTile inherits TempoAction { background: !root.enabled ? transparent : root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } HorizontalLayout { padding-top: 10px; padding-bottom: 10px; padding-left: 14px; padding-right: 14px; @@ -162,10 +162,10 @@ export component TempoTile inherits TempoAction { VerticalLayout { horizontal-stretch: 1; spacing: 2px; - Text { text: root.label; font-size: 14px; font-weight: 600; color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; overflow: elide; } + Text { text: root.label; font-size: (14px) * TempoTokens.text-scale(1rem); font-weight: 600; color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; overflow: elide; } if root.subtitle != "" : Text { text: root.subtitle; color: root.enabled ? TempoTheme.text-tertiary : TempoTheme.text-disabled; - font-size: 12px; overflow: elide; + font-size: (12px) * TempoTokens.text-scale(1rem); overflow: elide; } } if root.trailing-icon.width > 0 : TempoIcon { @@ -188,7 +188,7 @@ export component TempoSelectionTile inherits TempoAction { background: !root.enabled ? transparent : root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.checked = !root.checked; } HorizontalLayout { padding-top: 10px; padding-bottom: 10px; @@ -201,18 +201,25 @@ export component TempoSelectionTile inherits TempoAction { border-width: TempoTokens.border-width; border-color: root.checked ? TempoTheme.primary : TempoTheme.border-strong; background: root.checked ? TempoTheme.primary : TempoTheme.surface; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } - if root.checked : TempoIcon { - source: root.radio-style ? TempoIcons.circle-filled : root.check-icon; tint: TempoTheme.text-inverse; - width: root.radio-style ? 8px : 15px; height: self.width; + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + TempoIcon { + source: root.radio-style ? TempoIcons.circle-filled : root.check-icon; + tint: TempoTheme.text-inverse; + width: root.checked ? (root.radio-style ? 8px : 15px) : 0px; + height: self.width; + x: (parent.width - self.width) / 2; + y: (parent.height - self.height) / 2; + opacity: root.checked ? 1.0 : 0.0; + animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: cubic-bezier(0.34, 1.4, 0.64, 1.0); } + animate opacity { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } VerticalLayout { horizontal-stretch: 1; spacing: 2px; - Text { text: root.label; font-size: 14px; font-weight: 600; color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; overflow: elide; } + Text { text: root.label; font-size: (14px) * TempoTokens.text-scale(1rem); font-weight: 600; color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; overflow: elide; } if root.subtitle != "" : Text { - text: root.subtitle; font-size: 12px; color: TempoTheme.text-secondary; overflow: elide; + text: root.subtitle; font-size: (12px) * TempoTokens.text-scale(1rem); color: TempoTheme.text-secondary; overflow: elide; } } } @@ -235,7 +242,7 @@ export component TempoSwitchTile inherits TempoAction { background: !root.enabled ? transparent : root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.checked = !root.checked; root.toggled(root.checked); @@ -254,10 +261,10 @@ export component TempoSwitchTile inherits TempoAction { VerticalLayout { horizontal-stretch: 1; spacing: 2px; - Text { text: root.label; font-size: TempoTokens.text-md; font-weight: 600; color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; overflow: elide; } + Text { text: root.label; font-size: (TempoTokens.text-md) * TempoTokens.text-scale(1rem); font-weight: 600; color: root.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; overflow: elide; } if root.subtitle != "" : Text { text: root.subtitle; color: root.enabled ? TempoTheme.text-tertiary : TempoTheme.text-disabled; - font-size: TempoTokens.text-sm; overflow: elide; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); overflow: elide; } } TempoSwitch { @@ -296,8 +303,8 @@ export component TempoSegmentedControl inherits Rectangle { drop-shadow-color: TempoTheme.shadow; animate x, width { enabled: !TempoMotionSettings.reduced; - duration: TempoTokens.motion-short; - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); + duration: TempoTokens.normal; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } } HorizontalLayout { @@ -307,12 +314,14 @@ export component TempoSegmentedControl inherits Rectangle { private property active: index == root.selected; private property ink: active ? TempoTheme.text-primary : TempoTheme.text-secondary; horizontal-stretch: 1; + min-width: 0px; + preferred-width: 0px; label: item.label; border-radius: TempoTokens.radius-sm; background: active ? transparent : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface.with-alpha(0.55) : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.selected-index(index); } VerticalLayout { padding-top: 7px; padding-bottom: 7px; @@ -324,9 +333,10 @@ export component TempoSegmentedControl inherits Rectangle { } Text { text: item.label; color: active && item.icon.width > 0 ? TempoTheme.primary : segment.ink; - font-size: item.icon.width > 0 ? TempoTokens.text-xs : 13px; + font-size: (item.icon.width > 0 ? TempoTokens.text-xs : 13px) * TempoTokens.text-scale(1rem); font-weight: segment.active ? 600 : 500; horizontal-alignment: center; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } } @@ -347,7 +357,7 @@ export component TempoProgressBar inherits Rectangle { width: parent.width * clamp(root.value, 0, 1); border-radius: TempoTokens.radius-full; background: TempoTheme.primary; - animate width { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); } + animate width { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.normal; easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } } } @@ -364,9 +374,9 @@ export component TempoEmptyState inherits VerticalLayout { alignment: center; TempoIcon { source: root.icon; tint: TempoTheme.text-tertiary; width: 48px; height: 48px; } } - Text { text: root.title; color: TempoTheme.text-primary; font-size: 16px; font-weight: 600; horizontal-alignment: center; } + Text { text: root.title; color: TempoTheme.text-primary; font-size: (16px) * TempoTokens.text-scale(1rem); font-weight: 600; horizontal-alignment: center; } if root.message != "" : Text { - text: root.message; color: TempoTheme.text-secondary; font-size: 13px; wrap: word-wrap; horizontal-alignment: center; + text: root.message; color: TempoTheme.text-secondary; font-size: (13px) * TempoTokens.text-scale(1rem); wrap: word-wrap; horizontal-alignment: center; } if root.action-label != "" : HorizontalLayout { alignment: center; @@ -388,7 +398,7 @@ export component TempoExpander inherits TempoSurface { label: root.title; min-height: 46px; background: self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.expanded = !root.expanded; root.toggled(root.expanded); @@ -409,21 +419,27 @@ export component TempoExpander inherits TempoSurface { Text { text: root.title; color: TempoTheme.text-primary; - font-size: TempoTokens.text-md; + font-size: (TempoTokens.text-md) * TempoTokens.text-scale(1rem); font-weight: 600; overflow: elide; } if root.subtitle != "" : Text { text: root.subtitle; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); overflow: elide; } } TempoIcon { - source: root.expanded ? TempoIcons.chevron-up : TempoIcons.chevron-down; - tint: TempoTheme.text-secondary; + source: TempoIcons.chevron-down; + tint: root.expanded ? TempoTheme.primary : TempoTheme.text-secondary; width: 18px; height: 18px; + transform-rotation: root.expanded ? 180deg : 0deg; + animate transform-rotation { + enabled: !TempoMotionSettings.reduced; + duration: TempoTokens.normal; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); + } } } } @@ -434,8 +450,8 @@ export component TempoExpander inherits TempoSurface { opacity: root.expanded ? 1.0 : 0.0; animate height, opacity { enabled: !TempoMotionSettings.reduced; - duration: TempoTokens.motion-short; - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); + duration: TempoTokens.motion-medium; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } body := VerticalLayout { x: 0px; y: 0px; width: parent.width; @@ -481,15 +497,16 @@ export component TempoPagination inherits HorizontalLayout { background: active ? TempoTheme.primary : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : TempoTheme.surface; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.select(page-num); } Text { text: page-num; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: active ? 700 : 500; color: active ? TempoTheme.text-inverse : TempoTheme.text-primary; horizontal-alignment: center; vertical-alignment: center; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } TempoIconButton { @@ -526,6 +543,7 @@ export component TempoStepBar inherits HorizontalLayout { border-color: TempoTheme.border-strong; background: done ? TempoTheme.primary-soft : active ? TempoTheme.primary : TempoTheme.surface; + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.normal; easing: ease-out; } if done : TempoIcon { source: TempoIcons.checkmark-small; tint: TempoTheme.primary; @@ -533,7 +551,7 @@ export component TempoStepBar inherits HorizontalLayout { } if !done : Text { text: idx + 1; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 700; color: active ? TempoTheme.text-inverse : TempoTheme.text-secondary; horizontal-alignment: center; @@ -543,7 +561,7 @@ export component TempoStepBar inherits HorizontalLayout { } Text { text: step; - font-size: TempoTokens.text-xs; + font-size: (TempoTokens.text-xs) * TempoTokens.text-scale(1rem); font-weight: idx == root.current ? 700 : 500; color: idx <= root.current ? TempoTheme.text-primary : TempoTheme.text-tertiary; horizontal-alignment: center; @@ -554,6 +572,7 @@ export component TempoStepBar inherits HorizontalLayout { height: 2px; border-radius: 1px; background: idx < root.current ? TempoTheme.primary : TempoTheme.border; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.normal; easing: ease-out; } } } } @@ -580,17 +599,18 @@ export component TempoBreadcrumb inherits HorizontalLayout { border-radius: TempoTokens.radius-xs; background: !is-last && self.pressed ? TempoTheme.surface-pressed : !is-last && self.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.activated(idx); } HorizontalLayout { padding-left: 6px; padding-right: 6px; cross-axis-alignment: center; Text { text: item; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: is-last ? 700 : 500; color: is-last ? TempoTheme.text-primary : crumb.hovered ? TempoTheme.primary : TempoTheme.text-secondary; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } } @@ -622,7 +642,7 @@ export component TempoAvatar inherits Rectangle { if root.source.width == 0 && root.initials != "" : Text { text: root.initials; color: TempoTheme.primary; - font-size: root.size * 0.38; + font-size: (root.size * 0.38) * TempoTokens.text-scale(1rem); font-weight: 700; horizontal-alignment: center; vertical-alignment: center; @@ -665,7 +685,7 @@ export component TempoStatCard inherits TempoSurface { horizontal-stretch: 1; text: root.label; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; overflow: elide; } @@ -679,14 +699,14 @@ export component TempoStatCard inherits TempoSurface { Text { text: root.value; color: TempoTheme.text-primary; - font-size: 22px; + font-size: (22px) * TempoTokens.text-scale(1rem); font-weight: 800; overflow: elide; } if root.hint != "" : Text { text: root.hint; color: root.hint-color; - font-size: TempoTokens.text-xs; + font-size: (TempoTokens.text-xs) * TempoTokens.text-scale(1rem); font-weight: 600; overflow: elide; } @@ -705,7 +725,7 @@ export component TempoProgressRing inherits Rectangle { animate shown { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.motion-medium; - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } private property ring-color: root.variant == success ? TempoTheme.success : root.variant == warning ? TempoTheme.warning @@ -747,7 +767,7 @@ export component TempoProgressRing inherits Rectangle { if root.show-label : Text { text: round(clamp(root.value, 0.0, 1.0) * 100) + "%"; color: TempoTheme.text-primary; - font-size: root.size * 0.22; + font-size: (root.size * 0.22) * TempoTokens.text-scale(1rem); font-weight: 700; horizontal-alignment: center; vertical-alignment: center; @@ -804,20 +824,20 @@ export component TempoTimeline inherits VerticalLayout { horizontal-stretch: 1; text: item.title; color: TempoTheme.text-primary; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: 600; overflow: elide; } if item.time != "" : Text { text: item.time; color: TempoTheme.text-tertiary; - font-size: TempoTokens.text-xs; + font-size: (TempoTokens.text-xs) * TempoTokens.text-scale(1rem); } } if item.subtitle != "" : Text { text: item.subtitle; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); wrap: word-wrap; } } @@ -828,14 +848,15 @@ export component TempoKeyValue inherits HorizontalLayout { in property label; in property value; in property copyable: false; + in property wrap: false; callback copied(string); spacing: TempoTokens.gap12; - cross-axis-alignment: center; + cross-axis-alignment: root.wrap ? start : center; min-height: 30px; Text { text: root.label; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; min-width: 90px; } @@ -843,9 +864,10 @@ export component TempoKeyValue inherits HorizontalLayout { horizontal-stretch: 1; text: root.value; color: TempoTheme.text-primary; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: 500; horizontal-alignment: right; + wrap: root.wrap ? word-wrap : no-wrap; overflow: elide; } if root.copyable : TempoIconButton { @@ -890,7 +912,7 @@ export component TempoBanner inherits Rectangle { horizontal-stretch: 1; text: root.message; color: TempoTheme.text-primary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 500; wrap: word-wrap; } @@ -904,10 +926,44 @@ export component TempoBanner inherits Rectangle { } +component TempoTabBarItem inherits TempoAction { + in property title; + in property active; + out property marker-x: root.x; + out property marker-width: root.width; + callback marker(length, length); + label: root.title; + height: 38px; + preferred-width: inner.preferred-width; + border-radius: TempoTokens.radius-xs; + background: self.pressed ? TempoTheme.surface-pressed + : self.hovered && !root.active ? TempoTheme.surface-alt : transparent; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + init => { if root.active { root.marker(root.x, root.width); } } + changed active => { if root.active { root.marker(root.x, root.width); } } + changed marker-x => { if root.active { root.marker(root.x, root.width); } } + changed marker-width => { if root.active { root.marker(root.x, root.width); } } + inner := HorizontalLayout { + padding-left: 14px; padding-right: 14px; + cross-axis-alignment: center; + Text { + text: root.title; + font-size: (13px) * TempoTokens.text-scale(1rem); + font-weight: root.active ? 700 : 500; + color: root.active ? TempoTheme.primary + : root.hovered ? TempoTheme.text-primary : TempoTheme.text-secondary; + animate color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } + } + } +} + export component TempoTabBar inherits Rectangle { in property <[string]> tabs; in-out property selected: 0; callback selected-index(int); + private property target-x: 0px; + private property target-width: 0px; + private property measured: false; height: 38px; Rectangle { y: parent.height - 1px; @@ -917,44 +973,33 @@ export component TempoTabBar inherits Rectangle { HorizontalLayout { spacing: TempoTokens.gap4; alignment: start; - for title[idx] in root.tabs : tab-item := TempoAction { - private property active: idx == root.selected; - label: title; - height: 38px; - preferred-width: inner.preferred-width; - border-radius: TempoTokens.radius-xs; - background: self.pressed ? TempoTheme.surface-pressed - : self.hovered && !active ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + for title[idx] in root.tabs : TempoTabBarItem { + title: title; + active: idx == root.selected; + marker(x, w) => { + root.target-x = x; + root.target-width = w; + root.measured = true; + } activated => { root.selected = idx; root.selected-index(idx); } - inner := HorizontalLayout { - padding-left: 14px; padding-right: 14px; - cross-axis-alignment: center; - Text { - text: title; - font-size: 13px; - font-weight: active ? 700 : 500; - color: active ? TempoTheme.primary - : tab-item.hovered ? TempoTheme.text-primary : TempoTheme.text-secondary; - } - } - // Bottom active indicator - Rectangle { - x: (parent.width - self.width) / 2; - y: parent.height - 2px; - width: active ? max(0px, parent.width - 16px) : 0px; - height: 2px; - border-radius: 1px; - background: TempoTheme.primary; - animate width { - enabled: !TempoMotionSettings.reduced; - duration: TempoTokens.motion-short; - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); - } - } + } + } + // Continuous sliding bottom indicator + Rectangle { + x: root.target-x + 8px; + y: parent.height - 2px; + width: root.selected >= 0 && root.selected < root.tabs.length ? max(0px, root.target-width - 16px) : 0px; + height: 2px; + border-radius: 1px; + background: TempoTheme.primary; + opacity: root.measured && root.selected >= 0 && root.selected < root.tabs.length ? 1.0 : 0.0; + animate x, width { + enabled: root.measured && !TempoMotionSettings.reduced; + duration: TempoTokens.normal; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } } } @@ -962,10 +1007,16 @@ export component TempoTabBar inherits Rectangle { export component TempoLoadingOverlay inherits Rectangle { in property loading: false; in property message: "Loading…"; - visible: root.loading; + presence := TempoPresence { + active: root.loading; + enter-time: TempoTokens.normal; + exit-time: TempoTokens.fast; + } + visible: presence.present; + opacity: presence.progress; background: TempoTheme.surface.with-alpha(TempoTheme.dark ? 0.78 : 0.82); - if root.loading : TouchArea {} - if root.loading : VerticalLayout { + if presence.present : TouchArea {} + if presence.present : VerticalLayout { alignment: center; cross-axis-alignment: center; spacing: TempoTokens.gap10; @@ -979,7 +1030,7 @@ export component TempoLoadingOverlay inherits Rectangle { if root.message != "" : Text { text: root.message; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; horizontal-alignment: center; } @@ -1007,7 +1058,7 @@ export component TempoTable inherits TempoSurface { horizontal-stretch: 1; text: col; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 700; overflow: elide; } @@ -1024,7 +1075,7 @@ export component TempoTable inherits TempoSurface { : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : (root.zebra && mod(r, 2) == 1) ? TempoTheme.surface-alt.with-alpha(0.45) : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.selected-row = r; root.row-activated(r); @@ -1043,7 +1094,7 @@ export component TempoTable inherits TempoSurface { horizontal-stretch: 1; text: cell; color: active ? TempoTheme.primary : c == 0 ? TempoTheme.text-primary : TempoTheme.text-secondary; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: active || c == 0 ? 600 : 400; overflow: elide; } @@ -1080,7 +1131,7 @@ export component TempoTreeView inherits TempoSurface { background: active ? TempoTheme.primary-soft : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.selected = idx; root.selected-index(idx); @@ -1100,9 +1151,15 @@ export component TempoTreeView inherits TempoSurface { Rectangle { width: 16px; height: 16px; if node.has-children : TempoIcon { - source: node.expanded ? TempoIcons.chevron-down : TempoIcons.chevron-right; + source: TempoIcons.chevron-right; tint: TempoTheme.text-tertiary; width: 14px; height: 14px; + transform-rotation: node.expanded ? 90deg : 0deg; + animate transform-rotation { + enabled: !TempoMotionSettings.reduced; + duration: TempoTokens.fast; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); + } } } if node.icon.width > 0 : TempoIcon { @@ -1114,7 +1171,7 @@ export component TempoTreeView inherits TempoSurface { horizontal-stretch: 1; text: node.label; color: active ? TempoTheme.primary : TempoTheme.text-primary; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: active ? 600 : 400; overflow: elide; } @@ -1137,7 +1194,7 @@ export component TempoColorPicker inherits VerticalLayout { if root.label != "" : Text { text: root.label; color: TempoTheme.text-secondary; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 600; } FlexboxLayout { @@ -1152,14 +1209,21 @@ export component TempoColorPicker inherits VerticalLayout { border-width: active ? 2px : 1px; border-color: active ? TempoTheme.text-primary : swatch.darker(0.15); background: swatch; + animate border-color, border-width { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.value = swatch; root.color-changed(swatch); } - if active : TempoIcon { + TempoIcon { source: TempoIcons.checkmark-small; tint: #F8FAFC; - width: 14px; height: 14px; + width: active ? 14px : 0px; + height: self.width; + x: (parent.width - self.width) / 2; + y: (parent.height - self.height) / 2; + opacity: active ? 1.0 : 0.0; + animate width, height { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: cubic-bezier(0.34, 1.4, 0.64, 1.0); } + animate opacity { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } } } } @@ -1195,7 +1259,7 @@ export component TempoCalendar inherits TempoSurface { horizontal-stretch: 1; text: root.month-label; color: TempoTheme.text-primary; - font-size: 13px; + font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: 700; horizontal-alignment: center; } @@ -1214,7 +1278,7 @@ export component TempoCalendar inherits TempoSurface { horizontal-stretch: 1; text: wd; color: TempoTheme.text-tertiary; - font-size: TempoTokens.text-xs; + font-size: (TempoTokens.text-xs) * TempoTokens.text-scale(1rem); font-weight: 600; horizontal-alignment: center; } @@ -1238,14 +1302,14 @@ export component TempoCalendar inherits TempoSurface { background: is-selected ? TempoTheme.primary : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; - animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.selected-day = day-num; root.day-selected(day-num); } Text { text: day-num; - font-size: TempoTokens.text-sm; + font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: is-selected || is-today ? 700 : 500; color: is-selected ? TempoTheme.text-inverse : is-today ? TempoTheme.primary : TempoTheme.text-primary; @@ -1263,11 +1327,13 @@ export component TempoCarousel inherits TempoSurface { in-out property current: 0; in property viewport-height: 140px; callback changed-index(int); + private property slide-direction: 1; min-width: 200px; function go(idx: int) { if root.count > 0 { let next = mod(idx + root.count, root.count); if next != root.current { + root.slide-direction = idx < root.current ? -1 : 1; root.current = next; root.changed-index(next); } @@ -1278,7 +1344,16 @@ export component TempoCarousel inherits TempoSurface { Rectangle { height: root.viewport-height; clip: true; - @children + TempoRouteMotion { + width: parent.width; + height: parent.height; + route-key: root.current; + transition: TempoRouteTransition.shared-axis-x; + direction: root.slide-direction; + travel: 28px; + enter-time: TempoTokens.motion-medium; + @children + } if root.count > 1 : TempoIconButton { x: 8px; y: (parent.height - self.height) / 2; @@ -1315,8 +1390,8 @@ export component TempoCarousel inherits TempoSurface { : self.hovered ? TempoTheme.text-tertiary : TempoTheme.border-strong; animate width, background { enabled: !TempoMotionSettings.reduced; - duration: TempoTokens.motion-short; - easing: cubic-bezier(0.05, 0.7, 0.1, 1.0); + duration: TempoTokens.normal; + easing: cubic-bezier(0.22, 1.0, 0.36, 1.0); } activated => { root.go(idx); } } @@ -1350,8 +1425,8 @@ export component TempoTransfer inherits Rectangle { HorizontalLayout { padding-left: 12px; padding-right: 12px; cross-axis-alignment: center; - Text { horizontal-stretch: 1; text: root.source-title; color: TempoTheme.text-primary; font-size: TempoTokens.text-sm; font-weight: 700; } - Text { text: root.source-items.length; color: TempoTheme.text-tertiary; font-size: TempoTokens.text-xs; font-weight: 600; } + Text { horizontal-stretch: 1; text: root.source-title; color: TempoTheme.text-primary; font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 700; } + Text { text: root.source-items.length; color: TempoTheme.text-tertiary; font-size: (TempoTokens.text-xs) * TempoTokens.text-scale(1rem); font-weight: 600; } } } TempoDivider {} @@ -1365,10 +1440,11 @@ export component TempoTransfer inherits Rectangle { private property active: i == root.source-selected; label: item; height: 34px; border-radius: TempoTokens.radius-xs; background: active ? TempoTheme.primary-soft : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.source-selected = i; } Text { x: 10px; width: parent.width - 20px; height: parent.height; - vertical-alignment: center; overflow: elide; text: item; font-size: 13px; + vertical-alignment: center; overflow: elide; text: item; font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: active ? 600 : 400; color: active ? TempoTheme.primary : TempoTheme.text-primary; } @@ -1401,8 +1477,8 @@ export component TempoTransfer inherits Rectangle { HorizontalLayout { padding-left: 12px; padding-right: 12px; cross-axis-alignment: center; - Text { horizontal-stretch: 1; text: root.target-title; color: TempoTheme.text-primary; font-size: TempoTokens.text-sm; font-weight: 700; } - Text { text: root.target-items.length; color: TempoTheme.text-tertiary; font-size: TempoTokens.text-xs; font-weight: 600; } + Text { horizontal-stretch: 1; text: root.target-title; color: TempoTheme.text-primary; font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 700; } + Text { text: root.target-items.length; color: TempoTheme.text-tertiary; font-size: (TempoTokens.text-xs) * TempoTokens.text-scale(1rem); font-weight: 600; } } } TempoDivider {} @@ -1416,10 +1492,11 @@ export component TempoTransfer inherits Rectangle { private property active: i == root.target-selected; label: item; height: 34px; border-radius: TempoTokens.radius-xs; background: active ? TempoTheme.primary-soft : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.target-selected = i; } Text { x: 10px; width: parent.width - 20px; height: parent.height; - vertical-alignment: center; overflow: elide; text: item; font-size: 13px; + vertical-alignment: center; overflow: elide; text: item; font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: active ? 600 : 400; color: active ? TempoTheme.primary : TempoTheme.text-primary; } @@ -1438,8 +1515,8 @@ export component TempoTransfer inherits Rectangle { height: 34px; background: TempoTheme.surface-alt; HorizontalLayout { padding-left: 12px; padding-right: 12px; cross-axis-alignment: center; - Text { horizontal-stretch: 1; text: root.source-title; color: TempoTheme.text-primary; font-size: TempoTokens.text-sm; font-weight: 700; } - Text { text: root.source-items.length; color: TempoTheme.text-tertiary; font-size: TempoTokens.text-xs; font-weight: 600; } + Text { horizontal-stretch: 1; text: root.source-title; color: TempoTheme.text-primary; font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 700; } + Text { text: root.source-items.length; color: TempoTheme.text-tertiary; font-size: (TempoTokens.text-xs) * TempoTokens.text-scale(1rem); font-weight: 600; } } } TempoDivider {} @@ -1453,10 +1530,11 @@ export component TempoTransfer inherits Rectangle { private property active: i == root.source-selected; label: item; height: 38px; border-radius: TempoTokens.radius-xs; background: active ? TempoTheme.primary-soft : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.source-selected = i; } Text { x: 10px; width: parent.width - 20px; height: parent.height; - vertical-alignment: center; overflow: elide; text: item; font-size: 13px; + vertical-alignment: center; overflow: elide; text: item; font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: active ? 600 : 400; color: active ? TempoTheme.primary : TempoTheme.text-primary; } @@ -1486,8 +1564,8 @@ export component TempoTransfer inherits Rectangle { height: 34px; background: TempoTheme.surface-alt; HorizontalLayout { padding-left: 12px; padding-right: 12px; cross-axis-alignment: center; - Text { horizontal-stretch: 1; text: root.target-title; color: TempoTheme.text-primary; font-size: TempoTokens.text-sm; font-weight: 700; } - Text { text: root.target-items.length; color: TempoTheme.text-tertiary; font-size: TempoTokens.text-xs; font-weight: 600; } + Text { horizontal-stretch: 1; text: root.target-title; color: TempoTheme.text-primary; font-size: (TempoTokens.text-sm) * TempoTokens.text-scale(1rem); font-weight: 700; } + Text { text: root.target-items.length; color: TempoTheme.text-tertiary; font-size: (TempoTokens.text-xs) * TempoTokens.text-scale(1rem); font-weight: 600; } } } TempoDivider {} @@ -1501,10 +1579,11 @@ export component TempoTransfer inherits Rectangle { private property active: i == root.target-selected; label: item; height: 38px; border-radius: TempoTokens.radius-xs; background: active ? TempoTheme.primary-soft : self.pressed ? TempoTheme.surface-pressed : self.hovered ? TempoTheme.surface-alt : transparent; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.target-selected = i; } Text { x: 10px; width: parent.width - 20px; height: parent.height; - vertical-alignment: center; overflow: elide; text: item; font-size: 13px; + vertical-alignment: center; overflow: elide; text: item; font-size: (13px) * TempoTokens.text-scale(1rem); font-weight: active ? 600 : 400; color: active ? TempoTheme.primary : TempoTheme.text-primary; } diff --git a/ui/primitives.slint b/ui/primitives.slint index d5ab532..e4b93df 100644 --- a/ui/primitives.slint +++ b/ui/primitives.slint @@ -29,9 +29,11 @@ export component TempoMenuButton inherits TempoAction { in property icon: TempoIcons.more; in property outline: false; in property menu-width: 208px; - out property opened: popup.is-open; + out property opened: root.open-state || open-kickoff.running; callback chosen(int); private property highlighted; + private property open-state: false; + private property popup-open: popup.is-open; width: 36px; height: 36px; label: "Actions"; @@ -41,19 +43,60 @@ export component TempoMenuButton inherits TempoAction { background: root.opened || root.pressed ? TempoTheme.surface-pressed : root.hovered ? TempoTheme.surface-alt : root.outline ? TempoTheme.surface : transparent; - animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; } + animate background, border-color { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } accessible-expandable: true; accessible-expanded: root.opened; accessible-action-expand => { root.open(); } - activated => { if root.opened { popup.close(); } else { root.open(); } } - public function open() { if root.enabled && root.items.length > 0 { root.highlighted = 0; popup.show(); } } + activated => { if root.opened { root.close(); } else { root.open(); } } + public function open() { + if root.enabled && root.items.length > 0 { + close-timer.running = false; + root.highlighted = 0; + if !popup.is-open { + popup.show(); + if TempoMotionSettings.reduced { + root.open-state = true; + } else { + open-kickoff.running = true; + } + } else { + root.open-state = true; + } + } + } + public function close() { + open-kickoff.running = false; + root.open-state = false; + if popup.is-open { popup.close(); } + } function choose(i: int) { if i >= 0 && i < root.items.length && root.items[i].enabled { - popup.close(); root.chosen(i); + root.close(); root.chosen(i); } } + changed popup-open => { + if !root.popup-open { + open-kickoff.running = false; + root.open-state = false; + } + } + open-kickoff := Timer { + interval: 16ms; + running: false; + triggered => { self.running = false; if popup.is-open { root.open-state = true; } } + } + close-timer := Timer { + interval: 1ms; + running: false; + triggered => { self.running = false; if !root.open-state && popup.is-open { popup.close(); } } + } TempoIcon { source: root.icon; width: 20px; height: 20px; } - appearance := TempoPresence { active: popup.is-open; enter-time: TempoTokens.motion-short; } + appearance := TempoPresence { + active: root.open-state; + enter-time: TempoTokens.motion-short; + exit-time: 110ms; + exited => { if !root.open-state { close-timer.running = true; } } + } popup := PopupWindow { x: root.width - root.menu-width; y: root.height + 4px; @@ -66,12 +109,13 @@ export component TempoMenuButton inherits TempoAction { if e.text == Key.DownArrow { root.highlighted = min(root.items.length - 1, root.highlighted + 1); return accept; } if e.text == Key.UpArrow { root.highlighted = max(0, root.highlighted - 1); return accept; } if e.text == Key.Return || e.text == Key.Space { root.choose(root.highlighted); return accept; } - if e.text == Key.Escape { popup.close(); return accept; } + if e.text == Key.Escape { root.close(); return accept; } return reject; } TempoSurface { elevated: true; clip: true; + cache-rendering-hint: appearance.progress < 0.999; y: -6px * (1 - appearance.progress); opacity: appearance.progress; ScrollView { @@ -87,6 +131,7 @@ export component TempoMenuButton inherits TempoAction { enabled: item.enabled; border-radius: TempoTokens.radius-lg - TempoTokens.gap4; background: item.enabled && (self.active || self.hovered) ? TempoTheme.primary-soft : transparent; + animate background { enabled: !TempoMotionSettings.reduced; duration: TempoTokens.fast; easing: ease-out; } activated => { root.choose(i); } HorizontalLayout { padding-left: 10px; padding-right: 10px; @@ -95,7 +140,7 @@ export component TempoMenuButton inherits TempoAction { Text { text: item.label; color: item.enabled ? TempoTheme.text-primary : TempoTheme.text-disabled; - font-size: 13px; horizontal-stretch: 1; overflow: elide; + font-size: (13px) * TempoTokens.text-scale(1rem); horizontal-stretch: 1; overflow: elide; } } } @@ -153,8 +198,8 @@ export component TempoReorderList inherits Rectangle { activated => { root.activated(i); } VerticalLayout { alignment: center; spacing: 3px; - Text { text: item.label; color: TempoTheme.text-primary; font-size: 14px; overflow: elide; } - if item.subtitle != "" : Text { text: item.subtitle; color: TempoTheme.text-secondary; font-size: 11px; overflow: elide; } + Text { text: item.label; color: TempoTheme.text-primary; font-size: (14px) * TempoTokens.text-scale(1rem); overflow: elide; } + if item.subtitle != "" : Text { text: item.subtitle; color: TempoTheme.text-secondary; font-size: (11px) * TempoTokens.text-scale(1rem); overflow: elide; } } } TempoIconButton { diff --git a/ui/theme.slint b/ui/theme.slint index 6862123..71002be 100644 --- a/ui/theme.slint +++ b/ui/theme.slint @@ -41,6 +41,12 @@ export global TempoTheme { } export global TempoTokens { + // On Android Slint's platform rem reflects Configuration.fontScale. + // Keep desktop metrics unchanged for existing applications. + public pure function text-scale(platform-em: length) -> float { + return Platform.os == OperatingSystemType.android ? platform-em / 14px : 1.0; + } + out property radius-xs: 4px; out property radius-sm: 6px; out property radius-md: 8px; @@ -79,9 +85,9 @@ export global TempoTokens { out property border-width: 1px; out property fast: 120ms; out property normal: 180ms; - out property motion-short: 150ms; - out property motion-medium: 220ms; - out property motion-emphasized: 300ms; + out property motion-short: 140ms; + out property motion-medium: 200ms; + out property motion-emphasized: 260ms; out property motion-axis-distance: 24px; out property rail-breakpoint: 720px; out property extended-rail-breakpoint: 1100px;