diff options
| author | Joe Carstairs <me@joeac.net> | 2026-02-07 11:52:08 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-02-07 12:02:27 +0000 |
| commit | 1664e741ad35ce52a01788c34029f0b2ea477e32 (patch) | |
| tree | dd6bd7c83a7e834c75815a786d67b5188cdd1f48 /schist_desktop_gui/src/gui/components/navigation/navigation_select_option.rs | |
| parent | 179878d12ba10ac242da2044f4c6dfe4d4829e59 (diff) | |
task-001: can navigate file screen options with keyboard
Diffstat (limited to 'schist_desktop_gui/src/gui/components/navigation/navigation_select_option.rs')
| -rw-r--r-- | schist_desktop_gui/src/gui/components/navigation/navigation_select_option.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/schist_desktop_gui/src/gui/components/navigation/navigation_select_option.rs b/schist_desktop_gui/src/gui/components/navigation/navigation_select_option.rs index 4192059..5aa96cd 100644 --- a/schist_desktop_gui/src/gui/components/navigation/navigation_select_option.rs +++ b/schist_desktop_gui/src/gui/components/navigation/navigation_select_option.rs @@ -1,5 +1,7 @@ use iced::Element; +use crate::traits::Focusable; + use super::{Message, Navigation}; pub enum SelectOptionResult<TOption> { @@ -10,7 +12,7 @@ pub enum SelectOptionResult<TOption> { impl<'a, TOption> Navigation<TOption> where - TOption: Clone + PartialEq + 'a, + TOption: Clone + Focusable + PartialEq + 'a, Element<'a, Message<TOption>>: From<&'a TOption>, { pub fn select_option(&mut self, option: TOption) -> SelectOptionResult<TOption> @@ -30,15 +32,17 @@ where { let split = self.options_before_active.split_at(index); self.options_after_active = vec![ - self.active_option - .clone() - .map_or(vec![], |active_option| vec![active_option]), + self.active_option.as_mut().map_or(vec![], |active_option| { + active_option.unfocus(); + vec![active_option.clone()] + }), split.1.split_at(1).1.to_vec(), self.options_after_active.clone(), ] .concat(); self.options_before_active = split.0.to_vec(); self.active_option = Some(option.clone()); + self.active_option.iter_mut().for_each(TOption::focus); SelectOptionResult::SelectedExistingOption(option) } else if let Some(index) = self .options_after_active @@ -49,21 +53,25 @@ where self.options_before_active = vec![ self.options_before_active.clone(), split.0.to_vec(), - self.active_option - .clone() - .map_or(vec![], |active_option| vec![active_option]), + self.active_option.as_mut().map_or(vec![], |active_option| { + active_option.unfocus(); + vec![active_option.clone()] + }), ] .concat(); self.active_option = Some(option.clone()); + self.active_option.iter_mut().for_each(TOption::focus); self.options_after_active = split.1.split_at(1).1.to_vec(); SelectOptionResult::SelectedExistingOption(option) } else { - if let Some(active_option) = &self.active_option { + if let Some(active_option) = &mut self.active_option { + active_option.unfocus(); self.options_before_active.push(active_option.clone()); } self.options_before_active .append(&mut self.options_after_active); self.active_option = Some(option.clone()); + self.active_option.iter_mut().for_each(TOption::focus); self.options_after_active = vec![]; SelectOptionResult::SelectedNewOption(option) } |
