diff --git a/toolbox/ratchet/src/main.rs b/toolbox/ratchet/src/main.rs index 1363fa6..a81e521 100644 --- a/toolbox/ratchet/src/main.rs +++ b/toolbox/ratchet/src/main.rs @@ -23,7 +23,10 @@ use log::{ use crate::screens::{ CurrentTopLevelScreen, MoveToScreen, - configurator::ConfiguratorScreen, + configurator::{ + ConfiguratorScreen, + ConfiguratorTab, + }, wizard::{ WizardScreen, WizardStep, @@ -71,6 +74,7 @@ impl Default for MainAppState { pub enum Message { MoveToScreen(MoveToScreen), SetWizardStep(WizardStep), + SetConfiguratorTab(ConfiguratorTab), } impl MainAppState { @@ -118,6 +122,7 @@ impl MainAppState { task } }, + screens::configurator::Action::SetTab(_configurator_tab) => Task::none(), } } }, @@ -163,6 +168,7 @@ impl MainAppState { task } }, + screens::configurator::Action::SetTab(_configurator_tab) => Task::none(), } } }, @@ -213,7 +219,7 @@ impl MainAppState { CurrentTopLevelScreen::Configurator(_configurator_screen) => Task::none(), }, }, - Message::SetWizardStep(_wizard_step) => match &mut self.screen { + Message::SetWizardStep(_step) => match &mut self.screen { CurrentTopLevelScreen::Welcome(_welcome_screen) => Task::none(), CurrentTopLevelScreen::Wizard(wizard_screen) => { let action = wizard_screen.update(message.clone()); @@ -230,6 +236,23 @@ impl MainAppState { } CurrentTopLevelScreen::Configurator(_configurator_screen) => Task::none(), }, + Message::SetConfiguratorTab(_tab) => match &mut self.screen { + CurrentTopLevelScreen::Welcome(_welcome_screen) => Task::none(), + CurrentTopLevelScreen::Wizard(_wizard_screen) => Task::none(), + CurrentTopLevelScreen::Configurator(configurator_screen) => { + let action = configurator_screen.update(message.clone()); + + match action { + screens::configurator::Action::None => Task::none(), + screens::configurator::Action::MoveToScreen(_move_to_screen) => { + warn!("Not moving to screen since this is not the message that should cause that!"); + Task::none() + } + + screens::configurator::Action::SetTab(_tab) => Task::none(), + } + } + }, } } diff --git a/toolbox/ratchet/src/screens/configurator/mod.rs b/toolbox/ratchet/src/screens/configurator/mod.rs index 5d7820a..1e62e2b 100644 --- a/toolbox/ratchet/src/screens/configurator/mod.rs +++ b/toolbox/ratchet/src/screens/configurator/mod.rs @@ -1,13 +1,34 @@ use iced::{ Task, - widget::button, + widget::{ + button, + column, + row, + scrollable, + text, + vertical_space, + }, }; -use crate::screens::MoveToScreen; +use crate::{ + Message, + screens::MoveToScreen, +}; #[derive(Debug, Clone)] pub struct ConfiguratorScreen { pub instance_id: String, + pub tab: ConfiguratorTab, +} + +// TODO: Setup setting to save this in app state or use the default here. +#[derive(Debug, Clone, Default, Copy, PartialEq)] +pub enum ConfiguratorTab { + #[default] + Overview, + Modules, + Apps, + Repos, } #[derive(Debug, Clone, Default)] @@ -15,16 +36,117 @@ pub enum Action { #[default] None, MoveToScreen(MoveToScreen), + SetTab(ConfiguratorTab), } impl ConfiguratorScreen { pub fn new(id: String) -> (Self, Task) { - (ConfiguratorScreen { instance_id: id }, Task::none()) + ( + ConfiguratorScreen { + instance_id: id, + tab: Default::default(), + }, + Task::none(), + ) } pub fn view(&self, _state: &crate::MainAppState) -> iced::Element { - button("Hallo, Welt") - .on_press(crate::Message::MoveToScreen(MoveToScreen::Welcome)) + let mut elements = Vec::new(); + let mut sidebar = Vec::new(); + let mut content: Vec> = Vec::new(); + + sidebar.push( + button("Overview") + .on_press_maybe({ + if self.tab != ConfiguratorTab::Overview { + Some(Message::SetConfiguratorTab(ConfiguratorTab::Overview)) + } else { + None + } + }) + .width(iced::Length::Fill) + .into(), + ); + sidebar.push( + button("Modules") + .on_press_maybe({ + if self.tab != ConfiguratorTab::Modules { + Some(Message::SetConfiguratorTab(ConfiguratorTab::Modules)) + } else { + None + } + }) + .width(iced::Length::Fill) + .into(), + ); + sidebar.push( + button("Apps") + .on_press_maybe({ + if self.tab != ConfiguratorTab::Apps { + Some(Message::SetConfiguratorTab(ConfiguratorTab::Apps)) + } else { + None + } + }) + .width(iced::Length::Fill) + .into(), + ); + sidebar.push( + button("Repos") + .on_press_maybe({ + if self.tab != ConfiguratorTab::Repos { + Some(Message::SetConfiguratorTab(ConfiguratorTab::Repos)) + } else { + None + } + }) + .width(iced::Length::Fill) + .into(), + ); + sidebar.push(vertical_space().into()); + sidebar.push( + button("Instances") + .on_press(Message::MoveToScreen(MoveToScreen::Welcome)) + .width(iced::Length::Fill) + .into(), + ); + + match self.tab { + ConfiguratorTab::Overview => { + content.push(text("Overview").into()); + } + ConfiguratorTab::Modules => { + content.push(text("Modules").into()); + } + ConfiguratorTab::Apps => { + content.push(text("Apps").into()); + } + ConfiguratorTab::Repos => { + content.push(text("Repositories").into()); + } + } + + elements.push( + column(sidebar) + .height(iced::Length::Fill) + .width(256) + .spacing(12) + .padding(12) + .into(), + ); + elements.push( + scrollable( + column(content) + .width(iced::Length::Fill) + .spacing(12) + .padding(12), + ) + .width(iced::Length::Fill) + .into(), + ); + row(elements) + .height(iced::Length::Fill) + .width(iced::Length::Fill) .into() } @@ -38,6 +160,10 @@ impl ConfiguratorScreen { } }, crate::Message::SetWizardStep(_wizard_step) => Action::None, + crate::Message::SetConfiguratorTab(tab) => { + self.tab = tab; + Action::None + } } } } diff --git a/toolbox/ratchet/src/screens/welcome/mod.rs b/toolbox/ratchet/src/screens/welcome/mod.rs index cc0380a..8603a6c 100644 --- a/toolbox/ratchet/src/screens/welcome/mod.rs +++ b/toolbox/ratchet/src/screens/welcome/mod.rs @@ -38,7 +38,8 @@ impl WelcomeScreen { Action::MoveToScreen(MoveToScreen::Configurator(id)) } }, - crate::Message::SetWizardStep(_wizard_step) => Action::None, + crate::Message::SetWizardStep(_step) => Action::None, + crate::Message::SetConfiguratorTab(_tab) => Action::None, } } @@ -90,10 +91,11 @@ impl WelcomeScreen { ))) .into(), ]) + .spacing(12) .into(), ); - column(elements).into() + column(elements).spacing(12).padding(12).into() } } diff --git a/toolbox/ratchet/src/screens/wizard/mod.rs b/toolbox/ratchet/src/screens/wizard/mod.rs index a3b321a..4f7e0ca 100644 --- a/toolbox/ratchet/src/screens/wizard/mod.rs +++ b/toolbox/ratchet/src/screens/wizard/mod.rs @@ -4,8 +4,10 @@ use iced::{ widget::{ button, column, + horizontal_space, row, text, + vertical_space, }, }; use log::debug; @@ -44,6 +46,7 @@ impl WizardScreen { .on_press(crate::Message::MoveToScreen(MoveToScreen::Welcome)) .into(), ); + controls.push(horizontal_space().into()); match self.step { WizardStep::Intro => { @@ -81,8 +84,15 @@ impl WizardScreen { } } - elements.push(row(controls).into()); - column(elements).into() + elements.push(vertical_space().into()); + elements.push( + row(controls) + .spacing(12) + .padding(12) + .width(iced::Length::Fill) + .into(), + ); + column(elements).spacing(12).padding(12).into() } pub fn update(&mut self, message: crate::Message) -> Action { @@ -101,6 +111,7 @@ impl WizardScreen { self.step = wizard_step; Action::None } + crate::Message::SetConfiguratorTab(_tab) => Action::None, } } }