Fix styling example when system theme is selected

This commit is contained in:
Héctor Ramón Jiménez 2025-09-08 05:23:50 +02:00
parent 0111f514a1
commit 4d32e733b7
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -46,21 +46,26 @@ impl Styling {
Message::CheckboxToggled(value) => self.checkbox_value = value,
Message::TogglerToggled(value) => self.toggler_value = value,
Message::PreviousTheme | Message::NextTheme => {
if let Some(current) = Theme::ALL.iter().position(|candidate| {
let current = Theme::ALL.iter().position(|candidate| {
self.theme.as_ref() == Some(candidate)
}) {
self.theme =
Some(if matches!(message, Message::NextTheme) {
Theme::ALL[(current + 1) % Theme::ALL.len()].clone()
} else if current == 0 {
Theme::ALL
.last()
.expect("Theme::ALL must not be empty")
.clone()
} else {
Theme::ALL[current - 1].clone()
});
}
});
self.theme = Some(if matches!(message, Message::NextTheme) {
Theme::ALL[current.map(|current| current + 1).unwrap_or(0)
% Theme::ALL.len()]
.clone()
} else {
let current = current.unwrap_or(0);
if current == 0 {
Theme::ALL
.last()
.expect("Theme::ALL must not be empty")
.clone()
} else {
Theme::ALL[current - 1].clone()
}
});
}
}
}