建立统一 UI 设计令牌

This commit is contained in:
张家训
2026-08-01 13:54:31 +08:00
parent e8cf4e42ea
commit 6635117e36
4 changed files with 183 additions and 58 deletions
@@ -0,0 +1,40 @@
package com.example.workutils.system.ui;
import javafx.scene.text.Font;
import java.util.List;
/**
* Shared dimensions and typography choices for the application shell.
*/
public final class DesignTokens {
public static final int FONT_PAGE_TITLE = 20;
public static final int FONT_SECTION_TITLE = 15;
public static final int FONT_BODY = 14;
public static final int FONT_SECONDARY = 13;
public static final int ROW_HEIGHT = 40;
public static final int CONTROL_HEIGHT = 36;
public static final int NAV_EXPANDED_WIDTH = 214;
public static final int NAV_COLLAPSED_WIDTH = 56;
public static final int HEADER_HEIGHT = 48;
private DesignTokens() {
}
static String firstAvailable(List<String> preferred, List<String> installed) {
return preferred.stream().filter(installed::contains).findFirst().orElse("System");
}
public static String uiFontFamily() {
return firstAvailable(List.of("Segoe UI Variable Text", "Segoe UI", "Microsoft YaHei UI"),
Font.getFamilies());
}
public static String monoFontFamily() {
String preferredFont = firstAvailable(
List.of("JetBrains Mono", "Cascadia Mono", "Consolas"), Font.getFamilies());
return "System".equals(preferredFont) ? "Monospaced" : preferredFont;
}
}
@@ -89,8 +89,8 @@ public final class Theme {
public static final Color BG_CARD = Color.web("#f1f5f9");
public static final Color BORDER = Color.web("#e2e8f0");
public static final Color NAV_BG = Color.web("#1e293b");
public static final Color NAV_TEXT = Color.web("#ffffff");
public static final Color NAV_BG = BG_SURFACE;
public static final Color NAV_TEXT = TEXT_PRIMARY;
// ==================== CSS 类名常量(统一引用,避免魔法字符串) ====================
@@ -101,7 +101,8 @@ public final class Theme {
public static final String CSS_NAV_CELL = "nav-cell";
public static final String CSS_NAV_CELL_ACTIVE = "nav-cell-active";
public static final String CSS_NAV_INDICATOR = "nav-indicator";
public static final String CSS_NAV_RIPPLE = "nav-ripple";
/** @deprecated The ripple has no visual style; retained until the navigation shell is migrated. */
@Deprecated public static final String CSS_NAV_RIPPLE = "nav-ripple";
public static final String CSS_NAV_VERSION = "nav-version";
public static final String CSS_HEADER_BAR = "header-bar";
@@ -126,7 +127,12 @@ public final class Theme {
public static final String CSS_TABLE = "table-default";
public static final String CSS_PAGE_TITLE = "page-title";
public static final String CSS_SECTION_TITLE = "section-title";
public static final String CSS_BODY_TEXT = "body-text";
public static final String CSS_SECONDARY_TEXT = "secondary-text";
public static final String CSS_APP_ICON = "app-icon";
public static final String CSS_CONTROL_DEFAULT = "control-default";
public static final String CSS_HINT_TEXT = "hint-text";
public static final String CSS_MUTED_TEXT = "muted-text";
public static final String CSS_DANGER_TEXT = "danger-text";
@@ -151,20 +157,43 @@ public final class Theme {
// ==================== 字体系统(保留,各窗口通过代码动态设置) ====================
public static Font h1(int size) { return Font.font("Microsoft YaHei", FontWeight.BOLD, size); }
public static Font h2(int size) { return Font.font("Microsoft YaHei", FontWeight.BOLD, size); }
public static Font h3(int size) { return Font.font("Microsoft YaHei", FontWeight.BOLD, size); }
public static Font body(int size) { return Font.font("Microsoft YaHei", size); }
public static Font small(int size) { return Font.font("Microsoft YaHei", size); }
public static Font base(int size) { return Font.font("Microsoft YaHei", size); }
public static Font bold(int size) { return Font.font("Microsoft YaHei", FontWeight.BOLD, size); }
public static Font mono(int size) { return Font.font("Consolas", size); }
public static Font heading(int size) { return bold(size); }
public static Font caption(int size) { return Font.font("Microsoft YaHei", size); }
public static Font pageTitle() { return Font.font(DesignTokens.uiFontFamily(), FontWeight.SEMI_BOLD,
DesignTokens.FONT_PAGE_TITLE); }
public static Font sectionTitle() { return Font.font(DesignTokens.uiFontFamily(), FontWeight.SEMI_BOLD,
DesignTokens.FONT_SECTION_TITLE); }
public static Font body() { return Font.font(DesignTokens.uiFontFamily(), DesignTokens.FONT_BODY); }
public static Font secondary() { return Font.font(DesignTokens.uiFontFamily(), DesignTokens.FONT_SECONDARY); }
public static Font tableText() { return body(); }
public static Font mono() { return Font.font(DesignTokens.monoFontFamily(), DesignTokens.FONT_BODY); }
/** @deprecated Migrate to {@link #pageTitle()} or {@link #sectionTitle()}. */
@Deprecated public static Font h1(int size) { return Font.font(DesignTokens.uiFontFamily(), FontWeight.BOLD, size); }
/** @deprecated Migrate to {@link #sectionTitle()}. */
@Deprecated public static Font h2(int size) { return Font.font(DesignTokens.uiFontFamily(), FontWeight.BOLD, size); }
/** @deprecated Migrate to {@link #sectionTitle()}. */
@Deprecated public static Font h3(int size) { return Font.font(DesignTokens.uiFontFamily(), FontWeight.BOLD, size); }
/** @deprecated Migrate to {@link #body()}. */
@Deprecated public static Font body(int size) { return Font.font(DesignTokens.uiFontFamily(), size); }
/** @deprecated Migrate to {@link #secondary()}. */
@Deprecated public static Font small(int size) { return Font.font(DesignTokens.uiFontFamily(), size); }
/** @deprecated Migrate to {@link #body()}. */
@Deprecated public static Font base(int size) { return Font.font(DesignTokens.uiFontFamily(), size); }
/** @deprecated Migrate to {@link #sectionTitle()}. */
@Deprecated public static Font bold(int size) { return Font.font(DesignTokens.uiFontFamily(), FontWeight.BOLD, size); }
/** @deprecated Migrate to {@link #mono()}. */
@Deprecated public static Font mono(int size) { return Font.font(DesignTokens.monoFontFamily(), size); }
/** @deprecated Migrate to {@link #sectionTitle()}. */
@Deprecated public static Font heading(int size) { return bold(size); }
/** @deprecated Migrate to {@link #secondary()}. */
@Deprecated public static Font caption(int size) { return Font.font(DesignTokens.uiFontFamily(), size); }
/** @deprecated Migrate to {@link #body()}. */
@Deprecated
public static Font base(int size, String family) {
return Font.font(family, size);
}
/** @deprecated Migrate to {@link #sectionTitle()}. */
@Deprecated
public static Font bold(int size, String family) {
return Font.font(family, FontWeight.BOLD, size);
}