Skip to main content

Theme

Struct Theme 

Source
pub struct Theme {
Show 21 fields pub colors: ThemeColor, pub tokens: ThemeTokens, pub highlight_theme: Arc<HighlightTheme>, pub light_theme: Rc<ThemeConfig>, pub dark_theme: Rc<ThemeConfig>, pub mode: ThemeMode, pub font_family: SharedString, pub font_size: Pixels, pub mono_font_family: SharedString, pub mono_font_size: Pixels, pub radius: Pixels, pub radius_lg: Pixels, pub shadow: bool, pub transparent: Hsla, pub scrollbar_show: ScrollbarShow, pub notification: NotificationSettings, pub tile_grid_size: Pixels, pub tile_shadow: bool, pub tile_radius: Pixels, pub list: ListSettings, pub sheet: SheetSettings,
}
Expand description

全局主题配置。

Fields§

§colors: ThemeColor

主题颜色。

§tokens: ThemeTokens

主题令牌(颜色 + 背景)。

§highlight_theme: Arc<HighlightTheme>

代码高亮主题。

§light_theme: Rc<ThemeConfig>

亮色主题配置。

§dark_theme: Rc<ThemeConfig>

暗色主题配置。

§mode: ThemeMode

主题模式。

§font_family: SharedString

应用字体族,默认 .SystemUIFont

§font_size: Pixels

基础字号,默认 16px。

§mono_font_family: SharedString

等宽字体族。

默认值:

  • macOS: Menlo
  • Windows: Consolas
  • Linux: DejaVu Sans Mono
§mono_font_size: Pixels

等宽字号,默认 13px。

§radius: Pixels

常规元素圆角。

§radius_lg: Pixels

大元素圆角(如 Dialog、Notification)。

§shadow: bool

是否启用阴影。

§transparent: Hsla

透明色。

§scrollbar_show: ScrollbarShow

滚动条显示模式,默认:Scrolling。

§notification: NotificationSettings

通知设置。

§tile_grid_size: Pixels

磁贴网格尺寸,默认 4px。

§tile_shadow: bool

磁贴面板阴影。

§tile_radius: Pixels

磁贴面板圆角,默认 0px。

§list: ListSettings

List 设置。

§sheet: SheetSettings

Sheet 设置。

Implementations§

Source§

impl Theme

Source

pub fn apply_config(&mut self, config: &Rc<ThemeConfig>)

将给定的主题配置应用到当前主题。

Source§

impl Theme

Source

pub fn global(cx: &App) -> &Theme

返回全局主题引用。

Source

pub fn global_mut(cx: &mut App) -> &mut Theme

返回全局主题可变引用。

Source

pub fn is_dark(&self) -> bool

返回当前是否为暗色主题。

Source

pub fn theme_name(&self) -> &SharedString

返回当前主题名称。

Source

pub fn sync_system_appearance(window: Option<&mut Window>, cx: &mut App)

与系统外观同步主题。

Source

pub fn sync_scrollbar_appearance(cx: &mut App)

与系统同步滚动条显示行为。

Source

pub fn change( mode: impl Into<ThemeMode>, window: Option<&mut Window>, cx: &mut App, )

切换主题模式。

Source

pub fn input_background(&self) -> Hsla

获取输入框背景色。

暗色模式下使用透明色与输入框边框混合:cx.theme().input, 亮色模式下使用 cx.theme().background 颜色。

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

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 Theme

Source§

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

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

impl Default for Theme

Source§

fn default() -> Self

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

impl Deref for Theme

Source§

type Target = ThemeColor

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Theme

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'de> Deserialize<'de> for Theme

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&ThemeColor> for Theme

Source§

fn from(colors: &ThemeColor) -> Self

Converts to this type from the input type.
Source§

impl Global for Theme

Source§

impl JsonSchema for Theme

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl Serialize for Theme

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl !Send for Theme

§

impl !Sync for Theme

§

impl Freeze for Theme

§

impl RefUnwindSafe for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

§

impl UnwindSafe for Theme

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ReadGlobal for T
where T: Global,

Source§

fn global(cx: &App) -> &T

返回实现类型的全局实例。 Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> UpdateGlobal for T
where T: Global,

Source§

fn update_global<C, F, R>(cx: &mut C, update: F) -> R
where C: BorrowAppContext, F: FnOnce(&mut T, &mut C) -> R,

使用提供的闭包更新全局实例。 Read more
Source§

fn set_global<C>(cx: &mut C, global: T)

设置全局实例。
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more