Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<dyn std::error::Error>> {
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
Expand All @@ -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
Expand Down
33 changes: 30 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 桌面选择的系统界面字体,遇到缺字时保留简繁中文、日文和韩文回退。

### 暗色桌面与移动端布局

Expand Down Expand Up @@ -66,16 +66,20 @@ fn main() {
}
```

在 `main.rs` 创建窗口前启用 CJK 字体回退(开启 `cjk-font-fallback` feature):
开启 `cjk-font-fallback` feature,在 UI 线程初始化 Slint 之前配置字体:

```rust
fn main() -> Result<(), Box<dyn std::error::Error>> {
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
Expand All @@ -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
Expand Down
109 changes: 95 additions & 14 deletions examples/showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn options() -> Result<Options> {
"--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);
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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(())
}

Expand Down Expand Up @@ -658,7 +682,64 @@ fn run_motion_smoke(ui: &TempoCatalogWindow, screenshot: Option<String>) -> 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()?)
}
Loading
Loading