From 49215622667033916c8936600007dcb8b4d5c17f Mon Sep 17 00:00:00 2001 From: OpenSauce Date: Sun, 1 Mar 2026 21:15:26 +0000 Subject: [PATCH] fix: reset selected stage type when switching tabs Switching from the Amp tab to the Effects tab (or vice versa) did not update selected_stage_type, so clicking "Add Stage" would add the previously selected stage from the other tab's category. --- src/gui/app.rs | 28 +++++++++++++++++++++------- src/gui/tabs.rs | 12 ++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/gui/app.rs b/src/gui/app.rs index 81b0018..d85c267 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -513,6 +513,7 @@ impl AmplifierApp { match message { Message::TabSelected(tab) => { self.active_tab = tab; + self.sync_stage_type_with_tab(tab); } Message::SetStages(stages) => { if let Some(preset_name) = self.settings.selected_preset.as_deref() { @@ -604,13 +605,7 @@ impl AmplifierApp { } Message::ToggleAllStagesCollapse => { // Only affect stages of the current tab's category - let category = match self.active_tab { - Tab::Amp => Some(StageCategory::Amp), - Tab::Effects => Some(StageCategory::Effect), - _ => None, - }; - - if let Some(cat) = category { + if let Some(cat) = self.active_tab.stage_category() { let category_indices: Vec = self .stages .iter() @@ -805,6 +800,25 @@ impl AmplifierApp { Task::none() } + /// Reset `selected_stage_type` to the first stage of the new tab's category. + fn sync_stage_type_with_tab(&mut self, tab: Tab) { + let Some(category) = tab.stage_category() else { + return; + }; + + if self.selected_stage_type.category() == category { + return; + } + + if let Some(first) = StageType::ALL + .iter() + .copied() + .find(|s| s.category() == category) + { + self.selected_stage_type = first; + } + } + /// Find the index after the last stage of the given category. fn category_end_index(&self, category: StageCategory) -> usize { match category { diff --git a/src/gui/tabs.rs b/src/gui/tabs.rs index 0c45c97..329f41b 100644 --- a/src/gui/tabs.rs +++ b/src/gui/tabs.rs @@ -1,3 +1,5 @@ +use crate::gui::stages::StageCategory; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub enum Tab { #[default] @@ -6,3 +8,13 @@ pub enum Tab { Cabinet, Io, } + +impl Tab { + pub const fn stage_category(self) -> Option { + match self { + Self::Amp => Some(StageCategory::Amp), + Self::Effects => Some(StageCategory::Effect), + _ => None, + } + } +}