Skip to main content

ThemeData

Struct ThemeData 

Source
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: SpacingScale

4pt 间距刻度与组件默认间距

§text: TextTheme§button: ButtonStyle§button_variants: ButtonVariants

按钮语义变体色板(Primary/Normal/Tertiary/Success/Warning/Error/Info)

§avatar: AvatarStyle

Avatar 首字头像样式

§control: ControlStyle

表单控件令牌(Checkbox/Radio/Toggle/Slider)

§geom: ControlGeometry

表单控件几何(指示器尺寸 / 描边 / 焦点环),见 ControlGeometry

§scrollbar: ScrollbarStyle§input: InputStyle§tooltip: TooltipStyle§menu: MenuStyle§tab: TabStyle§nav: NavStyle§feedback: FeedbackStyle§dropdown: DropdownStyle§dialog: DialogStyle§list: ListStyle

Implementations§

Source§

impl ThemeData

Source

pub fn dark() -> Self

深色主题(Astryx Neutral 暗档)。

Source

pub fn light() -> Self

浅色主题(Astryx Neutral 明档)。

Source

pub fn neutral(dark: bool) -> Self

Astryx Neutral 主题 —— 由 tokens 层的基表 + scale + 覆盖解析而来。

dark=true 取每个 light-dark(明, 暗) 的暗档。

Source

pub fn neutral_light() -> Self

Source

pub fn neutral_dark() -> Self

Source

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-*。
Source

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 为白底黑字/深蓝主色。 系统高对比度色板由平台提供时,应用仍可自行替换核心令牌。

Trait Implementations§

Source§

impl Clone for ThemeData

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ThemeData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ThemeData

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for ThemeData

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ThemeData

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.