Merge branch 'master' into feature/test-recorder
This commit is contained in:
commit
a052ce58b0
69 changed files with 1555 additions and 833 deletions
|
|
@ -1 +1 @@
|
|||
0650eb2c27c21c5d48e1e00031a52d8471d8a3b4e827ad502c4628914f5c1c13
|
||||
129523830df064908cfa911214ba61dadc31d8975425ba3efaae69da9514a3d0
|
||||
|
|
@ -15,7 +15,7 @@ pub fn main() -> iced::Result {
|
|||
|
||||
#[derive(Default)]
|
||||
struct Styling {
|
||||
theme: Theme,
|
||||
theme: Option<Theme>,
|
||||
input_value: String,
|
||||
slider_value: f32,
|
||||
checkbox_value: bool,
|
||||
|
|
@ -32,13 +32,14 @@ enum Message {
|
|||
TogglerToggled(bool),
|
||||
PreviousTheme,
|
||||
NextTheme,
|
||||
ClearTheme,
|
||||
}
|
||||
|
||||
impl Styling {
|
||||
fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::ThemeChanged(theme) => {
|
||||
self.theme = theme;
|
||||
self.theme = Some(theme);
|
||||
}
|
||||
Message::InputChanged(value) => self.input_value = value,
|
||||
Message::ButtonPressed => {}
|
||||
|
|
@ -46,21 +47,29 @@ 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| &self.theme == candidate)
|
||||
{
|
||||
self.theme = if matches!(message, Message::NextTheme) {
|
||||
Theme::ALL[(current + 1) % Theme::ALL.len()].clone()
|
||||
} else if current == 0 {
|
||||
let current = Theme::ALL.iter().position(|candidate| {
|
||||
self.theme.as_ref() == Some(candidate)
|
||||
});
|
||||
|
||||
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()
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Message::ClearTheme => {
|
||||
self.theme = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,8 +77,9 @@ impl Styling {
|
|||
fn view(&self) -> Element<'_, Message> {
|
||||
let choose_theme = column![
|
||||
text("Theme:"),
|
||||
pick_list(Theme::ALL, Some(&self.theme), Message::ThemeChanged)
|
||||
.width(Fill),
|
||||
pick_list(Theme::ALL, self.theme.as_ref(), Message::ThemeChanged)
|
||||
.width(Fill)
|
||||
.placeholder("System"),
|
||||
]
|
||||
.spacing(10);
|
||||
|
||||
|
|
@ -186,11 +196,14 @@ impl Styling {
|
|||
keyboard::key::Named::ArrowDown
|
||||
| keyboard::key::Named::ArrowRight,
|
||||
) => Some(Message::NextTheme),
|
||||
keyboard::Key::Named(keyboard::key::Named::Space) => {
|
||||
Some(Message::ClearTheme)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
fn theme(&self) -> Theme {
|
||||
fn theme(&self) -> Option<Theme> {
|
||||
self.theme.clone()
|
||||
}
|
||||
}
|
||||
|
|
@ -210,9 +223,7 @@ mod tests {
|
|||
.cloned()
|
||||
.map(|theme| {
|
||||
let mut styling = Styling::default();
|
||||
styling.update(Message::ThemeChanged(theme));
|
||||
|
||||
let theme = styling.theme();
|
||||
styling.update(Message::ThemeChanged(theme.clone()));
|
||||
|
||||
let mut ui = simulator(styling.view());
|
||||
let snapshot = ui.snapshot(&theme)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue