The Custom Theme implementation in my code is like this
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct Theme {
pub background: Color,
container_bg: Color,
text: Color
}
impl Theme {
pub const LIGHT: Self = Self {
background: color!(255, 255, 255),
container_bg: color!(214, 214, 214),
text: Color::BLACK
};
pub const DARK: Self = Self {
background: color!(32, 34, 37),
container_bg: color!(54, 54, 54),
text: Color::WHITE
};
}
impl Default for Theme {
fn default() -> Self {
Self::LIGHT
}
}
impl application::StyleSheet for Theme {
type Style = Theme;
fn appearance(&self, style: &Self::Style) -> application::Appearance {
application::Appearance {
background_color: style.background,
text_color: style.text
}
}
}
And the App Struct is like this
pub struct App {
theme: Theme
}
enum Message {
ToggleTheme
}
// The update function inside the implementation
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
match message {
Message::ToggleTheme => {
println!("Theme changed to {:?}", self.theme);
if self.theme == Theme::LIGHT {
self.theme = Theme::DARK
} else {
self.theme = Theme::LIGHT
}
}
}
Command::none()
}
it does print the theme change message but the theme doesn’t change