本系列教程对应的代码已开源在 Github zeedle
暗色主题 | 亮色主题 |
---|---|
![]() |
![]() |
Slint UI内置全局调色板,支持运行时动态切换明暗主题,这通过更改Palette.color-scheme
来实现:
Palette.color-scheme = ColorScheme.light
变为亮色主题Palette.color-scheme = ColorScheme.dark
则变为暗色主题
把上述代码放入UI主窗口的function/callback
中,通过用户点击按钮触发调用:
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 ?