diff --git a/toolbox/ratchet/src/main.rs b/toolbox/ratchet/src/main.rs index b43ce7a..1363fa6 100644 --- a/toolbox/ratchet/src/main.rs +++ b/toolbox/ratchet/src/main.rs @@ -15,13 +15,19 @@ use iced::{ Task, Theme, }; -use log::debug; +use log::{ + debug, + warn, +}; use crate::screens::{ CurrentTopLevelScreen, MoveToScreen, configurator::ConfiguratorScreen, - wizard::WizardScreen, + wizard::{ + WizardScreen, + WizardStep, + }, }; fn theme(_state: &MainAppState) -> Theme { @@ -64,6 +70,7 @@ impl Default for MainAppState { #[derive(Debug, Clone)] pub enum Message { MoveToScreen(MoveToScreen), + SetWizardStep(WizardStep), } impl MainAppState { @@ -90,6 +97,7 @@ impl MainAppState { task } }, + screens::wizard::Action::SetStep(_wizard_step) => Task::none(), } } CurrentTopLevelScreen::Configurator(configurator_screen) => { @@ -199,26 +207,44 @@ impl MainAppState { task } }, + screens::wizard::Action::SetStep(_wizard_step) => Task::none(), } } CurrentTopLevelScreen::Configurator(_configurator_screen) => Task::none(), }, }, + Message::SetWizardStep(_wizard_step) => match &mut self.screen { + CurrentTopLevelScreen::Welcome(_welcome_screen) => Task::none(), + CurrentTopLevelScreen::Wizard(wizard_screen) => { + let action = wizard_screen.update(message.clone()); + + match action { + screens::wizard::Action::None => Task::none(), + screens::wizard::Action::MoveToScreen(_move_to_screen) => { + warn!("Not moving to screen since this is not the message that should cause that!"); + Task::none() + } + + screens::wizard::Action::SetStep(_wizard_step) => Task::none(), + } + } + CurrentTopLevelScreen::Configurator(_configurator_screen) => Task::none(), + }, } } fn view(&self) -> Element { match &self.screen { CurrentTopLevelScreen::Welcome(welcome_screen) => { - debug!("Switching to Welcome Screen..."); + debug!("Showing: Welcome Screen..."); welcome_screen.view(self) } CurrentTopLevelScreen::Wizard(wizard_screen) => { - debug!("Switching to Configuration Generation Wizard..."); + debug!("Showing: Configuration Generation Wizard..."); wizard_screen.view(self) } CurrentTopLevelScreen::Configurator(configurator_screen) => { - debug!("Switching to Instance Configurator"); + debug!("Showing: Instance Configurator"); configurator_screen.view(self) } } diff --git a/toolbox/ratchet/src/screens/configurator/mod.rs b/toolbox/ratchet/src/screens/configurator/mod.rs index 0a35d60..5d7820a 100644 --- a/toolbox/ratchet/src/screens/configurator/mod.rs +++ b/toolbox/ratchet/src/screens/configurator/mod.rs @@ -37,6 +37,7 @@ impl ConfiguratorScreen { Action::MoveToScreen(MoveToScreen::Wizard(starting_point)) } }, + crate::Message::SetWizardStep(_wizard_step) => Action::None, } } } diff --git a/toolbox/ratchet/src/screens/welcome/mod.rs b/toolbox/ratchet/src/screens/welcome/mod.rs index 7717f24..cc0380a 100644 --- a/toolbox/ratchet/src/screens/welcome/mod.rs +++ b/toolbox/ratchet/src/screens/welcome/mod.rs @@ -2,6 +2,7 @@ use carbon_steel::connections::ConnectionConfiguration; use iced::widget::{ button, column, + row, text, }; use log::{ @@ -10,7 +11,10 @@ use log::{ }; use std::collections::HashMap; -use crate::screens::MoveToScreen; +use crate::screens::{ + MoveToScreen, + wizard::WizardStep, +}; #[derive(Debug, Clone, Default)] pub struct WelcomeScreen {} @@ -34,6 +38,7 @@ impl WelcomeScreen { Action::MoveToScreen(MoveToScreen::Configurator(id)) } }, + crate::Message::SetWizardStep(_wizard_step) => Action::None, } } @@ -71,7 +76,22 @@ impl WelcomeScreen { elements.push(text("No existing connections!").into()); } - elements.push(text("Create a new...").into()); + elements.push(text("Create a New Connection...").into()); + elements.push( + row(vec![ + button("From Scratch") + .on_press(crate::Message::MoveToScreen(MoveToScreen::Wizard( + WizardStep::Intro, + ))) + .into(), + button("to an Existing Instance") + .on_press(crate::Message::MoveToScreen(MoveToScreen::Wizard( + WizardStep::ConnectionType, + ))) + .into(), + ]) + .into(), + ); column(elements).into() } diff --git a/toolbox/ratchet/src/screens/wizard/mod.rs b/toolbox/ratchet/src/screens/wizard/mod.rs index 5ec2a4b..a3b321a 100644 --- a/toolbox/ratchet/src/screens/wizard/mod.rs +++ b/toolbox/ratchet/src/screens/wizard/mod.rs @@ -1,6 +1,14 @@ -use iced::Task; - use crate::screens::MoveToScreen; +use iced::{ + Task, + widget::{ + button, + column, + row, + text, + }, +}; +use log::debug; #[derive(Default, Debug, Clone)] pub struct WizardScreen { @@ -12,6 +20,7 @@ pub enum Action { #[default] None, MoveToScreen(MoveToScreen), + SetStep(WizardStep), } impl WizardScreen { @@ -25,7 +34,55 @@ impl WizardScreen { } pub fn view(&self, _state: &crate::MainAppState) -> iced::Element { - todo!() + let mut elements = Vec::new(); + + elements.push(text("Configuration Wizard").into()); + let mut controls = Vec::new(); + + controls.push( + button("Cancel") + .on_press(crate::Message::MoveToScreen(MoveToScreen::Welcome)) + .into(), + ); + + match self.step { + WizardStep::Intro => { + elements.push(text("introduction").into()); + + controls.push(button("Back").into()); + controls.push( + button("Forward") + .on_press(crate::Message::SetWizardStep(WizardStep::ConnectionType)) + .into(), + ); + } + WizardStep::ConnectionType => { + elements.push(text("existing connection type").into()); + + controls.push( + button("Back") + .on_press(crate::Message::SetWizardStep(WizardStep::Intro)) + .into(), + ); + controls.push( + button("Finish") + .on_press(crate::Message::SetWizardStep(WizardStep::Finishing)) + .into(), + ); + } + WizardStep::Finishing => { + elements.push(text("Connecting to: ").into()); + + controls.push( + button("Back") + .on_press(crate::Message::SetWizardStep(WizardStep::ConnectionType)) + .into(), + ); + } + } + + elements.push(row(controls).into()); + column(elements).into() } pub fn update(&mut self, message: crate::Message) -> Action { @@ -37,6 +94,13 @@ impl WizardScreen { Action::MoveToScreen(MoveToScreen::Configurator(id)) } }, + crate::Message::SetWizardStep(wizard_step) => { + debug!("Moving to wizard step: {:?}", wizard_step); + + // TODO: Do validation on step move + self.step = wizard_step; + Action::None + } } } } @@ -44,5 +108,7 @@ impl WizardScreen { #[derive(Default, Debug, Clone, Copy)] pub enum WizardStep { #[default] - ConnectionType, + Intro = 0, + ConnectionType = 1, + Finishing = 3, }