【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 ?

相关推荐
ShineWinsu1 小时前
对于Qt:事件的解析
c++·qt·面试·笔试·gui·客户端·事件
喵个咪12 小时前
RushWind Shop — 一笔订单的穿越:电商买路径上的每一道闸门
后端·微服务·rust
Kapaseker14 小时前
5分钟学会 Rust 常见集合
rust
撸码猿1 天前
Ladybird 进入 alpha:从零写的浏览器引擎现在能下载了
c++·rust·开源·浏览器·ladybird
wflynn1 天前
GitHub 今日推荐|xcl:在 Windows PC 上直接运行 Xbox Series X|S 游戏
rust·开源·github·d3d12·gdk·rdna2
geovindu2 天前
rust: Functional Options Pattern
开发语言·后端·设计模式·rust·函数式选项模式·惯用法型模式
喵个咪2 天前
RushWind Admin — 模块化单体:一个进程与通往微服务的五级阶梯
后端·架构·rust
喵个咪2 天前
RushWind CMS — 最小微服务实例:微服务架构的最小完备集
后端·架构·rust
ShineWinsu2 天前
对于Qt:QFontDialog的解析
c++·qt·面试·gui·字体·客户端·qfontdialog
geovindu3 天前
rust: Timing Functions Pattern
开发语言·后端·设计模式·rust·计时函数模式·性能分析型模式