Skip to content

Latest commit

 

History

History
61 lines (46 loc) · 1.21 KB

File metadata and controls

61 lines (46 loc) · 1.21 KB

Changing Themes

We can implement theme method in Sandbox to return the desired theme.

use iced::{
    widget::{column, text},
    Element,
};

fn main() -> iced::Result {
    iced::application("changing_theme", MyApp::update, MyApp::view)
        .theme(MyApp::theme)
        .run()
}

struct MyApp {
    _state: String,
}

impl Default for MyApp {
    fn default() -> Self {
        MyApp::new()
    }
}


#[derive(Debug, Clone)]
enum Message {
    _Message1,
}


impl MyApp {
    fn new() -> Self {
        Self {
            _state: String::new(),
        }
    }
  
    fn update(&mut self, _message: Message) {
        todo!()
    }

    fn view(&self) -> Element<Message> {
        column!(text("Hello World!".to_string()),).into()
    }

    fn theme(&self) -> iced::Theme {
        iced::Theme::Dark
        // or
        // iced::Theme::Light
    }
}

Changing themes

➡️ Next: Changing Styles

📘 Back: Table of contents