creo-ui (Rust)
Creo UI Design System tokens for Rust consumers.
単一の W3C Design Tokens (DTCG) から生成された pub const 定義 (色 / 余白 / typography / radius / shadow) を creo_ui::tokens モジュールとして提供する。
インストール
まだ crates.io に publish していない。Phase 2 で公開予定。現時点では path dependency または git dependency で参照する:
# Cargo.toml (path 参照の例)
[]
= { = "../creo-ui/packages/rust" }
# Cargo.toml (git 参照の例)
[]
= { = "https://github.com/chronista-club/creo-ui.git" }
使い方
use tokens;
ratatui / image 等との連携
Rgb 構造体に as_array() が生えているので [u8; 3] 経由で他ライブラリの色型に渡せる:
use COLOR_BRAND_PRIMARY;
// ratatui
let bg = Rgb;
// image crate
let pixel = Rgb;
ratatui interop (features = ["ratatui"])
creo_ui::ratatui 下に Color 変換と palette helper、character cell padding が生えている:
use ratatui as creo_rat;
use tokens;
let title_style = default
.fg
.bg
.add_modifier;
// spacing token を character cell 数 (8px/cell 仮定) で扱う
let left_pad = md; // 18px → 2 cells
egui interop (features = ["egui"])
creo_ui::egui で mint-dark baseline の Visuals を egui Context にワンショット
適用できる。Rgb → Color32 変換も const fn として生えている:
use egui as creo_eg;
use tokens;
// Visuals を直接取得して部分 override したい場合
let mut v = creo_visuals;
v.window_rounding = 8.0.into;
// 単発の Color32 変換 (const 文脈でも OK)
const BRAND: Color32 = to_color32;
let info: Color32 = COLOR_SEMANTIC_INFO.into;
提供するトークン
| Category | 命名 | 型 |
|---|---|---|
color.* |
COLOR_BRAND_PRIMARY, COLOR_SEMANTIC_ERROR 等 |
Rgb { r, g, b } (u8) |
spacing.* |
SPACING_XS, SPACING_MD 等 (5 step) |
f32 (px) |
margin.* |
MARGIN_XS, MARGIN_MD 等 (5 step) |
f32 (px) |
radius.* |
RADIUS_NONE, RADIUS_XS ... RADIUS_FULL (5 step + special) |
f32 |
typography.size.* |
TYPOGRAPHY_SIZE_MD 等 (body text, 5 step) |
f32 (px) |
typography.display.* |
TYPOGRAPHY_DISPLAY_MD 等 (heading, 5 step) |
f32 (px) |
layout.gap.* |
LAYOUT_GAP_SIBLING 等 (semantic between-ness) |
f32 (px) |
layout.target.* |
LAYOUT_TARGET_TAP (=44) / FOCUS / HIT (Apple HIG accessibility) |
f32 (px) |
typography.title.* |
TYPOGRAPHY_TITLE_PAGE 等 (role-based headings, hero/page/section/subsection/card) |
f32 (px) |
typography.body.* |
TYPOGRAPHY_BODY_DEFAULT 等 (role-based body, lead/default/emphasis/helper/caption) |
f32 (px) |
typography.weight.* |
TYPOGRAPHY_WEIGHT_REGULAR 等 |
f32 |
typography.family.* / shadow.* |
TYPOGRAPHY_FAMILY_SANS, SHADOW_MD 等 |
&'static str |
全定数は packages/rust/src/generated/tokens.rs で確認できる (Style Dictionary が bun run build:rust で自動生成)。
Build 要件
- Rust edition 2024 (
rust-version = "1.95"をmiseと揃えている) #![forbid(unsafe_code)]creo_ui::tokensはinclude!()で外部 module に取り込まれる設計 (src/lib.rs:21)
License
Apache-2.0 — LICENSE