Add program::Preset and emulator::Mode

This commit is contained in:
Héctor Ramón Jiménez 2025-06-04 19:17:11 +02:00
parent 927d5b7cba
commit 73f5569f28
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
17 changed files with 305 additions and 39 deletions

View file

@ -5,6 +5,10 @@ authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2024"
publish = false
[features]
test = ["iced/test"]
tester = ["test", "iced/tester"]
[dependencies]
iced.workspace = true
iced.features = ["tokio", "debug", "time-travel"]

View file

@ -15,12 +15,16 @@ pub fn main() -> iced::Result {
#[cfg(not(target_arch = "wasm32"))]
tracing_subscriber::fmt::init();
iced::application(Todos::new, Todos::update, Todos::view)
let todos = iced::application(Todos::new, Todos::update, Todos::view)
.subscription(Todos::subscription)
.title(Todos::title)
.font(Todos::ICON_FONT)
.window_size((500.0, 800.0))
.run()
.window_size((500.0, 800.0));
#[cfg(feature = "test")]
let todos = todos.presets(presets());
todos.run()
}
#[derive(Debug)]
@ -572,6 +576,39 @@ impl SavedState {
}
}
#[cfg(feature = "test")]
fn presets() -> impl Iterator<Item = iced::application::Preset<Todos, Message>>
{
use iced::application::Preset;
[
Preset::new("Empty", || {
(
Todos::Loading,
Command::done(Message::Loaded(Err(LoadError::File))),
)
}),
Preset::new("Basic", || {
(
Todos::Loaded(State {
input_value: "Bake an apple pie".to_owned(),
filter: Filter::All,
tasks: vec![Task {
id: Uuid::new_v4(),
description: "Create the universe".to_owned(),
completed: false,
state: TaskState::Idle,
}],
dirty: false,
saving: false,
}),
Command::none(),
)
}),
]
.into_iter()
}
#[cfg(test)]
mod tests {
use super::*;