【Rust GUI开发入门】编写一个本地音乐播放器(11. 支持动态明暗主题切换)

本系列教程对应的代码已开源在 Github zeedle

暗色主题 亮色主题

Slint UI内置全局调色板,支持运行时动态切换明暗主题,这通过更改Palette.color-scheme来实现:

  • Palette.color-scheme = ColorScheme.light变为亮色主题
  • Palette.color-scheme = ColorScheme.dark则变为暗色主题

把上述代码放入UI主窗口的function/callback中,通过用户点击按钮触发调用:

slint 复制代码
public function set_light_theme(yes: bool) {
	if (yes) {
		Palette.color-scheme = ColorScheme.light;
	} else {
		Palette.color-scheme = ColorScheme.dark;
	}
}

注意

在Slint UI最新版本(1.13.1)中,ColorScheme无法导出到Rust中使用,因此,在function/callback中实现主题切换是推荐做法,在Rust代码中无法实现该功能,参考如下Github讨论:

How to access/change value of global predefined Palette variable in Rust API ?

相关推荐
WujieLi1 天前
初识 Vite+:一文了解 Rust 驱动的新一代前端工具链
javascript·rust·vite
std860211 天前
Rust 与 Python – 这是未来的语言吗?
开发语言·python·rust
std78791 天前
Rust 与 Go – 比较以及每个如何满足您的需求
开发语言·golang·rust
Amos_Web2 天前
Rust实战教程--文件管理命令行工具
前端·rust·全栈
alwaysrun2 天前
Rust中字符串与格式化
rust·display·格式化·string·str·精度
魔镜前的帅比2 天前
(开源项目)XSUN_DESKTOP_PET 2 (桌面宠物)
rust·宠物·tauri2
0110_10242 天前
tauri + rust的环境搭建---初始化以及构建
开发语言·后端·rust
像风一样自由20202 天前
Rust Tokio vs Go net/http:云原生与嵌入式生态选型指南
开发语言·golang·rust
大鱼七成饱3 天前
Rust Web 初学者必看:用一个宏搞定错误处理和统一返回
rust
Vallelonga3 天前
Rust 设计模式 Marker Trait + Blanket Implementation
开发语言·设计模式·rust