不能在冰 rust 中将主题设置为黑暗

jaql4c8m  于 2023-05-18  发布在  其他
关注(0)|答案(1)|浏览(134)

我试图学习生 rust 和2Iced“板条箱,我目前正试图将我的应用程序设置为黑暗模式,但我不理解文档,不知道该怎么做。

use iced::{Application, Settings, executor, Theme};

struct MyApp;

impl Application for MyApp {
    type Message = ();
    type Flags = ();
    type Executor = executor::Default;
    type Theme = **Theme::Dark**; //error[E0573]: expected type, found variant "Theme::Dark"
fn main() {
    let settings = Settings::default();
    MyApp::run(settings).unwrap();
}

我不知道如何以另一种方式实现它。
我尝试了随机的东西,如:dark::dark::dark::dark

cbjzeqam

cbjzeqam1#

正如错误所说,它需要一个类型,所以你必须执行type Theme = Theme,并且要设置黑暗主题,你需要实现theme trait项:

impl Application for MyApp {

    ... 
    ...

    type Theme = Theme;
    fn theme(&self) -> Self::Theme {
        Theme::Dark
    }
}

有关如何使用iced crate的示例,请查看github repo

相关问题