pub struct ThemeData {Show 34 fields
pub background: Color,
pub foreground: Color,
pub primary: Color,
pub accent: Color,
pub surface: Color,
pub error: Color,
pub high_contrast: bool,
pub border: Color,
pub divider: Color,
pub hover: Color,
pub disabled: Color,
pub selection: Color,
pub icon: Color,
pub radius_sm: f32,
pub radius_md: f32,
pub radius_lg: f32,
pub spacing: f32,
pub space: SpacingScale,
pub text: TextTheme,
pub button: ButtonStyle,
pub button_variants: ButtonVariants,
pub avatar: AvatarStyle,
pub control: ControlStyle,
pub geom: ControlGeometry,
pub scrollbar: ScrollbarStyle,
pub input: InputStyle,
pub tooltip: TooltipStyle,
pub menu: MenuStyle,
pub tab: TabStyle,
pub nav: NavStyle,
pub feedback: FeedbackStyle,
pub dropdown: DropdownStyle,
pub dialog: DialogStyle,
pub list: ListStyle,
}Expand description
主题色板 + 子主题。
所有 update_should_notify 走 PartialEq 派生自动比较。
风格基准:Astryx Design System 的 Neutral 主题
(tokens 层的基表 + scale + 覆盖 → ThemeData::from_tokens;
dark() / light() 是 neutral(true) / neutral(false) 的别名)。
想改主题就改 token:define_theme().token("--color-accent", "#7B61FF")
或 radius_multiplier(1.5),再 ThemeData::from_tokens(&def.resolve(dark))。
通用令牌(border / divider / hover)供全部组件共享,做到“一次改 token、全局换肤“。
Fields§
§background: Color§foreground: Color§primary: Color§accent: Color§surface: Color§error: Color§high_contrast: bool高对比度变体标记(由 ThemeData::high_contrast 设置)。
border: Color§divider: Color§hover: Color§disabled: Color§selection: Color§icon: Color§radius_sm: f32§radius_md: f32§radius_lg: f32§spacing: f32§space: SpacingScale4pt 间距刻度与组件默认间距
text: TextTheme按钮语义变体色板(Primary/Normal/Tertiary/Success/Warning/Error/Info)
avatar: AvatarStyleAvatar 首字头像样式
control: ControlStyle表单控件令牌(Checkbox/Radio/Toggle/Slider)
geom: ControlGeometry表单控件几何(指示器尺寸 / 描边 / 焦点环),见 ControlGeometry
scrollbar: ScrollbarStyle§input: InputStyle§tooltip: TooltipStyle§tab: TabStyle§feedback: FeedbackStyle§dropdown: DropdownStyle§dialog: DialogStyle§list: ListStyleImplementations§
Source§impl ThemeData
impl ThemeData
Sourcepub fn neutral(dark: bool) -> Self
pub fn neutral(dark: bool) -> Self
Astryx Neutral 主题 —— 由 tokens 层的基表 + scale + 覆盖解析而来。
dark=true 取每个 light-dark(明, 暗) 的暗档。
pub fn neutral_light() -> Self
pub fn neutral_dark() -> Self
Sourcepub fn from_tokens(tokens: &Tokens) -> Self
pub fn from_tokens(tokens: &Tokens) -> Self
由一份已解析的 token 集推导组件用的 ThemeData。
这是“主题修改功能“的落点:应用改任意 token(define_theme().token(...)),
这里就把整套子主题重算一遍。映射原则:
- 每个颜色都能追溯到一个
--color-*,本地不做调色(不再混色、不再硬编码 hex); - hover / pressed 是叠加层,先与所在容器色合成再填(见
tokens::overlay); - 圆角、控件高度、间距、字号全部走 token,所以 radius / 密度 / 字号 scale 会整体生效;
- 状态色用
--color-text-*(保证在容器上的对比度),填充按钮用--color-*+--color-on-*。
Sourcepub fn high_contrast(dark: bool) -> Self
pub fn high_contrast(dark: bool) -> Self
高对比度主题(Windows 高对比度 / 强制对比模式的通用替代)。
与 neutral 走同一条路:只覆盖 token,所有子主题由 ThemeData::from_tokens
一起重算,不再逐个字段覆写。强制的内容:
- 前景/背景 ≥ 7:1,边框/背景 ≥ 3:1,主色/背景 ≥ 4.5:1;
- 关键文本使用纯黑/纯白,边框与分割线使用前景色;
--radius-*归零、--focus-outline-width提到 3px,便于低视力用户辨识;- hover / 选中改用高 alpha 叠加层,不再用低对比的 muted 档。
dark=true 为黑底白字/金黄主色;false 为白底黑字/深蓝主色。
系统高对比度色板由平台提供时,应用仍可自行替换核心令牌。