feat(design): 加 unlucky-design 令牌 crate(M3 色彩/排版/形状/动效/图标)

D26 把视觉基线锁到 Material 3 Expressive,本 crate 是「UI 整体性」的地基:
令牌唯一真源,后续 iced 页面只消费不新增。零第三方依赖、零 UI 框架依赖
(cargo tree -p unlucky-design --edges normal 只有它自己一行)。

- 色彩:49 个 M3 语义角色 × light/dark,种子色派生 6 条 tone 调色板;
  tone 轴严格用 CIELAB L*(偏差 ≤1),色相/彩度用 OKLCh 近似 CAM16 并在
  模块文档里写明口径与已知偏差(不宣称是标准 HCT 动态取色)
- 对比度:26 组文字对 × 6 组种子 × 2 模式全部 ≥4.5:1;3 条例外显式登记
  (Outline 非文字 3:1、OutlineVariant 装饰、SurfaceVariant 是容器色)
- 排版:M3 type scale 15 档 + 三平台字体族回退栈(只写族名,不内嵌受限字体)
- 形状/高程/动效:Expressive 形状刻度 + shape morph 数据、elevation 级别与
  surface container 映射、时长/缓动/弹簧(纯函数可采样)
- 图标:24 个从 Slint 版迁移的 SVG path + 4 个新增,IconKind 冻结只可末尾追加;
  写明 Slint 的 stroke-width 是绝对像素、SVG 是 viewBox 用户单位的语义差异,
  换算封装成 Icon::stroke_width
- 组件档位表:20 个组件的形状/高程/字体/动效一次取全

TODO(M63):elevation shadow 的 blur/offset/alpha 与四组弹簧参数是占位值,
接口先定、数值待玻璃视觉规格表(tower 已通告边界)。
This commit is contained in:
AskaEth committed 2026-11-01 15:34:04 +08:00
1 parent fef0922073
commit 65ca0ed29a
25 files changed
+4622 -1

No files matched your search

+162
View File
@@ -0,0 +1,162 @@
//! 形状 / 高程 / 动效之外的「尺子」:4px 栅格与骨架尺寸。
//!
//! 源流有两条:`DevDocs/ops/slint-reference/crates/app/ui/theme/metrics.slint`(M52 定稿的骨架节奏),
//! 以及 `ui-integration-contract.md` §3「间距只允许 4/8/12/16/24/32」。M3 同样用 4dp 栅格,
//! 所以这层**不用改口径**,只是把值搬进唯一真源。
/// 栅格基数(dp)。
pub const GRID: f32 = 4.0;
/// 间距档位(M3/M2 通用 4px 栅格)。禁止 6/10/14 这类非整倍数值。
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Space {
/// 4dp:图标与文字之间。
X1,
/// 8dp:控件内边距、行内元素间距。
X2,
/// 12dp:控件间距。
X3,
/// 16dp:区块内行距、卡片内边距下限。
X4,
/// 24dp:区块间距、页面内边距。
X6,
/// 32dp:页级大留白。
X8,
}
impl Space {
/// 间距值(dp)。
pub const fn dp(self) -> f32 {
match self {
Space::X1 => 4.0,
Space::X2 => 8.0,
Space::X3 => 12.0,
Space::X4 => 16.0,
Space::X6 => 24.0,
Space::X8 => 32.0,
}
}
/// 全部档位,由小到大。
pub const ALL: [Space; 6] = [
Space::X1,
Space::X2,
Space::X3,
Space::X4,
Space::X6,
Space::X8,
];
}
/// 把任意数值对齐到 4px 栅格(最近档)。
pub fn snap_to_grid(value: f32) -> f32 {
(value / GRID).round() * GRID
}
/// 骨架尺寸:窗口结构(标题栏、导航、页头、行高)的单一来源。
///
/// 这些值不是 M3 规范值(M3 只规定组件内部节奏),而是本启动器的**布局契约**,
/// 由页面/组件两条线共同消费——任何页面自己写 `56px` 都是重复定义。
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LayoutMetrics {
/// 标题栏高度。
pub titlebar_height: f32,
/// 标题栏按钮宽度(关闭/最大化/最小化)。
pub titlebar_button_width: f32,
/// 展开态导航宽度。
pub nav_expanded_width: f32,
/// 收起态导航宽度。
pub nav_collapsed_width: f32,
/// 导航项高度。
pub nav_item_height: f32,
/// 导航项间距。
pub nav_item_gap: f32,
/// 单行页头高度。
pub page_header_height: f32,
/// 两行页头高度(日志页)。
pub page_header_tall_height: f32,
/// 运行中状态条高度。
pub running_strip_height: f32,
/// 列表行高。
pub row_height: f32,
/// 标准控件高(按钮/输入框)。
pub control_height: f32,
/// 最小可点区域。
pub touch_target: f32,
/// 卡片内边距。
pub card_padding: f32,
/// AI 面板宽度。
pub ai_panel_width: f32,
}
impl LayoutMetrics {
/// 桌面基线(1180×760 窗口,M53 页面骨架的取值)。
pub const DESKTOP: Self = Self {
titlebar_height: 40.0,
titlebar_button_width: 46.0,
nav_expanded_width: 88.0,
nav_collapsed_width: 48.0,
nav_item_height: 56.0,
nav_item_gap: 4.0,
page_header_height: 56.0,
page_header_tall_height: 84.0,
running_strip_height: 32.0,
row_height: 44.0,
control_height: 40.0,
touch_target: 44.0,
card_padding: 20.0,
ai_panel_width: 320.0,
};
}
impl LayoutMetrics {
/// 页头是否两行(日志页),决定主区与 AI 面板分隔线对齐的高度。
pub fn header_height(&self, two_line: bool) -> f32 {
if two_line {
self.page_header_tall_height
} else {
self.page_header_height
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_space_is_on_the_grid() {
for space in Space::ALL {
assert_eq!(space.dp() % GRID, 0.0, "{space:?} 不在 4px 栅格上");
}
}
#[test]
fn layout_values_are_on_the_grid() {
let m = LayoutMetrics::DESKTOP;
for (name, value) in [
("titlebar_height", m.titlebar_height),
("nav_item_height", m.nav_item_height),
("page_header_height", m.page_header_height),
("page_header_tall_height", m.page_header_tall_height),
("row_height", m.row_height),
("control_height", m.control_height),
] {
assert_eq!(value % GRID, 0.0, "{name} = {value} 不在 4px 栅格上");
}
}
#[test]
fn snap_rounds_to_nearest_grid_step() {
assert_eq!(snap_to_grid(5.0), 4.0);
assert_eq!(snap_to_grid(6.5), 8.0);
assert_eq!(snap_to_grid(0.0), 0.0);
}
#[test]
fn header_height_follows_line_count() {
let m = LayoutMetrics::DESKTOP;
assert_eq!(m.header_height(false), 56.0);
assert_eq!(m.header_height(true), 84.0);
}
}